TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcmodel
lms.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcmodel.h
"
7
/*****************************************************************************/
8
/* local function definitions */
10
int
lmsQSort
(
const
void
*par1,
const
void
*par2);
12
/*****************************************************************************/
21
double
least_median_of_squares
(
23
double
*data,
25
int
n
26
) {
27
int
i, odd=1, half=floor(n/2), smallnr;
28
double
small, *help;
29
if
(fmod((
double
)n, 2.0)<1e-99) odd=0;
30
double
*halfs_data;
31
32
halfs_data=(
double
*)malloc((half+odd) *
sizeof
(
double
));
33
34
help=data;
35
/* sort data in ascending order*/
36
qsort(help, n,
sizeof
(
double
),
lmsQSort
);
37
38
/* if n is even number */
39
for
(i=0; i<half+odd; i++) {
40
halfs_data[i]=data[half+i]-data[i];
41
}
42
43
i=smallnr=0;
44
for
(i=1, small=halfs_data[0]; i<half+odd; i++) {
45
if
(halfs_data[i]<small) {
46
small=halfs_data[i];
47
smallnr=i;
48
}
49
}
50
51
return
(data[half+smallnr]+data[smallnr])/2.0;
52
}
53
/*****************************************************************************/
54
55
/*****************************************************************************/
59
int
lmsQSort
(
61
const
void
*par1,
63
const
void
*par2
64
) {
65
if
( *((
double
*)par1) < *((
double
*)par2))
return
(-1);
66
else
if
( *((
double
*)par1) > *((
double
*)par2))
return
(1);
67
else
return
(0);
68
}
69
/*****************************************************************************/
70
71
/*****************************************************************************/
libtpcmodel.h
Header file for libtpcmodel.
lmsQSort
int lmsQSort(const void *par1, const void *par2)
Definition
lms.c:59
least_median_of_squares
double least_median_of_squares(double *data, int n)
Fit a constant (horisontal straight line) to the data by minimising the median of squared residuals.
Definition
lms.c:21
Generated on
for TPCCLIB by
1.17.0