Skip to content
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

Formatting loaded values #1

Closed
sethaxen opened this issue Oct 25, 2022 · 1 comment · Fixed by #7
Closed

Formatting loaded values #1

sethaxen opened this issue Oct 25, 2022 · 1 comment · Fixed by #7
Labels
discussion enhancement New feature or request

Comments

@sethaxen
Copy link
Owner

sethaxen commented Oct 25, 2022

Currently, we just return all loaded objects from JSON files without modification. JSON3 generates Objects, which are AbstractDict{Symbol}s but can also be accessed with string indices and a dot syntax. We may want to reformat these outputs for better compatibility with Julia. For example:

  1. We want to make sure that loaded reference posterior draws implement the Tables interface. The eltype of the vector of draws should be the narrowest possible eltype. The idea is to make it straightforward for users to analyze the draws, e.g. by plotting them.
  2. posteriordb stores matrices as lists of row vectors (https://github.com/stan-dev/posteriordb/blob/master/doc/DATABASE_CONTENT.md#datadata; because JSON has no way to encode matrices). To avoid confusion and allow use, we should package these as matrices.

Since posteriordb is very Stan-focused (only contains one pymc model) and will for now likely be used in conjunction with the StanJulia packages, a useful check would be that we can use all model code and data directly in StanSample.jl.

@sethaxen
Copy link
Owner Author

sethaxen commented Nov 4, 2022

I propose we format all JSON outputs to be AbstractDict{String}s, as these still implement the Tables interface. We may also want to use OrderedCollections.OrderedDict to store the outputs, as this preserves the ordering in case that is important, and OrderedCollections is a light and common dependency.

julia> using Tables, OrderedCollections, DataFrames

julia> d = OrderedDict("x" => randn(100), "y" => randn(100));

julia> DataFrame(columntable(d))
100×2 DataFrame
 Row │ x           y         
     │ Float64     Float64   
─────┼───────────────────────
   10.194559    1.88364
   20.514289   -0.979216
   30.731907   -0.262208
   4-0.232648    1.93591
             
  980.613435    0.404689
  990.541503   -0.654151
 1000.0387091  -0.261594
              93 rows omitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant