prophet-rb 0.3.1 → 0.4.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -2
  3. data/LICENSE.txt +1 -1
  4. data/README.md +149 -2
  5. data/data-raw/LICENSE-holidays.txt +20 -0
  6. data/data-raw/README.md +3 -0
  7. data/data-raw/generated_holidays.csv +29302 -61443
  8. data/lib/prophet/diagnostics.rb +349 -0
  9. data/lib/prophet/forecaster.rb +214 -4
  10. data/lib/prophet/holidays.rb +6 -10
  11. data/lib/prophet/plot.rb +56 -6
  12. data/lib/prophet/stan_backend.rb +10 -1
  13. data/lib/prophet/version.rb +1 -1
  14. data/lib/prophet.rb +23 -7
  15. data/stan/{unix/prophet.stan → prophet.stan} +8 -7
  16. data/vendor/aarch64-linux/bin/prophet +0 -0
  17. data/vendor/aarch64-linux/lib/libtbb.so.2 +0 -0
  18. data/vendor/aarch64-linux/lib/libtbbmalloc.so.2 +0 -0
  19. data/vendor/aarch64-linux/lib/libtbbmalloc_proxy.so.2 +0 -0
  20. data/vendor/aarch64-linux/licenses/sundials-license.txt +25 -63
  21. data/vendor/aarch64-linux/licenses/sundials-notice.txt +21 -0
  22. data/vendor/arm64-darwin/bin/prophet +0 -0
  23. data/vendor/arm64-darwin/lib/libtbb.dylib +0 -0
  24. data/vendor/arm64-darwin/lib/libtbbmalloc.dylib +0 -0
  25. data/vendor/arm64-darwin/licenses/sundials-license.txt +25 -63
  26. data/vendor/arm64-darwin/licenses/sundials-notice.txt +21 -0
  27. data/vendor/x86_64-darwin/bin/prophet +0 -0
  28. data/vendor/x86_64-darwin/lib/libtbb.dylib +0 -0
  29. data/vendor/x86_64-darwin/lib/libtbbmalloc.dylib +0 -0
  30. data/vendor/x86_64-darwin/licenses/sundials-license.txt +25 -63
  31. data/vendor/x86_64-darwin/licenses/sundials-notice.txt +21 -0
  32. data/vendor/x86_64-linux/bin/prophet +0 -0
  33. data/vendor/x86_64-linux/lib/libtbb.so.2 +0 -0
  34. data/vendor/x86_64-linux/lib/libtbbmalloc.so.2 +0 -0
  35. data/vendor/x86_64-linux/lib/libtbbmalloc_proxy.so.2 +0 -0
  36. data/vendor/x86_64-linux/licenses/sundials-license.txt +25 -63
  37. data/vendor/x86_64-linux/licenses/sundials-notice.txt +21 -0
  38. metadata +10 -4
  39. data/stan/win/prophet.stan +0 -175
@@ -1,67 +1,29 @@
1
- Copyright (c) 2002-2016, Lawrence Livermore National Security.
2
- Produced at the Lawrence Livermore National Laboratory.
3
- Written by A.C. Hindmarsh, D.R. Reynolds, R. Serban, C.S. Woodward,
4
- S.D. Cohen, A.G. Taylor, S. Peles, L.E. Banks, and D. Shumaker.
5
- LLNL-CODE-667205 (ARKODE)
6
- UCRL-CODE-155951 (CVODE)
7
- UCRL-CODE-155950 (CVODES)
8
- UCRL-CODE-155952 (IDA)
9
- UCRL-CODE-237203 (IDAS)
10
- LLNL-CODE-665877 (KINSOL)
11
- All rights reserved.
1
+ BSD 3-Clause License
12
2
 
13
- This file is part of SUNDIALS. For details,
14
- see http://computation.llnl.gov/projects/sundials
3
+ Copyright (c) 2002-2022, Lawrence Livermore National Security and Southern Methodist University.
4
+ All rights reserved.
15
5
 
16
6
  Redistribution and use in source and binary forms, with or without
