marleneberke / ORB_project3

0 stars 1 forks source link

Error with splice, only when using HMC #7

Open marleneberke opened 5 years ago

marleneberke commented 5 years ago

ERROR: LoadError: MethodError: no method matching splice!(::Array{String,1}, ::ReverseDiff.TrackedReal{Int64,Int64,Nothing}) Closest candidates are: splice!(::Array{T,1} where T, ::Integer) at array.jl:1311 splice!(::Array{T,1} where T, ::Integer, ::Any) at array.jl:1311 splice!(::Array{T,1} where T, ::UnitRange{#s75} where #s75<:Integer) at array.jl:1358 ... Stacktrace: [1] ##sample_wo_repl#570(::Gen.GFBackpropTraceState, ::Array{String,1}, ::Int64) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:54 [2] exec at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/dynamic.jl:39 [inlined] [3] choice_gradients(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::AllSelection, ::Nothing) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:376 [4] special_reverse_exec!(::ReverseDiff.SpecialInstruction{Gen.BackpropTraceRecord,Tuple{Array{String,1},Int64},Array{String,1},Nothing}) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:346 [5] reverse_exec!(::ReverseDiff.SpecialInstruction{Gen.BackpropTraceRecord,Tuple{Array{String,1},Int64},Array{String,1},Nothing}) at /Users/marleneberke/.julia/packages/ReverseDiff/qmgw8/src/tape.jl:93 [6] reverse_pass!(::Array{ReverseDiff.AbstractInstruction,1}) at /Users/marleneberke/.julia/packages/ReverseDiff/qmgw8/src/tape.jl:87 [7] reverse_pass! at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/backprop.jl:12 [inlined] [8] choice_gradients(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection, ::Nothing) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:396 [9] #hmc#167(::Float64, ::Int64, ::Float64, ::typeof(hmc), ::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/inference/hmc.jl:36 [10] hmc(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/inference/hmc.jl:24 [11] block_resimulation_update(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:265 [12] block_resimulation_inference(::Tuple{Array{String,1},Int64}, ::DynamicChoiceMap) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:282 [13] top-level scope at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:290 [14] include at ./boot.jl:328 [inlined] [15] include_relative(::Module, ::String) at ./loading.jl:1094 [16] include(::Module, ::String) at ./Base.jl:31 [17] include(::String) at ./client.jl:431

in expression starting at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:289

marleneberke commented 5 years ago

updating since inference.jl has been updated

include("inference.jl") current state is ["bicycle"] ERROR: LoadError: MethodError: no method matching splice!(::Array{String,1}, ::ReverseDiff.TrackedReal{Int64,Int64,Nothing}) Closest candidates are: splice!(::Array{T,1} where T, ::Integer) at array.jl:1311 splice!(::Array{T,1} where T, ::Integer, ::Any) at array.jl:1311 splice!(::Array{T,1} where T, ::UnitRange{#s75} where #s75<:Integer) at array.jl:1358 ... Stacktrace: [1] ##sample_wo_repl#373(::Gen.GFBackpropTraceState, ::Array{String,1}, ::Int64) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:58 [2] exec at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/dynamic.jl:39 [inlined] [3] choice_gradients(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::AllSelection, ::Nothing) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:376 [4] special_reverse_exec!(::ReverseDiff.SpecialInstruction{Gen.BackpropTraceRecord,Tuple{Array{String,1},ReverseDiff.TrackedReal{Int64,Int64,Nothing}},Array{String,1},Nothing}) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:346 [5] reverse_exec!(::ReverseDiff.SpecialInstruction{Gen.BackpropTraceRecord,Tuple{Array{String,1},ReverseDiff.TrackedReal{Int64,Int64,Nothing}},Array{String,1},Nothing}) at /Users/marleneberke/.julia/packages/ReverseDiff/qmgw8/src/tape.jl:93 [6] reverse_pass!(::Array{ReverseDiff.AbstractInstruction,1}) at /Users/marleneberke/.julia/packages/ReverseDiff/qmgw8/src/tape.jl:87 [7] reverse_pass! at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/backprop.jl:12 [inlined] [8] choice_gradients(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection, ::Nothing) at /Users/marleneberke/.julia/packages/Gen/eQpFO/src/dynamic/backprop.jl:396 [9] #hmc2#10(::Int64, ::Float64, ::typeof(hmc2), ::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:117 [10] (::getfield(Main, Symbol("#kw##hmc2")))(::NamedTuple{(:L, :eps),Tuple{Int64,Float64}}, ::typeof(hmc2), ::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::DynamicSelection) at ./none:0 [11] block_resimulation_update(::Gen.DynamicDSLTrace{DynamicDSLFunction{Any}}, ::String) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:389 [12] every_step(::Array{String,1}, ::Int64, ::DynamicChoiceMap) at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:431 [13] top-level scope at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:438 [14] include at ./boot.jl:328 [inlined] [15] include_relative(::Module, ::String) at ./loading.jl:1094 [16] include(::Module, ::String) at ./Base.jl:31 [17] include(::String) at ./client.jl:431

in expression starting at /Users/marleneberke/Documents/03_Yale/Projects/001_Mask_RCNN/ORB_project3/inference.jl:438

belledon commented 5 years ago

@mdb293

I'm not entirely sure whats going on here but I think the culprit is the type of

Take a close look at the error:

ERROR: LoadError: MethodError: no method matching splice!(::Array{String,1}, ::ReverseDiff.TrackedReal{Int64,Int64,Nothing})
Closest candidates are:
splice!(::Array{T,1} where T, ::Integer) at array.jl:1311
splice!(::Array{T,1} where T, ::Integer, ::Any) at array.jl:1311
splice!(::Array{T,1} where T, ::UnitRange{#s75} where #s75<:Integer) at array.jl:1358

It is saying that splice! is not defined for an array of time String but only for integers. Perhaps you should encode your strings to indexes in your GM.

After taking a look at : https://github.com/mdb293/ORB_project3/blob/fdffd6e60c7d6f0d5ff4a440952b3a5fb3012d21/inference.jl#L43-L70

It seems that you might be passing the wrong array to sample_wo_repl. Since gen doesnt handle function type signatures atm, I would create a helper function that is deterministic that merely checks your types.. something along the lines of .


# This just checks types and returns
function _sample_wo_repl(A::Vector{Integer}, n::Int)
    (A, n)
end

@gen function sample_wo_repl(A,n)
       A,n = _sample_wo_repl(A,n)

    sample = Array{String}(undef,n)
    for i in 1:n
        #println("i is ", i)

        idx = @trace(Gen.uniform_discrete(1, length(A_mutable)), (:idx, i))
        #print("idx is ", idx)
        sample[i] = splice!(A_mutable, idx)
        #sample[i] = A_mutable[idx]
        #deleteat!(A_mutable, idx)
        #println("A_mutable is ", A_mutable)
    end
    #trying to reset A
    #A = copy(A_immutable)
    #want to rearrange so that the order of items in the sample matches the order of items that we're sampling from
    sampleIdx = names_to_IDs(sample, A_immutable)
    sorted = sort(sampleIdx)
    ordered_sample = A_immutable[sorted]
    return ordered_sample
end
marleneberke commented 4 years ago

I think the problem is the type of idx. When running metropolis_hastings, idx passes the type check and is an int. When running hm, it's of type ::ReverseDiff.TrackedReal{Int64,Int64,Nothing}