TPCCLIB
Loading...
Searching...
No Matches
mestim.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpcmodel.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
18double mEstim(
20 double *data,
22 int nr,
24 int iterNr,
26 double cutoff
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}
47/*****************************************************************************/
48
49/*****************************************************************************/
53double huber(
55 double x,
57 double b
58) {
59 double help;
60
61 if(x<-b) help=-b; else help=x;
62 if(help<b) {return help;} else {return b;}
63}
64/*****************************************************************************/
65
66/*****************************************************************************/
Header file for libtpcmodel.
double dmedian(double *data, int n)
Definition median.c:48
double huber(double x, double b)
Definition mestim.c:53
double mEstim(double *data, int nr, int iterNr, double cutoff)
Definition mestim.c:18