dummy-link

StanMamba

Integration of Mamba diagnostic plots and CmdStan

Readme

StanMamba

Build Status

Coverage Status

codecov.io

Introduction

StanMamba generates a Mamba.Chains object from the draws generated by CmdStan.

Example usage

using CmdStan, StanMamba, Test, Statistics

ProjDir = dirname(@__FILE__)
cd(ProjDir) do

  bernoullimodel = "
  data { 
    int<lower=1> N; 
    int<lower=0,upper=1> y[N];
  } 
  parameters {
    real<lower=0,upper=1> theta;
  } 
  model {
    theta ~ beta(1,1);
    y ~ bernoulli(theta);
  }
  "

  observeddata = [
    Dict("N" => 10, "y" => [0, 1, 0, 1, 0, 0, 0, 0, 0, 1]),
    Dict("N" => 10, "y" => [0, 1, 0, 0, 0, 0, 1, 0, 0, 1]),
    Dict("N" => 10, "y" => [0, 0, 0, 0, 0, 0, 1, 0, 1, 1]),
    Dict("N" => 10, "y" => [0, 0, 0, 1, 0, 0, 0, 1, 0, 1])
  ]

  global stanmodel, rc, chains, cnames
  stanmodel = Stanmodel(num_samples=1200, thin=2, name="bernoulli", 
    model=bernoullimodel, output_format=:mambachains);

  rc, chains, cnames = stan(stanmodel, observeddata, ProjDir, diagnostics=false,
    CmdStanDir=CMDSTAN_HOME);
    
  @test 0.1 <  mean(chains.value[:, 8, :] ) < 0.6

end # cd

It is also possible to do the conversion after the call to stan():

stanmodel = Stanmodel(num_samples=1200, thin=2, name="bernoulli", 
    model=bernoullimodel);

  rc, sims, cnames = stan(stanmodel, observeddata, ProjDir, diagnostics=false,
    CmdStanDir=CMDSTAN_HOME);
  
  @test 0.1 <  mean(sims[:, 8, :] ) < 0.6
  
  chains = convert_a3d(sims, cnames, Val(:mambachains))
    
  @test 0.1 <  mean(chains.value[:, 8, :] ) < 0.6

Further examples

A separate package, StanMambaExamples.jl, will contain the Mamba based examples originally in Stan.jl.

First Commit

05/11/2018

Last Touched

9 months ago

Commits

49 commits

Used By: