JuliaStats / Klara.jl

MCMC inference in Julia
Other
166 stars 38 forks source link

Is there any guidance for custom sample space #172

Open Roger-luo opened 6 years ago

Roger-luo commented 6 years ago

Hi guys, I would like to sample from a lattice configuration (some Array contains only 0 and 1), each sample looks like [0, 1, 0, 1, 1]. and I have a distribution function for it.

How can I tweak your sampler to accomplish this task? Is there any guidance I could read? Do I need to define a new variate type in Distributions.jl too?

papamarkou commented 6 years ago

I understand your discrete parameter space is represented by an n-length vector (not matrix)? Do you have a proposal kernel for this, and if yes, in what form does it come, Is it a Markov transition matrix or a distribution conditional on the current state? Is the proposal symmetric or asymmetric?

Roger-luo commented 6 years ago

@scidom OK, this is a more detailed and more precise description:

About the sample space

The parameter space is an array (with arbitrary dimension) contains {0, 1} (sometimes {-1, 1} or {-0.5, 0.5}). Each metropolis step will flip some of them randomly (means flip the spin at n random positions)

a spin may looks like an array with tags

mutable struct Spin{T, N}
   up::T
   down::T
   data::Array{T, N}
end

the initialization is totally random, which can be done by this Julia command rand(shape, [up, down]). But the flip operation is different (which will be the proposal state in metropolis hasting).

About how to flip (generate a proposal for next step)

Generally, the next state will be generated based on previous state in metropolis, which means flip n spins in the array.

But how to flip it may different depends on the problem. And may have the following ways (So different type may need to be defined)

  1. use a uniform random offset to choose n positions to flip
  2. each you filp a spin (let's assume this spin is up) you need to find another spin randomly (which is down) and flip it to keep the total sum unchanged.
  3. etc.