flatironinstitute / stan-playground

Run Stan models in the browser
Apache License 2.0
5 stars 1 forks source link

Add a method of providing initial values, including from Python/R scripts #139

Open WardBrian opened 2 months ago

WardBrian commented 2 months ago

For initial values, we can similarly allow a magic variable called inits or initialize which should be set to a function that takes in the chain ID and returns initial values. This nicely side-steps the UI issues of how to support multiple initial values for the multiple chains.

magland commented 2 months ago

I think we should hash out exactly how this would work. I have some questions about it. Maybe we can chat in person tomorrow?

WardBrian commented 2 months ago

Sure -- it's also by no means a priority, I just wanted to split the older issue up so we could close it as the main part was completed

magland commented 2 months ago

Are we thinking initial.json in the project? Or is this something that would be called dynamically at the beginning of sampling? I'm uneasy about the latter for a couple reasons. But I'll save those reasons until after I get a better idea of what you had in mind.

WardBrian commented 2 months ago

initial.json in the project is fine if you're initializing all chains at the same point. It becomes problematic when you have different initial values for each chain (which is recommended), as you'd need a variable number of them depending on the current sampling options.

magland commented 2 months ago

That makes sense. But I feel like using data.py/data.R for this is problematic. For data, you run it manually and it replaces the data.json, whereas for inits, it runs automatically and presumably it does not replace data.json at that time. If it needs to be dynamic at the start of sampling, then I think it should be a separate inits.py/inits.R.

Another way to do this is to have data.py handle both... and creates both data.json and inits.json, based on the sampling opts which are available to the script. And when you go to do sampling, if the number of chains does not match inits.json, then you get a helpful error message and know to rerun data.py (or manually paste in new content for inits.json)

WardBrian commented 2 months ago

Sure. I've updated the issue title to reflect that this might not necessarily re-use the data generation files.