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
51 #include "gromacs/utility/real.h"
53 //! Abstract container type
54 typedef struct gmx_stats* gmx_stats_t;
56 //! Enum for statistical weights
67 * Initiate a data structure
68 * \return the data structure
70 gmx_stats_t gmx_stats_init();
73 * Destroy a data structure
74 * \param stats The data structure
76 void gmx_stats_free(gmx_stats_t stats);
79 * Add a point to the data set
80 * \param[in] stats The data structure
81 * \param[in] x The x value
82 * \param[in] y The y value
83 * \param[in] dx The error in the x value
84 * \param[in] dy The error in the y value
86 void gmx_stats_add_point(gmx_stats_t stats, double x, double y, double dx, double dy);
89 * Fit the data to y = ax + b, possibly weighted, if uncertainties
90 * have been input. da and db may be NULL.
91 * \param[in] stats The data structure
92 * \param[in] weight type of weighting
94 * \param[out] b intercept
95 * \param[out] da sigma in a
96 * \param[out] db sigma in b
97 * \param[out] chi2 normalized quality of fit
98 * \param[out] Rfit correlation coefficient
100 void gmx_stats_get_ab(gmx_stats_t stats, int weight, real* a, real* b, real* da, real* db, real* chi2, real* Rfit);
103 * Computes and returns the average value.
104 * \param[in] stats The data structure
105 * \param[out] aver Average value
106 * \return Average value
107 * \throws InconsistentInputError if given no points to average
109 real gmx_stats_get_average(gmx_stats_t stats);
112 * Pointers may be null, in which case no assignment will be done.
113 * \param[in] stats The data structure
114 * \return Tuple of (average value, its standard deviation, its standard error)
115 * \throws InconsistentInputError if given no points to analyze
117 std::tuple<real, real, real> gmx_stats_get_ase(gmx_stats_t gstats);
119 /****************************************************
120 * Some statistics utilities for convenience: useful when a complete data
121 * set is available already from another source, e.g. an xvg file.
122 ****************************************************/
125 * Fit a straight line y=ax+b thru the n data points x, y.
126 * \param[in] n number of points
127 * \param[in] x data points x
128 * \param[in] y data point y
129 * \param[out] a slope
130 * \param[out] b intercept
131 * \param[out] r correlation coefficient
132 * \param[out] chi2 quality of fit
134 * \throws InconsistentInputError if given no points to fit
136 void lsq_y_ax_b(int n, real x[], real y[], real* a, real* b, real* r, real* chi2);
138 /*! \copydoc lsq_y_ax_b
139 * Suits cases where x is already always computed in double precision
140 * even in a mixed-precision build configuration.
142 void lsq_y_ax_b_xdouble(int n, double x[], real y[], real* a, real* b, real* r, real* chi2);
145 * Fit a straight line y=ax+b thru the n data points x, y.
146 * \param[in] n number of points
147 * \param[in] x data points x
148 * \param[in] y data point y
149 * \param[in] dy uncertainty in data point y
150 * \param[out] a slope
151 * \param[out] b intercept
152 * \param[out] da error in slope
153 * \param[out] db error in intercept
154 * \param[out] r correlation coefficient
155 * \param[out] chi2 quality of fit
157 * \throws InconsistentInputError if given no points to fit
159 void 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);