Calculating Hubers M-estimator for single data.
More...
Go to the source code of this file.
|
| double | mEstim (double *data, int nr, int iterNr, double cutoff) |
| double | huber (double x, double b) |
Calculating Hubers M-estimator for single data.
- Author
- Kaisa Sederholm, Vesa Oikonen
Definition in file mestim.c.
◆ huber()
| double huber |
( |
double | x, |
|
|
double | b ) |
Hubers function.
- Returns
- Returns x if |x|<b, and b otherwise.
- Parameters
-
| x | parameter x |
| b | cutoff point |
Definition at line 53 of file mestim.c.
58 {
59 double help;
60
61 if(x<-b) help=-b; else help=x;
62 if(help<b) {return help;} else {return b;}
63}
Referenced by mEstim().
◆ mEstim()
| double mEstim |
( |
double * | data, |
|
|
int | nr, |
|
|
int | iterNr, |
|
|
double | cutoff ) |
Fit a constant (horizontal straight line) to the data with M-estimator.
The algorithm was described in the lecture notes of Nonlinear signal processing course of Tampere university of technology www.cs.tut.fi/~eeroh/nonlin.html
- Returns
- Returns Hubers M-estimator for single dataset.
- Parameters
-
| data | Data array |
| nr | Number of data values |
| iterNr | Number of iterations |
| cutoff | cutoff point |
Definition at line 18 of file mestim.c.
27 {
28 double theta, sum1, sum2, help;
29
31 for(int ii=0; ii<iterNr; ii++){
32 sum1=sum2=0;
33 for(int in=0; in<nr; in++){
34 if(data[in]<0.9999*theta || data[in]>1.0001*theta){
35 help=
huber(data[in]-theta, cutoff);
36 sum1=sum1+data[in]*help/(data[in]-theta);
37 sum2=sum2+help/(data[in]-theta);
38 } else {
39 sum1=sum1+cutoff*data[in];
40 sum2=sum2+cutoff;
41 }
42 }
43 theta=sum1/sum2;
44 }
45 return theta;
46}
double dmedian(double *data, int n)
double huber(double x, double b)