philiprehberger-math_kit 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +9 -0
- data/lib/philiprehberger/math_kit/stats.rb +24 -0
- data/lib/philiprehberger/math_kit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 749c0a9a1c673c58a1ba320d3bbf2dacf89328a3feedb166d76ef18dcca60284
|
|
4
|
+
data.tar.gz: 5698fb8599aa8343585a5cd64cd5b95bce81b6fb919a688aa7435af9a60882ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8019d5ee6e9f7e78cb2609f830d944f164aa77a333b49abadd6e75d4c62e3ba100f022f7c2212648bff3ac1d4ac362f6ec1cd575acad39164992727cb6aa2f44
|
|
7
|
+
data.tar.gz: 392bb7e9c895353d838582f5d80467d8edd3f46ecc9f0bb98c854079106dedcfd5c38f79e03646371f05b08cb847799d92f8041bba05c088374ea6664ab255d9
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-05-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Stats.iqr(values)` — interquartile range (Q3 - Q1), commonly used for outlier detection.
|
|
14
|
+
|
|
15
|
+
## [0.5.0] - 2026-04-21
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `Stats.sum_of_squares(values)` — sum of squared deviations from the mean, a building block for variance, regression residuals, and ANOVA; returns 0.0 for empty or single-element inputs
|
|
19
|
+
|
|
10
20
|
## [0.4.0] - 2026-04-15
|
|
11
21
|
|
|
12
22
|
### Added
|
|
@@ -77,7 +87,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
77
87
|
- Rounding modes: bankers (round half to even), ceiling, floor, truncate with precision
|
|
78
88
|
- Simple moving average and exponential moving average
|
|
79
89
|
|
|
80
|
-
[Unreleased]: https://github.com/philiprehberger/rb-math-kit/compare/v0.
|
|
90
|
+
[Unreleased]: https://github.com/philiprehberger/rb-math-kit/compare/v0.6.0...HEAD
|
|
91
|
+
[0.6.0]: https://github.com/philiprehberger/rb-math-kit/compare/v0.5.0...v0.6.0
|
|
92
|
+
[0.5.0]: https://github.com/philiprehberger/rb-math-kit/compare/v0.4.0...v0.5.0
|
|
81
93
|
[0.4.0]: https://github.com/philiprehberger/rb-math-kit/compare/v0.3.0...v0.4.0
|
|
82
94
|
[0.3.0]: https://github.com/philiprehberger/rb-math-kit/compare/v0.2.3...v0.3.0
|
|
83
95
|
[0.2.3]: https://github.com/philiprehberger/rb-math-kit/compare/v0.2.2...v0.2.3
|
data/README.md
CHANGED
|
@@ -41,6 +41,13 @@ Philiprehberger::MathKit::Stats.stddev([2, 4, 4, 4, 5, 5, 7, 9]) # => 2.0
|
|
|
41
41
|
Philiprehberger::MathKit::Stats.percentile([1, 2, 3, 4, 5], 50) # => 3.0
|
|
42
42
|
Philiprehberger::MathKit::Stats.sum([1, 2, 3]) # => 6
|
|
43
43
|
Philiprehberger::MathKit::Stats.range([1, 5, 3, 9, 2]) # => 8
|
|
44
|
+
Philiprehberger::MathKit::Stats.sum_of_squares([1, 2, 3]) # => 2.0
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Interquartile Range
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
Philiprehberger::MathKit::Stats.iqr([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # => 4.5
|
|
44
51
|
```
|
|
45
52
|
|
|
46
53
|
### Summary Statistics
|
|
@@ -160,7 +167,9 @@ Philiprehberger::MathKit::Numeric.clamp(42, 0, 10) # => 10
|
|
|
160
167
|
| `.variance(values, population: true)` | Population or sample variance |
|
|
161
168
|
| `.stddev(values, population: true)` | Standard deviation |
|
|
162
169
|
| `.percentile(values, p)` | Percentile (0-100) with linear interpolation |
|
|
170
|
+
| `.iqr(values)` | Interquartile range (Q3 - Q1) |
|
|
163
171
|
| `.sum(values)` | Sum of values |
|
|
172
|
+
| `.sum_of_squares(values)` | Sum of squared deviations from the mean (0.0 for empty/single input) |
|
|
164
173
|
| `.range(values)` | Max - min |
|
|
165
174
|
| `.skewness(values)` | Sample skewness (Fisher-Pearson) |
|
|
166
175
|
| `.kurtosis(values)` | Sample excess kurtosis (Fisher definition) |
|
|
@@ -97,6 +97,17 @@ module Philiprehberger
|
|
|
97
97
|
(sorted[lower] + (fraction * (sorted[upper] - sorted[lower]))).to_f
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
+
# Interquartile range (Q3 - Q1) using linear interpolation
|
|
101
|
+
#
|
|
102
|
+
# @param values [Array<Numeric>] the input values
|
|
103
|
+
# @return [Float] Q3 minus Q1
|
|
104
|
+
# @raise [ArgumentError] if values is empty
|
|
105
|
+
def iqr(values)
|
|
106
|
+
raise ArgumentError, 'values must not be empty' if values.empty?
|
|
107
|
+
|
|
108
|
+
percentile(values, 75) - percentile(values, 25)
|
|
109
|
+
end
|
|
110
|
+
|
|
100
111
|
# Sum of values
|
|
101
112
|
#
|
|
102
113
|
# @param values [Array<Numeric>] the input values
|
|
@@ -105,6 +116,19 @@ module Philiprehberger
|
|
|
105
116
|
values.sum
|
|
106
117
|
end
|
|
107
118
|
|
|
119
|
+
# Sum of squared deviations from the mean: \sum_i (x_i - mean)^2.
|
|
120
|
+
# Building block for variance, regression residuals, ANOVA, etc.
|
|
121
|
+
# Returns 0.0 for empty or single-element inputs.
|
|
122
|
+
#
|
|
123
|
+
# @param values [Array<Numeric>] the input values
|
|
124
|
+
# @return [Float] the sum of squares
|
|
125
|
+
def sum_of_squares(values)
|
|
126
|
+
return 0.0 if values.size < 2
|
|
127
|
+
|
|
128
|
+
avg = mean(values)
|
|
129
|
+
values.sum(0.0) { |v| (v - avg)**2 }
|
|
130
|
+
end
|
|
131
|
+
|
|
108
132
|
# Range (max - min)
|
|
109
133
|
#
|
|
110
134
|
# @param values [Array<Numeric>] the input values
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-math_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Descriptive statistics, linear interpolation, rounding modes, and moving
|
|
14
14
|
averages. Lightweight math toolkit with zero dependencies.
|