-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregret1.c
56 lines (39 loc) · 1.12 KB
/
regret1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
-------------------------------------------------------------------------
OBJECT NAME: regret1.c
FULL NAME: Linear Detrend Regression.
ENTRY POINTS: LinearLeastSquare()
STATIC FNS: none
DESCRIPTION:
REFERENCES: none
REFERENCED BY: spctrm.c
COPYRIGHT: University Corporation for Atmospheric Research, 1996-8
-------------------------------------------------------------------------
*/
#include "define.h"
/* -------------------------------------------------------------------- */
void LinearLeastSquare(DATASET_INFO *set, float inp[], float out[])
{
size_t i;
double Ymean, Xmean, SXX, SXY, B0, B1, im;
/* Compute x bar and y bar.
*/
Xmean = (double)set->nPoints / 2.0;
Ymean = set->stats.mean;
for (i = 0, SXX = SXY = 0.0; i < set->nPoints; ++i)
{
im = (i - Xmean);
SXX += im * im;
SXY += im * (inp[i] - Ymean);
}
B1 = SXY / SXX;
B0 = Ymean - B1 * Xmean;
/* y[i] = B0 + B1 * x[i]
*/
for (i = 0; i < set->nPoints; ++i)
out[i] = B0 + B1 * i;
/*
fprintf(stderr,"Ybar=%f, Xbar=%f, Slope=%f, Yinter=%f\n", Ymean, Xmean, B1, B0);
*/
} /* END LINEARLEASTSQUARE */
/* END REGRET1.C */