Changeset 4589 for trunk/library
- Timestamp:
- 11/12/08 07:48:56 (2 months ago)
- Location:
- trunk/library
- Files:
-
- 4 modified
-
population.lgt (modified) (1 diff)
-
sample.lgt (modified) (1 diff)
-
statistics.lgt (modified) (1 diff)
-
statisticsp.lgt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/library/population.lgt
r4588 r4589 10 10 11 11 skewness([X| Xs], Skewness) :- 12 :arithmetic_mean(Xs, 1, Length, X, Mean), 13 X2 is (X - Mean) ** 2, 14 X3 is (X - Mean) ** 3, 15 :squares_and_cubes(Xs, Mean, X2, Squares, X3, Cubes), 16 Skew is (Cubes / Length) / (Squares / Length) ** 1.5, 17 Skewness is sqrt(Length*(Length - 1)) * Skew / (Length - 2). 12 :arithmetic_mean(Xs, 1, N, X, Mean), 13 Square is (X - Mean) ** 2, 14 Cube is (X - Mean) ** 3, 15 :squares_and_cubes(Xs, Mean, Square, Squares, Cube, Cubes), 16 Skew is (Cubes / N) / (Squares / N) ** 1.5, 17 Skewness is sqrt(N*(N - 1)) * Skew / (N - 2). 18 19 kurtosis([X| Xs], Kurtosis) :- 20 :arithmetic_mean(Xs, 1, N, X, Mean), 21 Square is (X - Mean) ** 2, 22 Hyper is (X - Mean) ** 4, 23 :squares_and_hypers(Xs, Mean, Square, _, Hyper, Hypers), 24 :variance(Xs, 1, N, X, 0, M2), 25 K2 is M2 / (N - 1), 26 Kurtosis is N*(N + 1)*Hypers / ((N- 1)*(N- 2)*(N -3)*K2**2) - 3*(N -1)**2/((N- 2)*(N -3)). 18 27 19 28 standard_deviation([X| Xs], Deviation) :- 20 :variance(Xs, 1, Length, X, 0, M2),21 Deviation is sqrt(M2 / Length).29 :variance(Xs, 1, N, X, 0, M2), 30 Deviation is sqrt(M2 / N). 22 31 23 32 variance([X| Xs], Variance) :- 24 :variance(Xs, 1, Length, X, 0, M2),25 Variance is M2 / Length.33 :variance(Xs, 1, N, X, 0, M2), 34 Variance is M2 / N. 26 35 27 36 :- end_object. -
trunk/library/sample.lgt
r4588 r4589 10 10 11 11 skewness([X| Xs], Skewness) :- 12 :arithmetic_mean(Xs, 1, Length, X, Mean), 13 X2 is (X - Mean) ** 2, 14 X3 is (X - Mean) ** 3, 15 :squares_and_cubes(Xs, Mean, X2, Squares, X3, Cubes), 16 Skewness is (Cubes / Length) / (Squares / Length) ** 1.5. 12 :arithmetic_mean(Xs, 1, N, X, Mean), 13 Square is (X - Mean) ** 2, 14 Cube is (X - Mean) ** 3, 15 :squares_and_cubes(Xs, Mean, Square, Squares, Cube, Cubes), 16 Skewness is (Cubes / N) / (Squares / N) ** 1.5. 17 18 kurtosis([X| Xs], Kurtosis) :- 19 :arithmetic_mean(Xs, 1, N, X, Mean), 20 Square is (X - Mean) ** 2, 21 Hyper is (X - Mean) ** 4, 22 :squares_and_hypers(Xs, Mean, Square, Squares, Hyper, Hypers), 23 Kurtosis is (Hypers / N) / (Squares / N) ** 2 - 3. 17 24 18 25 standard_deviation([X| Xs], Deviation) :- 19 :variance(Xs, 1, Length, X, 0, M2),20 Deviation is sqrt(M2 / ( Length- 1)).26 :variance(Xs, 1, N, X, 0, M2), 27 Deviation is sqrt(M2 / (N - 1)). 21 28 22 29 variance([X| Xs], Variance) :- 23 :variance(Xs, 1, Length, X, 0, M2),24 Variance is M2 / ( Length- 1).30 :variance(Xs, 1, N, X, 0, M2), 31 Variance is M2 / (N - 1). 25 32 26 33 :- end_object. -
trunk/library/statistics.lgt
r4588 r4589 82 82 Cacc2 is Cacc + (X - Mean) ** 3, 83 83 squares_and_cubes(Xs, Mean, Sacc2, Squares, Cacc2, Cubes). 84 85 squares_and_hypers([], _, Squares, Squares, Hypers, Hypers). 86 squares_and_hypers([X| Xs], Mean, Sacc, Squares, Hacc, Hypers) :- 87 Sacc2 is Sacc + (X - Mean) ** 2, 88 Hacc2 is Hacc + (X - Mean) ** 4, 89 squares_and_hypers(Xs, Mean, Sacc2, Squares, Hacc2, Hypers). 84 90 85 91 median([X| Xs], Median) :- -
trunk/library/statisticsp.lgt
r4483 r4589 102 102 :- info(skewness/2, 103 103 [comment is 'Calculates the skewness of a list of numbers. Fails if the list is empty.', 104 argnames is ['List', 'Deviation']]). 104 argnames is ['List', 'Skewness']]). 105 106 :- public(kurtosis/2). 107 :- mode(kurtosis(+list(number), -float), zero_or_one). 108 :- info(kurtosis/2, 109 [comment is 'Calculates the (excess) kurtosis of a list of numbers. Fails if the list is empty.', 110 argnames is ['List', 'Kurtosis']]). 105 111 106 112 :- public(variance/2). … … 116 122 argnames is ['Term']]). 117 123 118 :- private(arithmetic_mean/5). 119 :- private(squares_and_cubes/6). 124 :- private(arithmetic_mean/5). 125 :- private(squares_and_cubes/6). 126 :- private(squares_and_hypers/6). 120 127 :- private(variance/6). 121 128
