44 #include <visp3/core/vpColVector.h>
45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpScale.h>
48 #define DEBUG_LEVEL2 0
54 std::cout <<
"vpScale constructor reached" << std::endl;
57 std::cout <<
"vpScale constructor finished" << std::endl;
62 vpScale::vpScale(
double kernel_bandwidth,
unsigned int dim) : bandwidth(kernel_bandwidth), dimension(dim)
66 std::cout <<
"vpScale constructor reached" << std::endl;
69 std::cout <<
"vpScale constructor finished" << std::endl;
81 unsigned int n = error.
getRows() / dimension;
86 unsigned int increment = 1;
90 while (error[i] < 0 && error[i] < error[i + 1])
94 while (increment >= 1 && i < n) {
98 mean_shift[i] =
vpMath::sqr(bandwidth) * density_gradient[i] / ((dimension + 2) * density[i]);
100 double tmp_shift = mean_shift[i];
103 while (tmp_shift > 0 && tmp_shift > error[i] - error[i + 1]) {
106 tmp_shift -= (error[i] - error[i - 1]);
118 unsigned int n = error.
getRows() / dimension;
121 unsigned int j = position;
129 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j <= n) {
131 for (
unsigned int i = 0; i < dimension; i++) {
132 X[i] = (error[position] - error[j]) / bandwidth;
136 position -= dimension;
146 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j >= dimension) {
148 for (
unsigned int i = 0; i < dimension; i++) {
149 X[i] = (error[position] - error[j]) / bandwidth;
153 position -= dimension;
159 density *= 1 / (n * bandwidth);
167 unsigned int n = error.
getRows() / dimension;
168 double density_gradient = 0;
169 double sum_delta = 0;
172 double inside_kernel = 1;
173 unsigned int j = position;
178 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j <= n) {
179 delta = error[position] - error[j];
182 sum_delta += error[j] - error[position];
193 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j >= dimension) {
194 delta = error[position] - error[j];
197 sum_delta += error[j] - error[position];
206 return density_gradient;
232 return 1 / (2 * c) * (dimension + 2) * (1 - XtX);
260 return sumX * (dimension + 2) / (n * bandwidth * c *
vpMath::sqr(bandwidth));
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
static double sqr(double x)
double KernelDensity(vpColVector &error, unsigned int position)
double KernelDensityGradient_EPANECHNIKOV(double X, unsigned int n)
double KernelDensityGradient(vpColVector &error, unsigned int position)
double MeanShift(vpColVector &error)
double KernelDensity_EPANECHNIKOV(vpColVector &X)
virtual ~vpScale(void)
Destructor.