Skip to content

Instantly share code, notes, and snippets.

@tommylees112
Created December 21, 2021 23:51
Show Gist options
  • Save tommylees112/ce016833a18c1a6615c4b38bdad1eb1b to your computer and use it in GitHub Desktop.
Save tommylees112/ce016833a18c1a6615c4b38bdad1eb1b to your computer and use it in GitHub Desktop.
from pathlib import Path
from cmdstanpy import cmdstan_path, CmdStanModel, CmdStanMCMC
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from typing import Dict
import arviz as az
model_dir = Path("stan_code")
data_dir = Path("data")
# ---- data ---- #
Q: np.ndarray = None
precip: np.ndarray = None
intial_state: float = 0.0
discharge_data: Dict = { "T" : len(Q), "Q" : Q , "P": precip}
# ---- model ---- # 
stan_file = model_dir / "abcmodel.stan"
stan_model = CmdStanModel(stan_file=stan_file)
stan_model.compile()
# ---- fit parameters ---- # 
abcmodel_fit: CmdStanMCMC = stan_model.sample(
data=discharge_data,
chains=4,
cores=1,
seed=1111,
show_progress=True,
)
# ---- get simulations ---- #
posterior = az.from_cmdstanpy(
posterior=bern_fit,
posterior_predictive="y",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment