-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Stan backend #347
base: master
Are you sure you want to change the base?
[WIP] Stan backend #347
Conversation
will document on sub-types of input and output
Hello @hyunjimoon! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2022-09-11 12:48:26 UTC |
Tom Fiddaman (from Vensim) shared his recent talk on calibration which is relevant to our goal. Based on PySD team's warm greeting and Vensim team's recent interest, may I go one step further from inference to calibration on this PR? I carefully drafted my opinion of future plans, detailed list of works, and some questions. Work for Vensim-PySD-Stan Calibration CollaborationTable for the whole workflow is one the first pr documentation here. Vensim-PySD-Stan
PySD-Stan
Question for discussion
|
HI @hyunjimoon @Dashadower |
@hyunjimoon @Dashadower also mention that currently the tests are "waiting for approval". I will not approve them until you have included the test for the new builder so we save sending jobs to GitHub Actions. |
Stan backend d2d
4c56ed6
to
daf724c
Compare
@Dashadower and I am planning for a test:
I would need @Dashadower's help on completing stan_builder's @JamesPHoughton Could you confirm the above would be enough to build trust on stan-interface modeling on which our future collaboration can be based? |
@hyunjimoon @Dashadower I would recommend you to merge the master branch from PySD into your branch. So you do not work with an outdated version of PySD. We fixed some bugs related to the latest parsimonious and pandas releases. And there are several other bug fixes and new features. |
Description
1. What is this PR doing and how?
The main contribution of this PR is inference; its benefits are estimating parameter values and calibration. Currently pysd is doing a good job in data generation conditional on parameter values but lacks modules that retrieves parameter from the generated data. This pr aims to fill the gap; Stan is a computational Bayesian statistics package, with a large eco-system, providing state of the art inference algorithms including MCMC (HMC-NUTS) and variational inference. Given the following input from users, our output is posterior samples of estimated parameters.
dynamic model in .mdl or .xmile or .stmx format
user's classification of
a. assumed parameter
a-1. time series of parameters (e.g. temperature or demand)
a-2. fixed value of parameter (e.g. size of one franchise branch)
b. estimated parameter (e.g. delay time of shipment)
b-1. prior distribution
b-2. prior parameter
c. observed state (stock variables with observed data)
Under the hood, files under
pysd/builders/stan
folder, we parsexmile
,mdl
,stmx
files into one Stan code file.stan
and pass it to Stan's state of the art MCMC infefinference engine, which serves inverse process of pysd's data generation. Stan has a large ecosystem that supports both calibration and model expansion (e.g. hierarchical regression, generalized linear).These are tested in
test_scripts
folder, and main parsing logics are in here and here. (SQ3. could you add some detailes on each file in the last sentence?)2. Future plans
This is part of SilkRoad project documented here.
SilkRoad, where User and Programs
.function(input)
)Vensim
assists U1.a().mdl
PySD
assists U2.a()est_param
,ass_param
, b. Selectobs_state
among stocksest_param
) and Have (assume:ass_param
, observe:obs_state
).json
PySD
,.read_vensim
(U1.a): Switch lang. from FP to OOP.py
assmed_param
, b. Choosefamily
(:= dist. ofmsr_err_scale
)object
,.json
prior_family
(est_param
's prior dist. type) , b. Setprior_param
(est_param
's prior param).json
PySD
,.run
(U2.ab, U3.ab): Generate synthetic dataobject
PySD
,.create_stan_program
(U2.ab, U3.ab): Switch lang. from OOP to PPL.stan
iter_sampling
(:= # of samples)int
Stan
,.sample
(P2, P3, U5.a)): Sample posterior draws (optimize measure with specified precision)object
Our work is casting dynamic model into statistical model structure as part of Bayesian workflow project which provides principled guidelines for model building.
Two works are planned for the near future and it would be tremendously helpful some support could be given in the second.
Currently
integration
,random generation
,lookup
are completed (but need testing) andsmooth
is in progress. Some parts we are missing:if then else
,step
(usingif then else
),pulse
(point mass + divide by dt),delay
(hard..),material memory
(not possible in stan as it does not allow).PR verification (to be filled by reviewers)