10 #pragma warning(disable : 4996)
25 static const double g[25] = {1.0,
28 -0.420026350340952e-1,
30 -0.421977345555443e-1,
55 if (x ==
static_cast<int>(x)) {
59 for (
int i = 2; i < x; i++) ga *= i;
66 double z = 0.0, r = 0.0;
69 int m =
static_cast<int>(z);
71 for (
int k = 1; k <= m; k++) r *= (z - k);
78 for (
int k = 23; k >= 0; k--) gr = gr * z + g[k];
79 double ga = 1.0 / (gr * z);
83 ga = -
M_PI / (x * ga * sin(
M_PI * x));
93 ScalarType valueShift) {
105 ScalarType& sigma2)
const {
114 ScalarType valueShift) {
122 if (
m_a > 0.0 &&
m_b >= 0.0) {
140 size_t n = values.size();
141 if (n == 0)
return false;
144 ScalarType minValue = 0;
145 ScalarType maxValue = 0;
146 bool firstValue =
true;
147 for (ScalarType s : values) {
151 minValue = maxValue = s;
156 else if (s > maxValue)
166 double valueRange = maxValue - minValue;
167 if (valueRange < std::numeric_limits<ScalarType>::epsilon()) {
171 double a =
FindGRoot(values, minValue, valueRange);
172 if (a < 0.0)
return false;
176 unsigned counter = 0;
177 for (
size_t i = 0; i < n; ++i) {
178 ScalarType v = values[i];
182 b += pow((
static_cast<double>(v) - minValue) / valueRange, a);
187 if (counter == 0)
return false;
190 static_cast<ScalarType
>(a),
191 static_cast<ScalarType
>(valueRange * pow(b / counter, 1.0 / a)),
199 double xp = pow(x,
m_a - 1.0);
200 return (
static_cast<double>(
m_a) /
m_b) * xp * exp(-xp * x);
208 static_cast<double>(
m_a))));
217 static_cast<double>(
m_a))) -
219 static_cast<double>(
m_a)));
224 ScalarType valueShift,
226 size_t n = values.size();
229 if (r <= 0.0 || n == 0)
235 unsigned counter = 0;
236 unsigned zeroValues = 0;
238 for (
unsigned i = 0; i < n; ++i) {
239 ScalarType v = values[i];
242 double v0 =
static_cast<double>(v) - valueShift;
244 double ln_v = log(v0);
245 double v_a = pow(v0 / valueRange, r);
263 q += v_a * zeroValues;
265 counter += zeroValues;
272 return (p / q - s / counter) * r - 1.0;
276 ScalarType valueShift,
281 double v =
ComputeG(values, aMin, valueShift, valueRange);
288 vMin =
ComputeG(values, aMin, valueShift, valueRange);
293 }
else if (vMin > 0) {
298 while (vMax < 0 && aMax < 1.0e3) {
300 vMax =
ComputeG(values, aMax, valueShift, valueRange);
305 }
else if (vMax < 0) {
313 r = (aMin + aMax) / 2;
315 v =
ComputeG(values, r, valueShift, valueRange);
329 unsigned numberOfClasses,
334 unsigned numberOfElements =
337 if (numberOfElements == 0)
return -1.0;
339 if (numberOfClasses < 1 ||
340 numberOfClasses * numberOfClasses > numberOfElements)
342 else if (numberOfClasses == 1)
349 int* histo = inputHisto;
351 histo =
new int[numberOfClasses];
352 if (!histo)
return -1.0;
354 memset(histo, 0, numberOfClasses *
sizeof(
int));
357 unsigned n = cloud->
size();
358 for (
unsigned i = 0; i < n; ++i) {
362 for (; j < numberOfClasses - 1; ++j)
372 double nPi =
static_cast<double>(numberOfElements) / numberOfClasses;
373 for (
unsigned i = 0; i < numberOfClasses; ++i) {
374 double tempValue =
static_cast<double>(histo[i]) - nPi;
375 dk += tempValue * tempValue;
380 if (histo && !inputHisto)
delete[] histo;
389 if (!
isValid() || numberOfClasses < 2)
return false;
393 }
catch (
const std::bad_alloc&) {
400 double areaPerClass = 1.0 / numberOfClasses;
401 double currentArea = areaPerClass;
402 double invA = 1.0 /
m_a;
404 for (
unsigned i = 1; i < numberOfClasses; ++i) {
407 static_cast<ScalarType
>(pow(-log(1.0 - currentArea), invA));
408 currentArea += areaPerClass;
430 m_sigma2 < std::numeric_limits<double>::epsilon()) {
431 return std::numeric_limits<double>::quiet_NaN();
constexpr double ZERO_TOLERANCE_D
virtual unsigned size() const =0
Returns the number of points.
virtual ScalarType getPointScalarValue(unsigned pointIndex) const =0
Returns the ith point associated scalar value.
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.
static bool ValidValue(ScalarType value)
Returns whether a scalar value is valid or not.
void setValueShift(ScalarType vs)
Sets the distribution value shift.
bool getOtherParameters(ScalarType &mu, ScalarType &sigma2) const
Returns the normal distribution equivalent parameters.
bool computeParameters(const ScalarContainer &values) override
Computes the distribution parameters from a set of values.
virtual bool setChi2ClassesPositions(unsigned numberOfClasses)
Compute each Chi2 class limits.
double computeP(ScalarType x) const override
Computes the probability of x.
bool setParameters(ScalarType a, ScalarType b, ScalarType valueShift=0)
Sets the distribution parameters.
bool getParameters(ScalarType &a, ScalarType &b) const
Returns the distribution parameters.
static double ComputeG(const ScalarContainer &values, double a, ScalarType valueShift, double valueRange)
internal function for parameters evaluation from sample points
ScalarType m_a
Weibull distribution parameter a (k)
ScalarType m_sigma2
Normal distribution equivalent parameter: variance.
double computeSkewness() const
Returns the distribution 'skewness'.
double computeChi2Dist(const GenericCloud *cloud, unsigned numberOfClasses, int *histo=nullptr) override
Computes the Chi2 distance (related to the Chi2 Test)
WeibullDistribution()
WeibullDistribution constructor.
ScalarType m_mu
Normal distribution equivalent parameter: mean.
ScalarType m_valueShift
Weibull distribution parameter 'value shift'.
static double FindGRoot(const ScalarContainer &values, ScalarType valueShift, double valueRange)
internal function for parameters evaluation from sample points
ScalarType m_b
Weibull distribution parameter b (lambda)
std::vector< ScalarType > chi2ClassesPositions
Chi2 classes limits.
double computePfromZero(ScalarType x) const override
Computes the cumulative probability between 0 and x.
double computeMode() const
Returns the distribution 'mode'.
static double Gamma_cc(double x)
__host__ __device__ int2 abs(int2 v)
Generic file read and write utility for python interface.
bool GreaterThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
bool LessThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).