MCPcopy
hub / github.com/facebook/prophet / sample_model

Method sample_model

python/prophet/forecaster.py:1509–1537  ·  view source on GitHub ↗

Simulate observations from the extrapolated generative model. Parameters ---------- df: Prediction dataframe. seasonal_features: pd.DataFrame of seasonal features. iteration: Int sampling iteration to use parameters from. s_a: Indicator vector for add

(self, df, seasonal_features, iteration, s_a, s_m)

Source from the content-addressed store, hash-verified

1507 return sim_values
1508
1509 def sample_model(self, df, seasonal_features, iteration, s_a, s_m) -> Dict[str, np.ndarray]:
1510 """Simulate observations from the extrapolated generative model.
1511
1512 Parameters
1513 ----------
1514 df: Prediction dataframe.
1515 seasonal_features: pd.DataFrame of seasonal features.
1516 iteration: Int sampling iteration to use parameters from.
1517 s_a: Indicator vector for additive components
1518 s_m: Indicator vector for multiplicative components
1519
1520 Returns
1521 -------
1522 Dictionary with `yhat` and `trend`, each like df['t'].
1523 """
1524 trend = self.sample_predictive_trend(df, iteration)
1525
1526 beta = self.params['beta'][iteration]
1527 Xb_a = np.matmul(seasonal_features.values,
1528 beta * s_a.values) * self.y_scale
1529 Xb_m = np.matmul(seasonal_features.values, beta * s_m.values)
1530
1531 sigma = self.params['sigma_obs'][iteration]
1532 noise = np.random.normal(0, sigma, df.shape[0]) * self.y_scale
1533
1534 return {
1535 'yhat': trend * (1 + Xb_m) + Xb_a + noise,
1536 'trend': trend
1537 }
1538
1539 def sample_model_vectorized(
1540 self,

Callers 1

Calls 1

Tested by

no test coverage detected