Created
December 21, 2021 23:51
-
-
Save tommylees112/ce016833a18c1a6615c4b38bdad1eb1b to your computer and use it in GitHub Desktop.
Trying to work with abcmodel: https://discourse.mc-stan.org/t/fitting-parameters-of-a-simple-process-model-optimisation-uncertainty/16349/14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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