17
- modification, are permitted provided that the following conditions
18
- are met:
19
-
20
- 1. Redistributions of source code must retain the above copyright
21
- notice, this list of conditions and the disclaimer below.
22
-
23
- 2. Redistributions in binary form must reproduce the above copyright
24
- notice, this list of conditions and the disclaimer (as noted below)
25
- in the documentation and/or other materials provided with the
26
- distribution.
27
-
28
- 3. Neither the name of the LLNS/LLNL nor the names of its contributors
29
- may be used to endorse or promote products derived from this software
30
- without specific prior written permission.
31
-
32
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
36
- LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF
37
- ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
39
- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43
29
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
-
45
- Additional BSD Notice
46
- ---------------------
47
- 1. This notice is required to be provided under our contract with
48
- the U.S. Department of Energy (DOE). This work was produced at
49
- Lawrence Livermore National Laboratory under Contract
50
- No. DE-AC52-07NA27344 with the DOE.
51
-
52
- 2. Neither the United States Government nor Lawrence Livermore
53
- National Security, LLC nor any of their employees, makes any warranty,
54
- express or implied, or assumes any liability or responsibility for the
55
- accuracy, completeness, or usefulness of any information, apparatus,
56
- product, or process disclosed, or represents that its use would not
57
- infringe privately-owned rights.
58
-
59
- 3. Also, reference herein to any specific commercial products, process,
60
- or services by trade name, trademark, manufacturer or otherwise does
61
- not necessarily constitute or imply its endorsement, recommendation,
62
- or favoring by the United States Government or Lawrence Livermore
63
- National Security, LLC. The views and opinions of authors expressed
64
- herein do not necessarily state or reflect those of the United States
65
- Government or Lawrence Livermore National Security, LLC, and shall
66
- not be used for advertising or product endorsement purposes.
67
-
@@ -0,0 +1,21 @@
1
+ This work was produced under the auspices of the U.S. Department of
2
+ Energy by Lawrence Livermore National Laboratory under Contract
3
+ DE-AC52-07NA27344.
4
+
5
+ This work was prepared as an account of work sponsored by an agency of
6
+ the United States Government. Neither the United States Government nor
7
+ Lawrence Livermore National Security, LLC, nor any of their employees
8
+ makes any warranty, expressed or implied, or assumes any legal liability
9
+ or responsibility for the accuracy, completeness, or usefulness of any
10
+ information, apparatus, product, or process disclosed, or represents that
11
+ its use would not infringe privately owned rights.
12
+
13
+ Reference herein to any specific commercial product, process, or service
14
+ by trade name, trademark, manufacturer, or otherwise does not necessarily
15
+ constitute or imply its endorsement, recommendation, or favoring by the
16
+ United States Government or Lawrence Livermore National Security, LLC.
17
+
18
+ The views and opinions of authors expressed herein do not necessarily
19
+ state or reflect those of the United States Government or Lawrence
20
+ Livermore National Security, LLC, and shall not be used for advertising
21
+ or product endorsement purposes.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prophet-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-28 00:00:00.000000000 Z
11
+ date: 2022-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdstan
@@ -61,16 +61,18 @@ files:
61
61
  - CHANGELOG.md
62
62
  - LICENSE.txt
63
63
  - README.md
64
+ - data-raw/LICENSE-holidays.txt
65
+ - data-raw/README.md
64
66
  - data-raw/generated_holidays.csv
65
67
  - lib/prophet-rb.rb
66
68
  - lib/prophet.rb
69
+ - lib/prophet/diagnostics.rb
67
70
  - lib/prophet/forecaster.rb
68
71
  - lib/prophet/holidays.rb
69
72
  - lib/prophet/plot.rb
70
73
  - lib/prophet/stan_backend.rb
71
74
  - lib/prophet/version.rb
72
- - stan/unix/prophet.stan
73
- - stan/win/prophet.stan
75
+ - stan/prophet.stan
74
76
  - vendor/aarch64-linux/bin/prophet
75
77
  - vendor/aarch64-linux/lib/libtbb.so
76
78
  - vendor/aarch64-linux/lib/libtbb.so.2
