iter=8000, warmup=2000, control=control, thin=6 ) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of mu tools.plot_ssm(mcmc_sample, sales_df_3['date'], 'local liner trend', 'sales', 'mu', sales_df_3['sales']) # plot ssm of delta tools.plot_ssm(mcmc_sample, sales_df_3['date'], 'drift', 'delta', 'delta')
sm = pickle.load(open('%s.pkl' % filename, 'rb')) # sm = pystan.StanModel(file='5-4-1-simple-reg.stan') else: # a model using prior for mu and sigma. sm = pystan.StanModel(file='%s.stan' % filename) control = {'adapt_delta': 0.8, 'max_treedepth': 10} mcmc_result = sm.sampling(data=stan_data, seed=1, chains=4, iter=8000, warmup=2000, control=control, thin=6) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of probs tools.plot_ssm(mcmc_sample, np.arange(0, len(boat_df['x'])), 'autoregressive local trend', 'prob.', 'probs', boat_df['x'])
sm = pickle.load(open('%s.pkl' % filename, 'rb')) # sm = pystan.StanModel(file='5-4-1-simple-reg.stan') else: # a model using prior for mu and sigma. sm = pystan.StanModel(file='%s.stan' % filename) control = {'adapt_delta': 0.8, 'max_treedepth': 16} mcmc_result = sm.sampling(data=stan_data, seed=1, chains=4, iter=8000, warmup=2000, control=control, thin=6) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of mu tools.plot_ssm(mcmc_sample, sales_df_5['date'], 'autoregressive local trend', 'sales', 'alpha', sales_df_5['sales'])
control=control, thin=1 ) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('5-3-2-local-level-interpolation.pkl'): with open('5-3-2-local-level-interpolation.pkl', 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract() # plot ssm tools.plot_ssm(mcmc_sample, sales_df['date'], 'local level model', 'sales', 'mu', sales_df['sales']) # plot ssm about prediction tools.plot_ssm(mcmc_sample, sales_df['date'], 'local level model', 'sales', 'y_pred', sales_df['sales'])
print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of alpha (trend and cycle) tools.plot_ssm(mcmc_sample, sales_df_4['date'], 'all state', 'sales', 'alpha', sales_df_4['sales']) # plot ssm of mu (only trend) tools.plot_ssm(mcmc_sample, sales_df_4['date'], 'only trend', 'sales', 'mu', sales_df_4['sales']) # plot ssm of gamma (only cycle) tools.plot_ssm(mcmc_sample, sales_df_4['date'], 'only cycle',
mcmc_result = sm.sampling(data=stan_data, seed=1, chains=4, iter=3000, warmup=2000, control=control, thin=6) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of probs tools.plot_ssm(mcmc_sample, fish_df['date'], 'expectation of state', 'prob.', 'lambda_exp', fish_df['fish_num']) tools.plot_ssm(mcmc_sample, fish_df['date'], 'expectation of state without random', 'prob.', 'lambda_smooth', fish_df['fish_num']) tools.plot_ssm(mcmc_sample, fish_df['date'], 'expectation of state without random and fixed temperature', 'prob.', 'lambda_smooth_fix', fish_df['fish_num'])
if os.path.exists('%s.pkl' % filename): sm = pickle.load(open('%s.pkl' % filename, 'rb')) # sm = pystan.StanModel(file='5-4-1-simple-reg.stan') else: # a model using prior for mu and sigma. sm = pystan.StanModel(file='%s.stan' % filename) control = {'adapt_delta': 0.99, 'max_treedepth': 16} mcmc_result = sm.sampling(data=stan_data, seed=1, chains=4, iter=8000, warmup=1200, control=control, thin=6) print(mcmc_result) mcmc_result.plot() plt.show() # saving compiled model if not os.path.exists('%s.pkl' % filename): with open('%s.pkl' % filename, 'wb') as f: pickle.dump(sm, f) mcmc_sample = mcmc_result.extract(permuted=True) # plot ssm of mu tools.plot_ssm(mcmc_sample, sales_df_3['date'], 'smooth trend model', 'sales', 'mu', sales_df_3['sales'])