Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Sum operations #30

Closed
bartvanerp opened this issue Feb 27, 2023 · 1 comment
Closed

Support Sum operations #30

bartvanerp opened this issue Feb 27, 2023 · 1 comment
Assignees

Comments

@bartvanerp
Copy link
Member

Following ReactiveBayes/RxInfer.jl#60:

Currently GraphPPL.jl allows for nesting linear operations, i.e. y ~ x1 + x2 + x3 * x4 , something which in my opinion is very cool and partly solves a remark in the above issue. Next up would be to also implement the sum() operation. I think we can get away with using it as an alias depending on its inputs:

# defaults to a + b + c + d (if independent)
y ~ sum(a, b, c, d)
y ~ sum([a, b, c, d])

# defaults to dot(a_array, ones(..)) (if dependent)
y ~ sum(a_array)
y ~ sum(a_array[1], a_array[2], ...)
y ~ sum([a_array[1], a_array[2], ...])

# more complicated structures can be unrolled
y ~ sum(a_array[1], a_array[2], b) # here y ~ sum(a_array[1], a_array[2]) + b
@wouterwln
Copy link
Member

I'll mark this as closed now, for two reasons. In the following code snippet:

@model function sum_test(out, x, y)
    τ := sum([1,2,3,4])
    σ := sum(ones(4))
    out := sum(x, y)
end

τ and σ will both be variables with value 10 and 4 respectively, and for out a sum node will be created if either (or both) x or y is a random variable. This is, as far as I know, everything we can do in this regard. Your last example will sadly not work. We know that sum is a commutative operation, however we do not have this guarantee in general, therefore we will always materialize this sum node if either a_array[1], a_array_2 or b is a random variable. I don't feel like having a trait based system that labels commutative operations is in the scope of GraphPPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants