Coder Social home page Coder Social logo

Comments (4)

cscherrer avatar cscherrer commented on June 9, 2024 1

Here's a MWE, removed from Soss:

julia> using Soss, MeasureTheory, GeneralizedGenerated

julia> g = GG.mk_function(:(x -> Normal(x,1)))
function = (x;) -> begin
    begin
        (GeneralizedGenerated).Normal(x, 1)
    end
end

julia> For(g, 3)
ERROR: MethodError: no method matching productmeasure(::ggfunc-function, ::UnitRange{Int64})
Closest candidates are:
  productmeasure(::Any, ::Any, ::Any) at /home/chad/git/MeasureBase/src/combinators/smart-constructors.jl:69
  productmeasure(::Kernel, ::Any) at /home/chad/git/MeasureBase/src/combinators/smart-constructors.jl:75
  productmeasure(::Returns, ::Any, ::Any) at /home/chad/git/MeasureBase/src/combinators/smart-constructors.jl:82
  ...
Stacktrace:
 [1] For(f::ggfunc-function, n::Int64)
   @ MeasureBase ~/git/MeasureBase/src/combinators/for.jl:82
 [2] top-level scope
   @ REPL[53]:1

mk_function calls GeneralizedGenerated.closure_conv, which produces

julia> typeof(g)
ggfunc-function

julia> typeof(g) |> supertype
Any

So the issue is that MeasureBase.productMeasure doesn't have a generic method, but wants a <:Function, and a ggfun-function doesn't meet this criteria.

The simplest fix for this is to add a method

productmeasure(f, pars) = productmeasure(f, identity, pars)

For example, this works:

julia> MeasureBase.productmeasure(f, pars) = MeasureBase.productmeasure(f, identity, pars)

julia> m = @model begin 
           x ~ For(3) do j Normal(j,1) end
       end;

julia> rand(m())
(x = [1.9296440232404293, 3.1574221730525336, 4.1352330633979255],)

But it turns out this just kicks the can down the road:

julia> logpdf(m(), rand(m()))
ERROR: MethodError: no method matching basekernel(::ggfunc-function)
Closest candidates are:
  basekernel(::Kernel) at /home/chad/git/MeasureBase/src/kernel.jl:73
  basekernel(::Returns) at /home/chad/git/MeasureBase/src/kernel.jl:74
  basekernel(::Function) at /home/chad/git/MeasureBase/src/kernel.jl:71

To be continued...

from soss.jl.

Tuebel avatar Tuebel commented on June 9, 2024 1

Thanks for the quick fix!

from soss.jl.

cscherrer avatar cscherrer commented on June 9, 2024

Thanks for letting me know about this! This is a high priority to fix, obviously. I think (hope?) it should be a quick fix, then we should add tests to be sure to catch this going forward. I'll spend some time on it today.

from soss.jl.

cscherrer avatar cscherrer commented on June 9, 2024

Hi @Tuebel , thanks again for this issue. There's a new release with tests that include

    @testset "https://github.com/cscherrer/Soss.jl/issues/305" begin
        m = @model begin 
            x ~ For(3) do j Normal=j) end
        end;
        
        @test logpdf(m(), rand(m())) isa Float64
    end

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.