Skip to content

StanJulia/StanIO.jl

Repository files navigation

StanIO.jl

Project Status Build Status

Purpose

A number of extensions to the Stan Programming Language have been proposed (see Bob Carpenter).

StanIO.jl will track the consequences of these changes in both input and output needed for Stan.

Over time, similar functionality will be made available in StanSample.jl and possibly other StanJulia packages (e.g. StanOptimize.jl).

This package is related to similar work in python by Brian Ward. Handling of tuples is based on Brian's reshape.py.

Currently it converts nested variables in Stan .csv files (including .csv files with complex variables, rectangular arrays, tuples and mixed tuples and arrays) to an array using extract_reshape().

Usage

using StanIO

# Define an array of names of Stan .csv file

csvfiles = filter(x -> x[end-3:end] == ".csv", readdir(joinpath(stanio_data, "mixed_02")))
csvfiles = joinpath.(joinpath(stanio_data, "mixed_02"), csvfiles)

a = extract_reshape(csvfiles, "m"); # Returns a nested 2D array [nsamples, nchains] of m
a[1, 1]

# or

b = extract_reshape(csvfiles, "m"; nested=false); # for a single array
b[1, 1, :, :]

In StanSample.jl the nested array functionality is available as:

ndf = read_samples(sm, :nesteddataframe) # sm is a StanSampleModel.

Further examples

Please see this stanio_example.jl Pluto notebook or these test scripts for examples.