Fix and add tests

This commit is contained in:
hcz 2019-05-06 12:08:54 +08:00
parent d86d60297a
commit 4f3e164c73
3 changed files with 88 additions and 0 deletions

View File

@ -189,6 +189,9 @@ struct HighOrderMoments
T NO_SANITIZE_UNDEFINED getMoment3() const T NO_SANITIZE_UNDEFINED getMoment3() const
{ {
// to avoid accuracy problem
if (m0 == 1)
return 0;
return (m3 return (m3
- (3 * m2 - (3 * m2
- 2 * m1 * m1 / m0 - 2 * m1 * m1 / m0
@ -198,6 +201,9 @@ struct HighOrderMoments
T NO_SANITIZE_UNDEFINED getMoment4() const T NO_SANITIZE_UNDEFINED getMoment4() const
{ {
// to avoid accuracy problem
if (m0 == 1)
return 0;
return (m4 return (m4
- (4 * m3 - (4 * m3
- (6 * m2 - (6 * m2

View File

@ -5,6 +5,12 @@ nan
nan nan
0 0
nan nan
nan
0
nan
nan
0
nan
0 0
0 0
nan nan
@ -14,6 +20,12 @@ nan
nan nan
0 0
nan nan
nan
0
nan
nan
0
nan
0 0
0 0
nan nan

View File

@ -30,6 +30,41 @@ SELECT
FROM series FROM series
); );
/* skewSamp */
SELECT skewSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
SELECT skewSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
SELECT round(abs(res1 - res2), 6) FROM
(
SELECT
skewSamp(x_value) AS res1,
(
sum(x_value * x_value * x_value) / count()
- 3 * sum(x_value * x_value) / count() * sum(x_value) / count()
+ 2 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1), 1.5) AS res2
FROM series
);
/* kurtSamp */
SELECT kurtSamp(x_value) FROM (SELECT x_value FROM series LIMIT 0);
SELECT kurtSamp(x_value) FROM (SELECT x_value FROM series LIMIT 1);
SELECT round(abs(res1 - res2), 6) FROM
(
SELECT
kurtSamp(x_value) AS res1,
(
sum(x_value * x_value * x_value * x_value) / count()
- 4 * sum(x_value * x_value * x_value) / count() * sum(x_value) / count()
+ 6 * sum(x_value * x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
- 3 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / (count() - 1), 2) AS res2
FROM series
);
/* varPop */ /* varPop */
SELECT varPop(x_value) FROM (SELECT x_value FROM series LIMIT 0); SELECT varPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
@ -56,6 +91,41 @@ SELECT
FROM series FROM series
); );
/* skewPop */
SELECT skewPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
SELECT skewPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
SELECT round(abs(res1 - res2), 6) FROM
(
SELECT
skewPop(x_value) AS res1,
(
sum(x_value * x_value * x_value) / count()
- 3 * sum(x_value * x_value) / count() * sum(x_value) / count()
+ 2 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count(), 1.5) AS res2
FROM series
);
/* kurtPop */
SELECT kurtPop(x_value) FROM (SELECT x_value FROM series LIMIT 0);
SELECT kurtPop(x_value) FROM (SELECT x_value FROM series LIMIT 1);
SELECT round(abs(res1 - res2), 6) FROM
(
SELECT
kurtPop(x_value) AS res1,
(
sum(x_value * x_value * x_value * x_value) / count()
- 4 * sum(x_value * x_value * x_value) / count() * sum(x_value) / count()
+ 6 * sum(x_value * x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
- 3 * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count() * sum(x_value) / count()
) / pow((sum(x_value * x_value) - ((sum(x_value) * sum(x_value)) / count())) / count(), 2) AS res2
FROM series
);
/* covarSamp */ /* covarSamp */
SELECT covarSamp(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 0); SELECT covarSamp(x_value, y_value) FROM (SELECT x_value, y_value FROM series LIMIT 0);