Code Monkey home page Code Monkey logo

Comments (3)

cscherrer avatar cscherrer commented on June 2, 2024

Hi @AxLamelas , thanks for letting me know about this. I'm checking into it now

from soss.jl.

cscherrer avatar cscherrer commented on June 2, 2024

The logdensity_def problem is easily addressed by adding a primitive for that. I'm still seeing an issue after doing that. This problem can be reduced to

using Soss

mc_init = @model begin
	x ~ Normal(0.0, 1.0)
	return (x=x,)
end

mc_step = @model s begin
	x ~ Normal(s.x + 0.1, 0.2)
	return (x = x,)
end

d = Chain(mc_init()) do s mc_step(s=s) end
x = Iterators.take(rand(d), 10) |> collect
logdensity_def(d,x)

This gives the result

ERROR: MethodError: First argument to `convert` must be a Type, got (x = Float64,)
Stacktrace:
 [1] macro expansion
   @ ~/git/Soss.jl/src/primitives/logdensity.jl:92 [inlined]
 [2] _logdensity_def(M::Type{Soss.GeneralizedGenerated.NGG.TypeLevel{Module, "Buf{17}()"}}, _m::Model{NamedTuple{(:p, :s)}, Soss.GeneralizedGenerated.NGG.TypeLevel{Expr, "Buf{23}()"}, Soss.GeneralizedGenerated.NGG.TypeLevel{Module, "Buf{17}()"}}, _args::NamedTuple{(:s, :p), Tuple{NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(:Δμ, ), Tuple{Float64, Float64}}}}, _data::NamedTuple{(), Tuple{}}, _pars::NamedTuple{(:x,), Tuple{Float64}})
   @ Soss ~/git/Soss.jl/src/primitives/logdensity.jl:92
 [3] logdensity_def(c::Soss.ConditionalModel{NamedTuple{(:p, :s)}, Soss.GeneralizedGenerated.NGG.TypeLevel{Expr, "Buf{23}()"}, Soss.GeneralizedGenerated.NGG.TypeLevel{Module, "Buf{17}()"}, NamedTuple{(:s, :p), Tuple{NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(:Δμ, ), Tuple{Float64, Float64}}}}, NamedTuple{(), Tuple{}}}, x::NamedTuple{(:x,), Tuple{Float64}})
   @ Soss ~/git/Soss.jl/src/primitives/logdensity.jl:51
 [4] logdensity_def(mc::Chain{var"#19#20", Soss.ConditionalModel{NamedTuple{()}, Soss.GeneralizedGenerated.NGG.TypeLevel{Expr, "Buf{23}()"}, Soss.GeneralizedGenerated.NGG.TypeLevel{Module, "Buf{17}()"}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}}}, x::Vector{Any})
   @ MeasureTheory ~/.julia/packages/MeasureTheory/MeOXc/src/combinators/chain.jl:28
 [5] top-level scope
   @ REPL[89]:1

from soss.jl.

cscherrer avatar cscherrer commented on June 2, 2024

I had hoped this would just be a matter of adding a logdensity_def method. After adding this in #350, I still get the above error,

ERROR: MethodError: First argument to `convert` must be a Type, got (x = Float64,)

We can also look at the simpler example:

julia> mc_step = @model x begin
               y ~ Normal(x + 0.1, 0.2)
               return y
       end;

julia> d = Chain(Normal()) do s mc_step(s) end;

julia> x = Iterators.take(rand(d), 10) |> collect;

julia> logdensity_def(d,x)
ERROR: MethodError: no method matching keys(::Type{Float64})
Closest candidates are:
  keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at ~/.julia/packages/Tables/PxO1m/src/Tables.jl:184
  keys(::Missings.EachReplaceMissing) at ~/.julia/packages/Missings/r1STI/src/Missings.jl:94
  keys(::DataStructures.Trie) at ~/.julia/packages/DataStructures/59MD0/src/trie.jl:82
  ...
Stacktrace:
 [1] loadvals(argstype::Type, datatype::Type, parstype::Type)
   @ Soss ~/git/Soss.jl/src/core/utils.jl:217
 [2] #s112#76
   @ ~/git/Soss.jl/src/primitives/logdensity.jl:92 [inlined]
 [3] var"#s112#76"(::Any, M::Any, _m::Any, _args::Any, _data::Any, _pars::Any)
   @ Soss ./none:0
 [4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
   @ Core ./boot.jl:582
 [5] logdensity_def(c::Soss.ConditionalModel{NamedTuple{(:x,)}, Soss.GeneralizedGenerated.NGG.TypeLevel{Expr, "Buf{23}()"}, Soss.GeneralizedGenerated.NGG.TypeLevel{Module, "Buf{17}()"}, NamedTuple{(:x,), Tuple{Float64}}, NamedTuple{(), Tuple{}}}, x::Float64)
   @ Soss ~/git/Soss.jl/src/primitives/logdensity.jl:50
 [6] logdensity_def(mc::Chain{var"#11#12", Normal{(), Tuple{}}}, x::Vector{Any})
   @ MeasureTheory ~/.julia/packages/MeasureTheory/Mrznp/src/combinators/chain.jl:28
 [7] top-level scope
   @ REPL[24]:1

So it looks like there's a place where types are mistakenly being treated as values. That kind of problem usually means it's a metaprogramming issue, maybe a generated function. But then it's also strange that other tests pass, included those for nested models. So it might have to do with the implementation of Chain, or possible its interaction with the generated functions.

The errors I'm getting are kind of tricky to debug. I think a next step might be for me to implement this example in Tilde and see if I hit the same issue.

from soss.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.