philiprehberger-math_kit 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a73db6abf0e0f987688786bd18c0b959182dc5290c52ac52e04a55926361436e
4
- data.tar.gz: 85c7d136bf63030f7009b736aa0d44c81429e383973bb8bd65ca58f0aa08c927
3
+ metadata.gz: e5160a941a8d5e202674e87876873e770f8c1977e9a16bcc3123e58a5a6b665d
4
+ data.tar.gz: b3ec9ac5e16e4defa442e6c9470065540da9acbbe4281884b034a66d91ec5b57
5
5
  SHA512:
6
- metadata.gz: 63bbbb1ca5f8c31f476dbb87f9df33569a4cdd420e49b736f2a5289c5f7e3839cff4cc3353af2c8db87f5bf909feb7b7047088e29167ea36d7318752c271848c
7
- data.tar.gz: 183f0a9fec1904a98d37520df268f260e7f6e4dd9e32403fc5ce1ef3e3fdf1d346947d1751e757a4d81de0eae73cd215b393c19faa82a3b7510d7ff4b23d6c9a
6
+ metadata.gz: 75957977d35a9313b370f65ab8c9bc99fa267eb0b14e93a4c2e802ef671ea5926991e871fc8794724dd3c58c1dec49accbca4d34ab181dac5907c257a4fcf998
7
+ data.tar.gz: ef5a5f0e61a225e88b8a232da5e60472a7aad51c0512163eb82a5e85207977fce943388142fcaa210252d8a104392a472a7069fc16dc38e2b5e70b5d4d9027e2
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-04-21
11
+
12
+ ### Added
13
+ - `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
14
+
10
15
  ## [0.4.0] - 2026-04-15
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -41,6 +41,7 @@ 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
44
45
  ```
45
46
 
46
47
  ### Summary Statistics
@@ -161,6 +162,7 @@ Philiprehberger::MathKit::Numeric.clamp(42, 0, 10) # => 10
161
162
  | `.stddev(values, population: true)` | Standard deviation |
162
163
  | `.percentile(values, p)` | Percentile (0-100) with linear interpolation |
163
164
  | `.sum(values)` | Sum of values |
165
+ | `.sum_of_squares(values)` | Sum of squared deviations from the mean (0.0 for empty/single input) |
164
166
  | `.range(values)` | Max - min |
165
167
  | `.skewness(values)` | Sample skewness (Fisher-Pearson) |
166
168
  | `.kurtosis(values)` | Sample excess kurtosis (Fisher definition) |
@@ -105,6 +105,19 @@ module Philiprehberger
105
105
  values.sum
106
106
  end
107
107
 
108
+ # Sum of squared deviations from the mean: \sum_i (x_i - mean)^2.
109
+ # Building block for variance, regression residuals, ANOVA, etc.
110
+ # Returns 0.0 for empty or single-element inputs.
111
+ #
112
+ # @param values [Array<Numeric>] the input values
113
+ # @return [Float] the sum of squares
114
+ def sum_of_squares(values)
115
+ return 0.0 if values.size < 2
116
+
117
+ avg = mean(values)
118
+ values.sum(0.0) { |v| (v - avg)**2 }
119
+ end
120
+
108
121
  # Range (max - min)
109
122
  #
110
123
  # @param values [Array<Numeric>] the input values
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module MathKit
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
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.0
4
+ version: 0.5.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-04-15 00:00:00.000000000 Z
11
+ date: 2026-04-21 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.