stan-dev / posterior

The posterior R package
https://mc-stan.org/posterior/
Other
167 stars 24 forks source link

Representation as json #27

Open MansMeg opened 5 years ago

MansMeg commented 5 years ago

Im impressed by the progress. Since Im finalizing the posteriordb beta, I realized that it would be good to formalize also how a posterior is represented as json. This would also enable cross-language representations.

Have you thought about this?

I currently represent draws as a named object of numeric arrays. Think a named list of a vector in R, with one vector per parameter.

paul-buerkner commented 5 years ago

I have thought about this, but not sure if may ideas made sense. Bascially, one reason to have the draws_list class (i.e., a list of lists with one element per chain and a numeric vector per parameter per chain) was to represent draws coming from formats such a JSON.

jgabry commented 5 years ago

Have you thought about this?

Not much but seems like a good thing to think about

I currently represent draws as a named object of numeric arrays. Think a named list of a vector in R, with one vector per parameter.

Seems reasonable. If you read this into R (e.g. using jsonlite::fromJSON()) does it give you the structure that @paul-buerkner mentioned? If so then this would already work nicely with this package given that we have the draws_list format.

Also, are you keeping the markov chains separate or combining all chains?

MansMeg commented 5 years ago

Hi! Me and @paul-buerkner spoke about this and we agree that this is working nicely with draws_list(). For the posteriorDB I need to tune a little anyway but otherwise just writing and reading a draws_list to json would probably work great. That would also be a good standard to transfer posteriors between languages, such as jsonstat. So when the formats are maturing we could formalize this as a JSON schema as well. https://json-stat.org/