# Can't figure out what is wrong with a simple Turing code

**URL:** <https://discourse.julialang.org/t/cant-figure-out-what-is-wrong-with-a-simple-turing-code/97264>\
**Category:** New to Julia\
**Tags:** turing\
**Created:** [April 9, 2023, 12:01am UTC](https://discourse.julialang.org/t/cant-figure-out-what-is-wrong-with-a-simple-turing-code/97264 "2023-04-09T00:01:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [April 9, 2023, 12:01am UTC](https://discourse.julialang.org/t/cant-figure-out-what-is-wrong-with-a-simple-turing-code/97264/1 "2023-04-09T00:01:01Z")

</div>

This is a simple program running on a clean enviroment but it produces an error message which I could not figure out.

```julia
using Pkg
Pkg.add("Distributions")
Pkg.add("Turing")
using Distributions
using Turing

testData = rand(Beta(3, 4), 100);

@model betaSample(rawdata) = begin

    alpha ~ InverseGamma(2, 1/8)
    beta ~ InverseGamma(2, 1/8)

    for i in eachindex(rawdata)
        rawdata[i] ~ Beta(alpha, beta)
    end
end

result_MH = sample(betaSample(testData), MH(250))

```

```julia
Starting Julia...
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _ | |
  | | |_| | | | (_| | | Version 1.8.5 (2023-01-08)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
 project at `~/juliascript/Turing`
LoadError: proposals of type Int64 are not supported
Stacktrace:
 [1] error(::String, ::Type, ::String)
   @ Base ./error.jl:44
 [2] proposal(x::Int64)
   @ Turing.Inference ~/.julia/packages/Turing/Suzsv/src/inference/mh.jl:13
 [3] MH(space::Int64)
   @ Turing.Inference ~/.julia/packages/Turing/Suzsv/src/inference/mh.jl:173
 [4] top-level scope
   @ ~/juliascript/Turing/Turing_Example01.jl:16
 [5] eval
   @ ./boot.jl:368 [inlined]
 [6] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1428
in expression starting at /Users/ssiew/juliascript/Turing/Turing_Example01.jl:16
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Resolving package versions...
  No Changes to `~/juliascript/Turing/Project.toml`
  No Changes to `~/juliascript/Turing/Manifest.toml`
   Resolving package versions...
  No Changes to `~/juliascript/Turing/Project.toml`
  No Changes to `~/juliascript/Turing/Manifest.toml`
ERROR: LoadError: proposals of type Int64 are not supported
Stacktrace:
 [1] error(::String, ::Type, ::String)
   @ Base ./error.jl:44
 [2] proposal(x::Int64)
   @ Turing.Inference ~/.julia/packages/Turing/Suzsv/src/inference/mh.jl:13
 [3] MH(space::Int64)
   @ Turing.Inference ~/.julia/packages/Turing/Suzsv/src/inference/mh.jl:173
 [4] top-level scope
   @ ~/juliascript/Turing/Turing_Example01.jl:19
 [5] eval
   @ ./boot.jl:368 [inlined]
 [6] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1428
in expression starting at /Users/ssiew/juliascript/Turing/Turing_Example01.jl:19

```

```julia
julia> 
(Turing) pkg> status
Status `~/juliascript/Turing/Project.toml`
  [31c24e10] Distributions v0.25.87
  [fce5fe82] Turing v0.24.3

(Turing) pkg> 

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [April 9, 2023, 1:42pm UTC](https://discourse.julialang.org/t/cant-figure-out-what-is-wrong-with-a-simple-turing-code/97264/2 "2023-04-09T13:42:06Z")

</div>

> [@StevenSiew](#):
>
> ```julia-auto
> using Pkg
> Pkg.add("Distributions")
> Pkg.add("Turing")
> using Distributions
> using Turing
> 
> testData = rand(Beta(3, 4), 100);
> 
> @model betaSample(rawdata) = begin
> 
> alpha ~ InverseGamma(2, 1/8)
> beta ~ InverseGamma(2, 1/8)
> 
> for i in eachindex(rawdata)
> rawdata[i] ~ Beta(alpha, beta)
> end
> end
> 
> result_MH = sample(betaSample(testData), MH(250))
> 
> ```

The problem was the construction of `HM`. According to the documentation:

```julia-auto
  MH(space...)

  Construct a Metropolis-Hastings algorithm.

  The arguments space can be

    • Blank (i.e. MH()), in which case MH defaults to using the prior for each parameter as the proposal distribution
...

```

So if you use an empty constructor (i.e., `MH()`), it will work as intended. There are options for passing other samplers or custom functions.
