2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2008, The GROMACS development team.
6 * Copyright (c) 2010,2014,2015,2019,2021, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 /*! \libinternal \file
39 * Declares simple statistics toolbox
41 * \authors David van der Spoel <david.vanderspoel@icm.uu.se>
44 #ifndef GMX_STATISTICS_H
45 #define GMX_STATISTICS_H
49 #include "gromacs/utility/real.h"
51 //! Abstract container type
52 typedef struct gmx_stats* gmx_stats_t;
54 //! Error codes returned by the routines
55 enum class StatisticsStatus : int
62 //! Enum for statistical weights
73 * Initiate a data structure
74 * \return the data structure
76 gmx_stats_t gmx_stats_init();
79 * Destroy a data structure
80 * \param stats The data structure
82 void gmx_stats_free(gmx_stats_t stats);
85 * Add a point to the data set
86 * \param[in] stats The data structure
87 * \param[in] x The x value
88 * \param[in] y The y value
89 * \param[in] dx The error in the x value
90 * \param[in] dy The error in the y value
93 StatisticsStatus gmx_stats_add_point(gmx_stats_t stats, double x, double y, double dx, double dy);
96 * Fit the data to y = ax + b, possibly weighted, if uncertainties
97 * have been input. da and db may be NULL.
98 * \param[in] stats The data structure
99 * \param[in] weight type of weighting
100 * \param[out] a slope
101 * \param[out] b intercept
102 * \param[out] da sigma in a
103 * \param[out] db sigma in b
104 * \param[out] chi2 normalized quality of fit
105 * \param[out] Rfit correlation coefficient
109 gmx_stats_get_ab(gmx_stats_t stats, int weight, real* a, real* b, real* da, real* db, real* chi2, real* Rfit);
112 * Computes and returns the average value.
113 * \param[in] stats The data structure
114 * \param[out] aver Average value
117 StatisticsStatus gmx_stats_get_average(gmx_stats_t stats, real* aver);
120 * Pointers may be null, in which case no assignment will be done.
121 * \param[in] stats The data structure
122 * \param[out] aver Average value
123 * \param[out] sigma Standard deviation
124 * \param[out] error Standard error
127 StatisticsStatus gmx_stats_get_ase(gmx_stats_t stats, real* aver, real* sigma, real* error);
129 /*! \brief Assert that statistics are OK
131 * \param[in] estats error code
133 void gmx_stats_message([[maybe_unused]] StatisticsStatus estats);
135 /****************************************************
136 * Some statistics utilities for convenience: useful when a complete data
137 * set is available already from another source, e.g. an xvg file.
138 ****************************************************/
141 * Fit a straight line y=ax+b thru the n data points x, y.
142 * \param[in] n number of points
143 * \param[in] x data points x
144 * \param[in] y data point y
145 * \param[out] a slope
146 * \param[out] b intercept
147 * \param[out] r correlation coefficient
148 * \param[out] chi2 quality of fit
151 StatisticsStatus lsq_y_ax_b(int n, real x[], real y[], real* a, real* b, real* r, real* chi2);
153 /*! \copydoc lsq_y_ax_b
155 StatisticsStatus lsq_y_ax_b_xdouble(int n, double x[], real y[], real* a, real* b, real* r, real* chi2);
158 * Fit a straight line y=ax+b thru the n data points x, y.
159 * \param[in] n number of points
160 * \param[in] x data points x
161 * \param[in] y data point y
162 * \param[in] dy uncertainty in data point y
163 * \param[out] a slope
164 * \param[out] b intercept
165 * \param[out] da error in slope
166 * \param[out] db error in intercept
167 * \param[out] r correlation coefficient
168 * \param[out] chi2 quality of fit
172 lsq_y_ax_b_error(int n, real x[], real y[], real dy[], real* a, real* b, real* da, real* db, real* r, real* chi2);