10 #pragma warning(disable : 4996)
36 ScalarType& sigma2)
const {
65 double p =
static_cast<double>(x -
m_mu);
85 double mean = 0.0, stddev2 = 0.0;
88 unsigned n = cloud->
size();
89 for (
unsigned i = 0; i < n; ++i) {
93 stddev2 +=
static_cast<double>(v) * v;
103 stddev2 =
std::abs(stddev2 / counter - mean * mean);
106 static_cast<ScalarType
>(stddev2));
113 double mean = 0.0, stddev2 = 0.0;
114 unsigned counter = 0;
116 for (ScalarType v : values) {
119 stddev2 +=
static_cast<double>(v) * v;
129 stddev2 =
std::abs(stddev2 / counter - mean * mean);
132 static_cast<ScalarType
>(stddev2));
140 const double maxStddev = sqrt(
static_cast<double>(
m_sigma2)) * nSigma;
142 unsigned counter = 0;
143 double mean = 0.0, stddev2 = 0.0;
145 for (ScalarType v : values) {
146 if (
static_cast<double>(
std::abs(v -
m_mu)) < maxStddev) {
148 stddev2 +=
static_cast<double>(v) * v;
158 stddev2 =
std::abs(stddev2 / counter - mean * mean);
161 static_cast<ScalarType
>(stddev2));
165 unsigned numberOfClasses,
169 unsigned n = cloud->
size();
172 unsigned numberOfElements =
175 if (numberOfElements == 0)
return -1.0;
177 if (numberOfClasses < 1 ||
178 numberOfClasses * numberOfClasses > numberOfElements)
180 else if (numberOfClasses == 1)
185 assert(
m_Pi.size() == numberOfClasses);
188 if (!_histo) _histo =
new int[numberOfClasses];
189 if (!_histo)
return -1.0;
191 memset(_histo, 0, numberOfClasses *
sizeof(
int));
194 for (
unsigned i = 0; i < n; ++i) {
198 for (; j < numberOfClasses - 1; ++j)
208 for (
unsigned i = 0; i < numberOfClasses; ++i) {
209 double nPi =
static_cast<double>(
m_Pi[i]) * numberOfElements;
210 double tempValue =
static_cast<double>(_histo[i]) - nPi;
211 dk += tempValue * tempValue / nPi;
215 if (_histo && !histo)
delete[] _histo;
225 if (!
isValid() || numberOfClasses < 2)
return false;
228 m_Pi.reserve(numberOfClasses);
230 }
catch (
const std::bad_alloc&) {
236 if (numberOfClasses == 2) {
244 ScalarType x =
m_mu - 2 * sigma;
250 ScalarType pas = 4 * sigma / (numberOfClasses - 2);
251 for (
unsigned i = 0; i < numberOfClasses - 2; ++i) {
255 m_Pi.push_back(y - oldy);
static double erf(double x)
Computes erf(x)
virtual unsigned size() const =0
Returns the number of points.
virtual ScalarType getPointScalarValue(unsigned pointIndex) const =0
Returns the ith point associated scalar value.
A generic class to handle a probability distribution.
virtual bool isValid() const
Indicates if the distribution parameters are valid.
void setValid(bool state)
Sets distribution current validity.
std::vector< ScalarType > ScalarContainer
Scalar values container.
double computeChi2Dist(const GenericCloud *Yk, unsigned numberOfClasses, int *histo=nullptr) override
Computes the Chi2 distance (related to the Chi2 Test)
bool computeRobustParameters(const ScalarContainer &values, double nSigma)
bool setParameters(ScalarType _mu, ScalarType _sigma2)
Sets the distribution parameters.
NormalDistribution()
NormalDistribution constructor.
bool computeParameters(const ScalarContainer &values) override
Computes the distribution parameters from a set of values.
bool getParameters(ScalarType &_mu, ScalarType &_sigma2) const
Returns the distribution parameters.
double m_qFactor
Exponential quotient.
double m_normFactor
Normalization factor.
virtual bool setChi2ClassesPositions(unsigned numberOfClasses)
Compute each Chi2 class limits.
std::vector< ScalarType > m_chi2ClassesPositions
Chi2 classes limits.
std::vector< ScalarType > m_Pi
Structure used during the Chi2 distance computation.
double computePfromZero(ScalarType x) const override
Computes the cumulative probability between 0 and x.
ScalarType m_sigma2
Variance.
double computeP(ScalarType x) const override
Computes the probability of x.
static bool ValidValue(ScalarType value)
Returns whether a scalar value is valid or not.
__host__ __device__ int2 abs(int2 v)
Generic file read and write utility for python interface.