mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Fix and add tests
This commit is contained in:
parent
d86d60297a
commit
4f3e164c73
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user