@@ -88,6 +90,7 @@ files:
88
90
  - vendor/aarch64-linux/licenses/stan-license.txt
89
91
  - vendor/aarch64-linux/licenses/stan-math-license.txt
90
92
  - vendor/aarch64-linux/licenses/sundials-license.txt
93
+ - vendor/aarch64-linux/licenses/sundials-notice.txt
91
94
  - vendor/aarch64-linux/licenses/tbb-license.txt
92
95
  - vendor/aarch64-linux/licenses/tbb-third-party-programs.txt
93
96
  - vendor/arm64-darwin/bin/prophet
@@ -104,6 +107,7 @@ files:
104
107
  - vendor/arm64-darwin/licenses/stan-license.txt
105
108
  - vendor/arm64-darwin/licenses/stan-math-license.txt
106
109
  - vendor/arm64-darwin/licenses/sundials-license.txt
110
+ - vendor/arm64-darwin/licenses/sundials-notice.txt
107
111
  - vendor/arm64-darwin/licenses/tbb-license.txt
108
112
  - vendor/arm64-darwin/licenses/tbb-third-party-programs.txt
109
113
  - vendor/x86_64-darwin/bin/prophet
@@ -120,6 +124,7 @@ files:
120
124
  - vendor/x86_64-darwin/licenses/stan-license.txt
121
125
  - vendor/x86_64-darwin/licenses/stan-math-license.txt
122
126
  - vendor/x86_64-darwin/licenses/sundials-license.txt
127
+ - vendor/x86_64-darwin/licenses/sundials-notice.txt
123
128
  - vendor/x86_64-darwin/licenses/tbb-license.txt
124
129
  - vendor/x86_64-darwin/licenses/tbb-third-party-programs.txt
125
130
  - vendor/x86_64-linux/bin/prophet
@@ -139,6 +144,7 @@ files:
139
144
  - vendor/x86_64-linux/licenses/stan-license.txt
140
145
  - vendor/x86_64-linux/licenses/stan-math-license.txt
141
146
  - vendor/x86_64-linux/licenses/sundials-license.txt
147
+ - vendor/x86_64-linux/licenses/sundials-notice.txt
142
148
  - vendor/x86_64-linux/licenses/tbb-license.txt
143
149
  - vendor/x86_64-linux/licenses/tbb-third-party-programs.txt
144
150
  homepage: https://github.com/ankane/prophet-ruby
