
include("Util_single.jl")


@everywhere module ReversibleJumpSingleParticle
using StatsBase
using KernelDensity
using Distributions
using SingleParticle

export bounds_check, judge, MCstep, MCstep_parallel, update_stepsize
export ReversibleParticle, init_particle

mutable struct ReversibleParticle
    x_present::Array{Float64, 1}
    obj_func::Function # return relative weight
    obj_func_val::Float64
    weight::Float64
    cov::Array{Float64, 2}
    model_id::Int
end

function init_particle(lbs, ubs, obj_func, weight, model_id)
    """
    obj_func: must return -1 as a flag if has an error.
    """
    @assert length(lbs) == length(ubs)
    num_param = length(lbs)
    obj_func_val = -1
    kernel = Uniform(0, 10)
    x_present = zeros(length(lbs))   # generate parameter
    while obj_func_val < 0
        for i in 1:num_param
            x_present[i] = rand(kernel)
        end
        obj_func_val = obj_func(x_present)
    end
    return ReversibleParticle(x_present, obj_func, obj_func_val, weight, eye(num_param), model_id)
end

end
