stl-rb 0.1.1 → 0.1.2

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: 8c050d95d79bc0c5d644257c5cb5130d595dd7fe18c691b0e71eed7ecfef7a0d
4
- data.tar.gz: 7c644155be7b848965299b62423e03ffa05bf17143fd76ca804bc5e4b36c03b2
3
+ metadata.gz: 42727b920b10d60aa69dad26babcc4f4112c46ad3d7c6f9d23cb6dff641862b3
4
+ data.tar.gz: 4f02b1fa6dbd16655e2d77389f0f6a064353f36c7208287dba07cea3dc8f704d
5
5
  SHA512:
6
- metadata.gz: 47a0248efdeb721218a9b5e1642e3e0b28735cb2692085c9ebc8f879d1cbc26bf2eb615611627d4a3873d9efda63da81fe214853eaae9901f74bddfc4bfac3e1
7
- data.tar.gz: ef7bbb4ba3039a1f2703875165047dc87e4ad3bdfad5f3050f7faa3478560ca022735f226f171355394ef7e87edfd545dfa79f437026b4db336286e0592e6d47
6
+ metadata.gz: 684faab8a79a777a80c479172ec95b06134e2216ea355282d154b45e667d2ede0e5fb38d555918aa78123bb123ce548a492bf7924116176daa97a65886372868
7
+ data.tar.gz: 75d3e012833030dd89ea50eb1dd84833ec06dfc38c36801ab6eda9394ad33199ea0d1d662322571d74b718a184e7680fc65a5985d8065fc4d7212f0577a17707
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.2 (2021-10-24)
2
+
3
+ - Added `seasonal_strength` and `trend_strength` methods
4
+ - Improved plot width and height
5
+
1
6
  ## 0.1.1 (2021-10-20)
2
7
 
3
8
  - Added `plot` method
data/README.md CHANGED
@@ -84,6 +84,20 @@ And use:
84
84
  Stl.plot(series, decompose_result)
85
85
  ```
86
86
 
87
+ ## Strength
88
+
89
+ Get the seasonal strength
90
+
91
+ ```ruby
92
+ Stl.seasonal_strength(decompose_result)
93
+ ```
94
+
95
+ Get the trend strength
96
+
97
+ ```ruby
98
+ Stl.trend_strength(decompose_result)
99
+ ```
100
+
87
101
  ## Credits
88
102
 
89
103
  This library was ported from the [Fortran implementation](https://www.netlib.org/a/stl).
@@ -91,6 +105,7 @@ This library was ported from the [Fortran implementation](https://www.netlib.org
91
105
  ## References
92
106
 
93
107
  - [STL: A Seasonal-Trend Decomposition Procedure Based on Loess](https://www.scb.se/contentassets/ca21efb41fee47d293bbee5bf7be7fb3/stl-a-seasonal-trend-decomposition-procedure-based-on-loess.pdf)
108
+ - [Measuring strength of trend and seasonality](https://otexts.com/fpp2/seasonal-strength.html)
94
109
 
95
110
  ## History
96
111
 
data/lib/stl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stl
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/stl.rb CHANGED
@@ -91,6 +91,19 @@ module Stl
91
91
  Vega.lite
92
92
  .data(data)
93
93
  .vconcat(charts)
94
+ .config(autosize: {type: "fit-x", contains: "padding"})
95
+ .width(nil) # prevents warning
96
+ .height(nil) # prevents warning and sets div height to auto
97
+ end
98
+
99
+ def seasonal_strength(result)
100
+ sr = result[:seasonal].zip(result[:remainder]).map { |a, b| a + b }
101
+ [0, 1 - var(result[:remainder]) / var(sr)].max
102
+ end
103
+
104
+ def trend_strength(result)
105
+ tr = result[:trend].zip(result[:remainder]).map { |a, b| a + b }
106
+ [0, 1 - var(result[:remainder]) / var(tr)].max
94
107
  end
95
108
 
96
109
  private
@@ -102,5 +115,10 @@ module Stl
102
115
  v.strftime("%Y-%m-%dT%H:%M:%S.%L%z")
103
116
  end
104
117
  end
118
+
119
+ def var(series)
120
+ mean = series.sum / series.size.to_f
121
+ series.sum { |v| (v - mean) ** 2 } / (series.size.to_f - 1)
122
+ end
105
123
  end
106
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stl-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2021-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rice