# Need help with Mamba.jl 🙄

**URL:** https://discourse.julialang.org/t/need-help-with-mamba-jl-roll-eyes/5582
**Category:** Specific Domains
**Tags:** question
**Created:** [August 26, 2017, 9:49pm UTC](https://discourse.julialang.org/t/need-help-with-mamba-jl-roll-eyes/5582 "2017-08-26T21:49:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![KrishnaKanhaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krishnakanhaiya/32/443_2.png) [@KrishnaKanhaiya](https://discourse.julialang.org/u/KrishnaKanhaiya)
#### Post date: [August 26, 2017, 9:49pm UTC](https://discourse.julialang.org/t/need-help-with-mamba-jl-roll-eyes/5582/1 "2017-08-26T21:49:06Z")

</div>

Hello everyone,  
I am using Stan and Mamba to write an API to find the distribution of the parameters of the differential equations.

The API is  
using OrdinaryDiffEq, ParameterizedFunctions, DiffEqBayes, Mamba

```julia
f1 = @ode_def_nohes LotkaVolterraTest1 begin
  dx = a*x - b*x*y
  dy = -c*y + d*x*y
end a=>1.5 b=1.0 c=3.0 d=1.0
u0 = [1.0,1.0]
tspan = (0.0,10.0)
prob1 = ODEProblem(f1,u0,tspan)
sol = solve(prob1,Tsit5())
t = collect(linspace(1,10,10))
using RecursiveArrayTools # for VectorOfArray
randomized = VectorOfArray([(sol(t[i]) + .01randn(2)) for i in 1:length(t)])
data = convert(Array,randomized)
bayesian_result = bayesian_inference(prob1,t,data;num_samples=1,num_warmup=1)

```

The source code of the API is [here](https://github.com/JuliaDiffEq/DiffEqBayes.jl/pull/3)  
**bayesian\_result** is a struct with one of the members as _chain\_results_ which is of type **Mamba.Chains**

```julia
julia> bayesian_result.chain_results
Warmup took (0.00090, 0.0043, 0.0016, 0.00078) seconds, 0.0076 seconds total
Sampling took (0.13, 6.7, 0.025, 0.019) seconds, 6.8 seconds total

                 Mean MCSE StdDev 5% 50% 95% N_Eff N_Eff/s R_hat
lp__ -179 45 89 -248 -200 -49 4.0 0.59 nan
accept_stat__ 0.00 0.00 0.00 0.00 0.00 0.00 4.0 0.59 nan
stepsize__ 14 0.00 0.00 14 14 14 4.0 0.59 nan
treedepth__ 0.00 0.00 0.00 0.00 0.00 0.00 4.0 0.59 nan
n_leapfrog__ 1.0 0.00 0.00 1.0 1.0 1.0 4.0 0.59 nan
divergent__ 1.0 0.00 0.00 1.0 1.0 1.0 4.0 0.59 nan
energy__ 181 45 90 50 222 253 4.0 0.59 nan
sigma[1] 1.6 0.62 1.2 0.55 2.6 2.9 4.0 0.59 nan
sigma[2] 1.1 0.59 1.2 0.32 0.87 2.9 4.0 0.59 nan
theta[1] -0.55 0.69 1.4 -1.8 0.23 0.98 4.0 0.59 nan

Samples were drawn using hmc with nuts.
For each parameter, N_Eff is a crude measure of effective sample size,
and R_hat is the potential scale reduction factor on split chains (at 
convergence, R_hat=1).

DiffEqBayes.StanModel{Int64,Mamba.Chains}(0, Object of type "Mamba.Chains"

Iterations = 1:1
Thinning interval = 1
Chains = 1,2,3,4
Samples per chain = 1

[-48.6759 0.0 … 0.869348 0.228172]

[-248.306 0.0 … 0.505688 0.979491]

[-199.57 0.0 … 2.88785 -1.79169]

[-218.627 0.0 … 0.32407 -1.6235])

```

I want to extract some useful information from this chain.  
When I am doing:

```julia
bayesian_result.chain_results[1:100,["lp__"],:]
Object of type "Mamba.Chains"

Iterations = 1:1
Thinning interval = 1
Chains = 1,2,3,4
Samples per chain = 1

[-48.6759]

[-248.306]

[-199.57]

[-218.627]

```

All well. but when I am trying to extract sigma or theta[1] by  
`bayesian_result.chain_results[1:100,["theta[1]"],:]`  
I get the following error:  
**ERROR: BoundsError: attempt to access 10-element Array{AbstractString,1} at index [[0]]**  
Stacktrace:  
[1] throw\_boundserror(::Array{AbstractString,1}, ::Tuple{Array{Int64,1}}) at ./abstractarray.jl:433  
[2] checkbounds at ./abstractarray.jl:362 [inlined]  
[3] macro expansion at ./multidimensional.jl:441 [inlined]  
[4] \_getindex at ./multidimensional.jl:438 [inlined]  
[5] getindex at ./abstractarray.jl:882 [inlined]  
[6] getindex(::Mamba.Chains, ::UnitRange{Int64}, ::Array{String,1}, ::Int64) at /Users/ayush/.julia/v0.6/Mamba

How do I access the sigma and theta variables from the Mamba chain?  
TIA 🙂

---

<div class="post-metadata">

### Author: ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)
#### Post date: [August 26, 2017, 10:46pm UTC](https://discourse.julialang.org/t/need-help-with-mamba-jl-roll-eyes/5582/2 "2017-08-26T22:46:14Z")

</div>

IIRC the keys for the Mamba chains are of the form `"theta.1", "sigma.1", "sigma.2"` (rather than `"theta[1]"` etc.)

---

<div class="post-metadata">

### Author: ![goedman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goedman/32/217_2.png) [@goedman](https://discourse.julialang.org/u/goedman)
#### Post date: [August 26, 2017, 11:11pm UTC](https://discourse.julialang.org/t/need-help-with-mamba-jl-roll-eyes/5582/3 "2017-08-26T23:11:06Z")

</div>

Correct, e.g. the EightSchools example in Stan.jl.

Rob
