47 #include <visp3/core/vpColVector.h> 48 #include <visp3/core/vpMath.h> 49 #include <visp3/core/vpScale.h> 51 #define DEBUG_LEVEL2 0 57 std::cout <<
"vpScale constructor reached" << std::endl;
60 std::cout <<
"vpScale constructor finished" << std::endl;
65 vpScale::vpScale(
double kernel_bandwidth,
unsigned int dim) : bandwidth(kernel_bandwidth), dimension(dim)
69 std::cout <<
"vpScale constructor reached" << std::endl;
72 std::cout <<
"vpScale constructor finished" << std::endl;
84 unsigned int n = error.
getRows() / dimension;
89 unsigned int increment = 1;
93 while (error[i] < 0 && error[i] < error[i + 1])
97 while (increment >= 1 && i < n) {
101 mean_shift[i] =
vpMath::sqr(bandwidth) * density_gradient[i] / ((dimension + 2) * density[i]);
103 double tmp_shift = mean_shift[i];
106 while (tmp_shift > 0 && tmp_shift > error[i] - error[i + 1]) {
109 tmp_shift -= (error[i] - error[i - 1]);
121 unsigned int n = error.
getRows() / dimension;
124 unsigned int j = position;
132 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j <= n) {
134 for (
unsigned int i = 0; i < dimension; i++) {
135 X[i] = (error[position] - error[j]) / bandwidth;
139 position -= dimension;
149 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j >= dimension) {
151 for (
unsigned int i = 0; i < dimension; i++) {
152 X[i] = (error[position] - error[j]) / bandwidth;
156 position -= dimension;
162 density *= 1 / (n * bandwidth);
170 unsigned int n = error.
getRows() / dimension;
171 double density_gradient = 0;
172 double sum_delta = 0;
176 double inside_kernel = 1;
177 unsigned int j = position;
182 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j <= n) {
183 delta = error[position] - error[j];
186 sum_delta += error[j] - error[position];
197 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j >= dimension) {
198 delta = error[position] - error[j];
201 sum_delta += error[j] - error[position];
210 return density_gradient;
231 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
236 return 1 / (2 * c) * (dimension + 2) * (1 - XtX);
258 std::cout <<
"ERROR in vpScale::Kernel_EPANECHNIKOV : wrong dimension" << std::endl;
264 return sumX * (dimension + 2) / (n * bandwidth * c *
vpMath::sqr(bandwidth));
unsigned int getRows() const
double KernelDensityGradient_EPANECHNIKOV(double X, unsigned int n)
double KernelDensityGradient(vpColVector &error, unsigned int position)
static double sqr(double x)
virtual ~vpScale(void)
Destructor.
Implementation of column vector and the associated operations.
double MeanShift(vpColVector &error)
double KernelDensity(vpColVector &error, unsigned int position)
double KernelDensity_EPANECHNIKOV(vpColVector &X)