@@ -1,175 +0,0 @@
1
- // Copyright (c) Facebook, Inc. and its affiliates.
2
-
3
- // This source code is licensed under the MIT license found in the
4
- // LICENSE file in the root directory of this source tree.
5
-
6
- functions {
7
- real[ , ] get_changepoint_matrix(real[] t, real[] t_change, int T, int S) {
8
- // Assumes t and t_change are sorted.
9
- real A[T, S];
10
- real a_row[S];
11
- int cp_idx;
12
-
13
- // Start with an empty matrix.
14
- A = rep_array(0, T, S);
15
- a_row = rep_array(0, S);
16
- cp_idx = 1;
17
-
18
- // Fill in each row of A.
19
- for (i in 1:T) {
20
- while ((cp_idx <= S) && (t[i] >= t_change[cp_idx])) {
21
- a_row[cp_idx] = 1;
22
- cp_idx = cp_idx + 1;
23
- }
24
- A[i] = a_row;
25
- }
26
- return A;
27
- }
28
-
29
- // Logistic trend functions
30
-
31
- real[] logistic_gamma(real k, real m, real[] delta, real[] t_change, int S) {
32
- real gamma[S]; // adjusted offsets, for piecewise continuity
33
- real k_s[S + 1]; // actual rate in each segment
34
- real m_pr;
35
-
36
- // Compute the rate in each segment
37
- k_s[1] = k;
38
- for (i in 1:S) {
39
- k_s[i + 1] = k_s[i] + delta[i];
40
- }
41
-
42
- // Piecewise offsets
43
- m_pr = m; // The offset in the previous segment
44
- for (i in 1:S) {
45
- gamma[i] = (t_change[i] - m_pr) * (1 - k_s[i] / k_s[i + 1]);
46
- m_pr = m_pr + gamma[i]; // update for the next segment
47
- }
48
- return gamma;
49
- }
50
-
51
- real[] logistic_trend(
52
- real k,
53
- real m,
54
- real[] delta,
55
- real[] t,
56
- real[] cap,
57
- real[ , ] A,
58
- real[] t_change,
59
- int S,
60
- int T
61
- ) {
62
- real gamma[S];
63
- real Y[T];
64
-
65
- gamma = logistic_gamma(k, m, delta, t_change, S);
66
- for (i in 1:T) {
67
- Y[i] = cap[i] / (1 + exp(-(k + dot_product(A[i], delta))
68
- * (t[i] - (m + dot_product(A[i], gamma)))));
69
- }
70
- return Y;
71
- }
72
-
73
- // Linear trend function
74
-
75
- real[] linear_trend(
76
- real k,
77
- real m,
78
- real[] delta,
79
- real[] t,
80
- real[ , ] A,
81
- real[] t_change,
82
- int S,
83
- int T
84
- ) {
85
- real gamma[S];
86
- real Y[T];
87
-
88
- for (i in 1:S) {
89
- gamma[i] = -t_change[i] * delta[i];
90
- }
91
- for (i in 1:T) {
92
- Y[i] = (k + dot_product(A[i], delta)) * t[i] + (
93
- m + dot_product(A[i], gamma));
94
- }
95
- return Y;
96
- }
97
-
98
- // Flat trend function
99
-
100
- real[] flat_trend(
101
- real m,
102
- int T
103
- ) {
104
- return rep_array(m, T);
105
- }
106
-
107
-
108
- }
109
-
110
- data {
111
- int T; // Number of time periods
112
- int<lower=1> K; // Number of regressors
113
- real t[T]; // Time
114
- real cap[T]; // Capacities for logistic trend
115
- real y[T]; // Time series
116
- int S; // Number of changepoints
117
- real t_change[S]; // Times of trend changepoints
118
- real X[T,K]; // Regressors
119
- vector[K] sigmas; // Scale on seasonality prior
120
- real<lower=0> tau; // Scale on changepoints prior
121
- int trend_indicator; // 0 for linear, 1 for logistic, 2 for flat
122
- real s_a[K]; // Indicator of additive features
123
- real s_m[K]; // Indicator of multiplicative features
124
- }
125
-
126
- transformed data {
127
- real A[T, S];
128
- A = get_changepoint_matrix(t, t_change, T, S);
129
- }
130
-
131
- parameters {
132
- real k; // Base trend growth rate
133
- real m; // Trend offset
134
- real delta[S]; // Trend rate adjustments
135
- real<lower=0> sigma_obs; // Observation noise
136
- real beta[K]; // Regressor coefficients
137
- }
138
-
139
- transformed parameters {
140
- real trend[T];
141
- real Y[T];
142
- real beta_m[K];
143
- real beta_a[K];
144
-
145
- if (trend_indicator == 0) {
146
- trend = linear_trend(k, m, delta, t, A, t_change, S, T);
147
- } else if (trend_indicator == 1) {
148
- trend = logistic_trend(k, m, delta, t, cap, A, t_change, S, T);
149
- } else if (trend_indicator == 2){
150
- trend = flat_trend(m, T);
151
- }
152
-
153
- for (i in 1:K) {
154
- beta_m[i] = beta[i] * s_m[i];
155
- beta_a[i] = beta[i] * s_a[i];
156
- }
157
-
158
- for (i in 1:T) {
159
- Y[i] = (
160
- trend[i] * (1 + dot_product(X[i], beta_m)) + dot_product(X[i], beta_a)
161
- );
162
- }
163
- }
164
-
165
- model {
166
- //priors
167
- k ~ normal(0, 5);
168
- m ~ normal(0, 5);
169
- delta ~ double_exponential(0, tau);
170
- sigma_obs ~ normal(0, 0.5);
171
- beta ~ normal(0, sigmas);
172
-
173
- // Likelihood
174
- y ~ normal(Y, sigma_obs);
175
- }