44 #include <visp3/core/vpColVector.h>
45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpScale.h>
48 #define DEBUG_LEVEL2 0
55 std::cout <<
"vpScale constructor reached" << std::endl;
58 std::cout <<
"vpScale constructor finished" << std::endl;
63 vpScale::vpScale(
double kernel_bandwidth,
unsigned int dim) : bandwidth(kernel_bandwidth), dimension(dim)
67 std::cout <<
"vpScale constructor reached" << std::endl;
70 std::cout <<
"vpScale constructor finished" << std::endl;
82 unsigned int n = error.
getRows() / dimension;
87 unsigned int increment = 1;
91 while (error[i] < 0 && error[i] < error[i + 1])
95 while (increment >= 1 && i < n) {
99 mean_shift[i] =
vpMath::sqr(bandwidth) * density_gradient[i] / ((dimension + 2) * density[i]);
101 double tmp_shift = mean_shift[i];
104 while (tmp_shift > 0 && tmp_shift > error[i] - error[i + 1]) {
107 tmp_shift -= (error[i] - error[i - 1]);
119 unsigned int n = error.
getRows() / dimension;
122 unsigned int j = position;
130 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j <= n) {
132 for (
unsigned int i = 0; i < dimension; i++) {
133 X[i] = (error[position] - error[j]) / bandwidth;
137 position -= dimension;
147 while (std::fabs(Ke) > std::numeric_limits<double>::epsilon() && j >= dimension) {
149 for (
unsigned int i = 0; i < dimension; i++) {
150 X[i] = (error[position] - error[j]) / bandwidth;
154 position -= dimension;
160 density *= 1 / (n * bandwidth);
168 unsigned int n = error.
getRows() / dimension;
169 double density_gradient = 0;
170 double sum_delta = 0;
173 double inside_kernel = 1;
174 unsigned int j = position;
179 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j <= n) {
180 delta = error[position] - error[j];
183 sum_delta += error[j] - error[position];
195 while (std::fabs(inside_kernel) > std::numeric_limits<double>::epsilon() && j >= dimension) {
196 delta = error[position] - error[j];
199 sum_delta += error[j] - error[position];
209 return density_gradient;
235 return 1 / (2 * c) * (dimension + 2) * (1 - XtX);
263 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.