14 mean /= points.
size();
20 corr += (p.x - mean.
x) * (p.y - mean.
y);
21 normX +=
sqr(p.x - mean.
x);
22 normY +=
sqr(p.y - mean.
y);
25 return corr / (
sqrt(normX * normY));
29 return 1._f / (
pow(2._f, 0.5_f * dof) * std::tgamma(0.5_f * dof)) *
pow(chiSqr, 0.5_f * dof - 1._f) *
36 for (
Size i = 0; i < measured.
size(); ++i) {
37 SPH_ASSERT(measured[i] >= 0._f && expected[i] >= 0._f);
38 if (expected[i] == 0._f) {
39 if (measured[i] == 0._f) {
47 chiSqr +=
sqr(measured[i] - expected[i]) / expected[i];
54 constexpr
Float eps1 = 1.e-3_f;
55 constexpr
Float eps2 = 1.e-8_f;
58 Float prevTerm = 0._f;
59 for (
Size j = 1; j < 100; ++j) {
62 if (
abs(term) <= eps1 * prevTerm ||
abs(term) <= eps2 * Q) {
73 std::sort(sortedData.
begin(), sortedData.
end(), [](
Float p1,
Float p2) { return p1 < p2; });
80 const Float step = 1._f / (pdf.
size() - 1);
81 for (
Size i = 0; i < pdf.
size(); ++i) {
82 cdf[i] = { sortedPdf[i], i * step };
84 SPH_ASSERT(cdf.front().y == 0 && cdf.back().y == 1);
101 const Float expectedY = expectedCdf(p.x);
102 D =
max(D,
abs(p.y - expectedY),
abs(prevY - expectedY));
106 Float prob = ksProb(sqrtN, D);
116 for (
Size i = 0, j = 0; i < cdf1.
size() && j < cdf2.
size();) {
117 if (cdf1[i].x <= cdf2[j].x) {
120 if (cdf1[i].x >= cdf2[j].x) {
123 D =
max(D,
abs(cdf1[i].y - cdf2[j].y));
127 Float prob = ksProb(sqrtNe, D);
135 quadrants.
fill(0._f);
137 if (p.y > origin.
y) {
138 p.x > origin.
x ? quadrants[0]++ : quadrants[1]++;
140 p.x > origin.
x ? quadrants[3]++ : quadrants[2]++;
143 for (
Float& q : quadrants) {
154 for (
Size i = 0; i < 4; ++i) {
155 D =
max(D, measuredQuadrants[i] - expectedQuadrants[i]);
171 return { (1._f - x) * (1._f - y), x * (1._f - y), x * y, (1._f - x) * y };
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T max(const T &f1, const T &f2)
constexpr INLINE bool isOdd(const T &f)
constexpr INLINE T clamp(const T &f, const T &f1, const T &f2)
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE T sqrt(const T f)
Return a squared root of a value.
constexpr INLINE Float pow(const Float v)
Power for floats.
INLINE auto abs(const T &f)
#define NAMESPACE_SPH_END
Object providing safe access to continuous memory of data.
INLINE TCounter size() const
INLINE Iterator< StorageType > begin()
INLINE Iterator< StorageType > end()
INLINE Iterator< StorageType > end() noexcept
INLINE TCounter size() const noexcept
INLINE Iterator< StorageType > begin() noexcept
void pushAll(const TIter first, const TIter last)
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float size() const
Returns the size of the interval.
Array with fixed number of allocated elements.
void fill(const T &value)
Assigns a value to all constructed elements of the array.
INLINE TCounter size() const
Returns the current size of the array (number of constructed elements).
Float kolmogorovSmirnovDistribution(const Float x)
Float chiSquareDistribution(const Float chiSqr, const Float dof)
Float correlationCoefficient(ArrayView< const PlotPoint > points)
KsFunction getUniformKsFunction(Interval rangeX, Interval rangeY)
Float chiSquareTest(ArrayView< const Float > measured, ArrayView< const Float > expected)
KsResult kolmogorovSmirnovTest(ArrayView< const Float > data, const Function< Float(Float)> &expectedCdf)
One-dimensional Kolmogorov-Smirnov test with given CDF of expected probability distribution.