From e406e1cf0d3cc684acec6ab7d2e45ce90904f913 Mon Sep 17 00:00:00 2001 From: Efim Kubyshkin Date: Wed, 18 Nov 2026 18:53:17 +0300 Subject: [PATCH 1/2] test: check KS normality statistic depends on mean and var KolmogorovSmirnovNormalityGofStatistic stores mean and var but evaluates the standard normal CDF, so the statistic ignores them. - Add a test that the statistic changes when mean and/or var differ from the defaults on the same sample. - Pass mean and var in test_ks_normality_criterion. The case labelled "mean = 11" used an N(0, 1) sample with the default N(0, 1) hypothesis; shift the sample by 11 and test it against N(11, 1). The expected value is unchanged since KS is shift-invariant (cross-checked with scipy.stats.kstest). These tests are expected to fail until the statistic is fixed. Co-Authored-By: Claude Opus 5.5 --- tests/distributions/test_normal.py | 38 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/distributions/test_normal.py b/tests/distributions/test_normal.py index a4f98102..6c56c9f3 100644 --- a/tests/distributions/test_normal.py +++ b/tests/distributions/test_normal.py @@ -49,7 +49,7 @@ @pytest.mark.parametrize( - ("data", "result"), + ("data", "mean", "var", "result"), [ # Normal with mean = 0, variance = 1 ( @@ -65,31 +65,43 @@ 0.90892169, -0.29045373, ], + 0, + 1, 0.18573457378941832, ), # Normal with mean = 11, variance = 1 ( [ - -0.46869863, - -0.22452687, - -1.7674444, - -0.727139, - 1.09089112, - -0.01319041, - 0.38578004, - 1.47354665, - 0.95253258, - -1.17323879, + 10.53130137, + 10.77547313, + 9.2325556, + 10.272861, + 12.09089112, + 10.98680959, + 11.38578004, + 12.47354665, + 11.95253258, + 9.82676121, ], + 11, + 1, 0.12958652448618313, ), ], ) -def test_ks_normality_criterion(data, result): - statistic = KolmogorovSmirnovNormalityGofStatistic().execute_statistic(data) +def test_ks_normality_criterion(data, mean, var, result): + statistic = KolmogorovSmirnovNormalityGofStatistic(mean=mean, var=var).execute_statistic(data) assert result == pytest.approx(statistic, 0.00001) +@pytest.mark.parametrize(("mean", "var"), [(5, 1), (0, 4), (5, 4)]) +def test_ks_normality_criterion_depends_on_parameters(mean, var): + data = [0.5, 1.2, 2.3, 3.1, 4.8, 5.0, 5.7, 6.4, 7.9, 9.2] + default = KolmogorovSmirnovNormalityGofStatistic().execute_statistic(data) + custom = KolmogorovSmirnovNormalityGofStatistic(mean=mean, var=var).execute_statistic(data) + assert custom != pytest.approx(default) + + def test_ks_normality_criterion_code(): assert "KS_NORMALITY_GOODNESS_OF_FIT" == KolmogorovSmirnovNormalityGofStatistic().code() From 1e6edeb3dfbe6328230b3a36f7226271e0d0785a Mon Sep 17 00:00:00 2001 From: Efim Kubyshkin Date: Wed, 18 Nov 2026 19:06:28 +0300 Subject: [PATCH 2/2] fix: pass mean and var to KS normality CDF KolmogorovSmirnovNormalityGofStatistic evaluated the standard normal CDF and ignored the mean and var it was constructed with. Use them as loc and scale; var is a variance, so scale is its square root. Co-Authored-By: Claude Opus 5.5 --- src/pysatl_criterion/statistics/goodness_of_fit/normal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pysatl_criterion/statistics/goodness_of_fit/normal.py b/src/pysatl_criterion/statistics/goodness_of_fit/normal.py index 122b103f..ae107b80 100644 --- a/src/pysatl_criterion/statistics/goodness_of_fit/normal.py +++ b/src/pysatl_criterion/statistics/goodness_of_fit/normal.py @@ -88,7 +88,7 @@ def code(): @override def execute_statistic(self, rvs, **kwargs): rvs = np.sort(rvs) - cdf_vals = scipy_stats.norm.cdf(rvs) + cdf_vals = scipy_stats.norm.cdf(rvs, loc=self.mean, scale=math.sqrt(self.var)) return KSStatistic.do_execute_statistic(self, rvs, cdf_vals)