in python/prophet/forecaster.py [0:0]
def sample_predictive_trend(self, df, iteration):
"""Simulate the trend using the extrapolated generative model.
Parameters
----------
df: Prediction dataframe.
iteration: Int sampling iteration to use parameters from.
Returns
-------
np.array of simulated trend over df['t'].
"""
k = self.params['k'][iteration]
m = self.params['m'][iteration]
deltas = self.params['delta'][iteration]
t = np.array(df['t'])
T = t.max()
# New changepoints from a Poisson process with rate S on [1, T]
if T > 1:
S = len(self.changepoints_t)
n_changes = np.random.poisson(S * (T - 1))
else:
n_changes = 0
if n_changes > 0:
changepoint_ts_new = 1 + np.random.rand(n_changes) * (T - 1)
changepoint_ts_new.sort()
else:
changepoint_ts_new = []
# Get the empirical scale of the deltas, plus epsilon to avoid NaNs.
lambda_ = np.mean(np.abs(deltas)) + 1e-8
# Sample deltas
deltas_new = np.random.laplace(0, lambda_, n_changes)
# Prepend the times and deltas from the history
changepoint_ts = np.concatenate((self.changepoints_t,
changepoint_ts_new))
deltas = np.concatenate((deltas, deltas_new))
if self.growth == 'linear':
trend = self.piecewise_linear(t, deltas, k, m, changepoint_ts)
elif self.growth == 'logistic':
cap = df['cap_scaled']
trend = self.piecewise_logistic(t, cap, deltas, k, m,
changepoint_ts)
elif self.growth == 'flat':
trend = self.flat_trend(t, m)
return trend * self.y_scale + df['floor']