49 #include <visp/vpColVector.h>
50 #include <visp/vpMath.h>
51 #include <visp/vpScale.h>
56 #define DEBUG_LEVEL2 0
63 : bandwidth(0.02), dimension(1), kernel_type(EPANECHNIKOV)
66 std::cout <<
"vpScale constructor reached" << std::endl;
69 std::cout <<
"vpScale constructor finished" << std::endl;
76 : bandwidth(kernel_bandwidth), dimension(dim), kernel_type(type)
80 std::cout <<
"vpScale constructor reached" << std::endl;
83 std::cout <<
"vpScale constructor finished" << std::endl;
98 unsigned int n = error.
getRows()/dimension;
103 unsigned int increment=1;
107 while(error[i]<0 && error[i]<error[i+1])
111 while(increment >= 1 && i<n)
116 mean_shift[i]=
vpMath::sqr(bandwidth)*density_gradient[i]/((dimension+2)*density[i]);
118 double tmp_shift = mean_shift[i];
121 while(tmp_shift>0 && tmp_shift>error[i]-error[i+1])
125 tmp_shift-=(error[i]-error[i-1]);
139 unsigned int n = error.
getRows()/dimension;
142 unsigned int j=position;
151 while(std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j<=n)
154 for(
unsigned int i=0; i<dimension; i++)
156 X[i]=(error[position]-error[j])/bandwidth;
170 while(std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j>=dimension)
173 for(
unsigned int i=0; i<dimension; i++)
175 X[i]=(error[position]-error[j])/bandwidth;
185 density*=1/(n*bandwidth);
195 unsigned int n = error.
getRows()/dimension;
196 double density_gradient=0;
201 double inside_kernel = 1;
202 unsigned int j=position;
207 while(std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j<=n)
209 delta = error[position]-error[j];
213 sum_delta+=error[j]-error[position];
225 while(std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j>=dimension)
227 delta = error[position]-error[j];
231 sum_delta+=error[j]-error[position];
242 return density_gradient;
267 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
272 return 1/(2*c)*(dimension+2)*(1-XtX);
298 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
303 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)