49 #include <visp/vpColVector.h>
50 #include <visp/vpMath.h>
51 #include <visp/vpScale.h>
56 #define DEBUG_LEVEL2 0
65 std::cout <<
"vpScale constructor reached" << std::endl;
69 kernel_type = EPANECHNIKOV;
72 std::cout <<
"vpScale constructor finished" << std::endl;
79 int dimension=1,
int kernel_type=EPANECHNIKOV)
82 std::cout <<
"vpScale constructor reached" << std::endl;
85 bandwidth = kernel_bandwidth;
86 this->dimension = (unsigned)dimension;
87 this->kernel_type = kernel_type;
90 std::cout <<
"vpScale constructor finished" << std::endl;
109 unsigned int n = error.
getRows()/dimension;
114 unsigned int increment=1;
118 while(error[i]<0 && error[i]<error[i+1])
122 while(increment >= 1 && i<n)
127 mean_shift[i]=
vpMath::sqr(bandwidth)*density_gradient[i]/((dimension+2)*density[i]);
129 double tmp_shift = mean_shift[i];
132 while(tmp_shift>0 && tmp_shift>error[i]-error[i+1])
136 tmp_shift-=(error[i]-error[i-1]);
150 unsigned int n = error.
getRows()/dimension;
153 unsigned int j=position;
162 while(std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j<=n)
165 for(
unsigned int i=0; i<dimension; i++)
167 X[i]=(error[position]-error[j])/bandwidth;
181 while(std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j>=dimension)
184 for(
unsigned int i=0; i<dimension; i++)
186 X[i]=(error[position]-error[j])/bandwidth;
196 density*=1/(n*bandwidth);
206 unsigned int n = error.
getRows()/dimension;
207 double density_gradient=0;
212 double inside_kernel = 1;
213 unsigned int j=position;
218 while(std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j<=n)
220 delta = error[position]-error[j];
224 sum_delta+=error[j]-error[position];
236 while(std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j>=dimension)
238 delta = error[position]-error[j];
242 sum_delta+=error[j]-error[position];
253 return density_gradient;
278 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
283 return 1/(2*c)*(dimension+2)*(1-XtX);
309 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
314 return sumX*(dimension+2)/(n*bandwidth*c*
vpMath::sqr(bandwidth));
double KernelDensityGradient_EPANECHNIKOV(double X, unsigned int n)
double KernelDensityGradient(vpColVector &error, unsigned int position)
static double sqr(double x)
virtual ~vpScale(void)
Destructor.
Class that provides a data structure for the column vectors as well as a set of operations on these v...
double MeanShift(vpColVector &error)
double KernelDensity(vpColVector &error, unsigned int position)
unsigned int getRows() const
Return the number of rows of the matrix.
double KernelDensity_EPANECHNIKOV(vpColVector &X)