]> git.mxchange.org Git - simgear.git/blob - simgear/math/leastsqs.hxx
Boolean uniforms are now updatable by properties
[simgear.git] / simgear / math / leastsqs.hxx
1 /**
2  * \file leastsqs.hxx
3  * Implements a simple linear least squares best fit routine.
4  */
5
6 // Written by Curtis Olson, started September 1997.
7 //
8 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _LEASTSQS_H
28 #define _LEASTSQS_H
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35
36 /**
37 Classical least squares fit:
38
39 \f[
40     y = b_0 + b_1 * x
41 \f]
42
43 \f[
44     b_1 = \frac{n * \sum_0^{i-1} (x_i*y_i) - \sum_0^{i-1} x_i* \sum_0^{i-1} y_i}
45           {n*\sum_0^{i-1} x_i^2 - (\sum_0^{i-1} x_i)^2}
46 \f]
47
48 \f[
49     b_0 = \frac{\sum_0^{i-1} y_i}{n} - b_1 * \frac{\sum_0^{i-1} x_i}{n}
50 \f]
51 */
52 void least_squares(double *x, double *y, int n, double *m, double *b);
53
54
55 /**
56  * Incrimentally update existing values with a new data point.
57  */
58 void least_squares_update(double x, double y, double *m, double *b);
59
60
61 /**
62   @return the least squares error:.
63 \f[
64
65     \frac{(y_i - \hat{y}_i)^2}{n}
66 \f]
67 */
68 double least_squares_error(double *x, double *y, int n, double m, double b);
69
70
71 /**
72   @return the maximum least squares error.
73
74 \f[
75     (y_i - \hat{y}_i)^2
76 \f]
77 */
78 double least_squares_max_error(double *x, double *y, int n, double m, double b);
79
80
81 #endif // _LEASTSQS_H
82
83