TPCCLIB
Loading...
Searching...
No Matches
mestim.c File Reference

Calculating Hubers M-estimator for single data. More...

#include "libtpcmodel.h"

Go to the source code of this file.

Functions

double mEstim (double *data, int nr, int iterNr, double cutoff)
 
double huber (double x, double b)
 

Detailed Description

Calculating Hubers M-estimator for single data.

Author
Kaisa Sederholm, Vesa Oikonen

Definition in file mestim.c.

Function Documentation

◆ huber()

double huber ( double x,
double b )

Hubers function.

Returns
Returns x if |x|<b, and b otherwise.
Parameters
xparameter x
bcutoff 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
dataData array
nrNumber of data values
iterNrNumber of iterations
cutoffcutoff point

Definition at line 18 of file mestim.c.

27 {
28 double theta, sum1, sum2, help;
29
30 theta=dmedian(data, nr);
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)
Definition median.c:48
double huber(double x, double b)
Definition mestim.c:53