Mamba

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mamba

Vincent Grunert
Hi,

I am trying to get a grip of Mamba and came across the following problem:

from the tutorial, as well as in the example there is always a fixed value, such as 0.001 and never a variable passed as a
parameter to the prior distributions in the Model function.

Now I am trying to compute a  linear regression model.
This requires to compute the prior parameter distributions from the data.
When I pass these values to the prior distributions in the model, the following error pops up:

ERROR: LoadError: type RemoteException has no field model
 in mcmc_master! at /home/vincent/.julia/v0.4/Mamba/src/model/mcmc.jl:53
 in mcmc at /home/vincent/.julia/v0.4/Mamba/src/model/mcmc.jl:35



Here is the code:


function baylinreg(  )
    n = 100

    ##data
    data = rand(n, 2)
    data = Dict{Symbol, Any}(
        :x => data,
        :y => 2 + 2*data[:,1] + 0.1*data[:, 2] + rand(Normal(0,0.5), n)
    )
    data[:xmat] = [ones(n) data[:x]]
   
    X = data[:xmat]
    y = data[:y]
    k = size(X,2)
    df = n - k

    #regression paramters
    V = X'X |> inv
    beta = V * X'y
    err = y - X*beta
   
    #regression variance  = sse / df
    sgm2 = sumabs2(err) / df

    ##model
    model = Model(
        y = Stochastic(1,
            @modelexpr(mu, s2,
                MvNormal(mu, sqrt(s2))
            ),
            false
        ),
        mu = Logical(1,
            @modelexpr(xmat, beta,
                xmat * beta
            ),
            false
        ),

        beta = Stochastic(1,
            :(MvNormal(3, sgm2))

        #in the tutorial this looks like
            :(MvNormal(3, sqrt(1000))
        ),

        #pass the computed variance as a parameter
        #to the inverse gamma distribution
        s2 = Stochastic(
            :(InverseGamma( df / 2.  , 1. / sgm2 ))
    
       #in the tutorial this looks like
            :(InverseGamma( 0.001, 0.001 ))
        )
    )

    scheme1 = [NUTS([:beta]),
                      Slice([:s2], [3.0])
    setsamplers!(model, scheme1)
  

    ##initial values
    inits = [     Dict(:y => data[:y], :beta => rand(Normal(0,1), 3), :s2 => rand(Gamma(1,1))),
                Dict(:y => data[:y], :beta => rand(Normal(0,1), 3), :s2 => rand(Gamma(1,1))),
                Dict(:y => data[:y], :beta => rand(Normal(0,1), 3), :s2 => rand(Gamma(1,1))),
    ]
    sim1 = mcmc(model, data, inits, 10000, burnin=250, thin=2, chains=3)
    sim1 |> describe

end
baylinreg()

Am I missing something?

--
You received this message because you are subscribed to the Google Groups "julia-stats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.