-
Notifications
You must be signed in to change notification settings - Fork 11
Implement of
#331
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
base: sunxd/v0.10
Are you sure you want to change the base?
Implement of
#331
Conversation
JuliaBUGS.jl documentation for PR #331 is available at: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a quick look and left a few minor comments.
DESIGN_of_proposal.md
Outdated
```julia | ||
# Tuple syntax | ||
@model function demo( | ||
(x::of(Array, 8), y::of(Array, of(Real), 4, 3), w::of(Real, lower, upper)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue with such tuple syntax is variables x
, y
, etc won't be available in the function body since Julia sees the first argument (x, y, ...)
as a single argument by default. We can override this behaviour, but that might surprise users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
JuliaFormatter
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 130 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 137 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 141 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 148 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 158 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 167 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Lines 169 to 176 in 9b57a62
spec3 = of(( | |
a = of(Real), | |
b = of(( | |
x = of(Array, 2), | |
y = of(Real, 0, nothing) | |
)) | |
)) | |
val3 = (a = 1.0, b = (x = [2.0, 3.0], y = 4.0)) |
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 185 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Lines 187 to 188 in 9b57a62
spec = of((a = of(Array, 2), b = of(Real))) | |
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 191 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 194 in 9b57a62
[JuliaFormatter] reported by reviewdog 🐶
JuliaBUGS.jl/test/test_of_type.jl
Line 200 in 9b57a62
end |
@yebai I just pushed some local changes. Can you give it another quick read? https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/of_design_doc.md ('unflatten' doesn't quite work yet, but the idea should be there.) |
A few comments:
# always do
@model function school_model((; mu0, beta, tau2, sigma2, school_effects)::SchoolParams, data)
end
# instead of
@model function school_model(params::SchoolParams, data)
(; mu0, beta, tau2, sigma2, school_effects) = params
end The motivation is that we want to enforce that all LHS of tilde has to be a variable from the destructured first argument of models (e.g.
Tp = of((;n=of(Constant), m=of(Constant), x=of(Array,n,m)))
zero(Tp, n=4, m=3)
rand(Tp, n=4, m=3)
Tp(n=4, m=3) # equivalent to `zero(Tp, n=4, m=3)`
|
there are some issues
|
@yebai comments at #331 (comment) are addressed. couple of deviations:
The updated design doc is at https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/of_design_doc.md and code is at https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/src/of_type.jl. The source code required no dependencies, all the example code in the design doc should run, except for the model macro (I haven't made substantial updates to JuliaBUGS.@model |
You can handle variable bounds using
This could be a good motivation for the Also, I don't think we need |
#324 (comment) is mostly implemented. Updated design doc https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/of_design_doc.md. The part left over is support of expressions in array size. I.e., currently Tparams = @of(
b=of(Int),
θ=of(Array, b, 1),
y=of(Real)
) is fine, but Tparams = @of(
b=of(Int),
θ=of(Array, b+1, 1),
y=of(Real)
) is not. Two things to consider further:
julia> A{:(x+1)}
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Expr
Stacktrace:
[1] top-level scope
@ REPL[2]:1
julia> A{:x}
A{:x} there are probably ways to circumvent this, but not trivial.
|
Good work @sunxd3 -- I left a few more comments above. We are getting there.
For now, let's only support |
design at the moment: https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/of_design_doc.md ![]() use of expressions is also supported (an example is added at https://github.com/TuringLang/JuliaBUGS.jl/blob/sunxd/of/of_design_doc.md#bayesian-nonparametric-clustering-model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work -- I added a few final comments on constructor syntax, mainly for consistency.
of_design_doc.md
Outdated
|
||
rand(ConcreteExpanded) | ||
# Generate random instance | ||
rand(ExpandedMatrixType; n=10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rand(ExpandedMatrixType; n=10) | |
rand(of(ExpandedMatrixType; n=10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunxd3 For clarity, let's make sure to remove these methods
zero(ExpandedMatrixType; n=10)
rand(ExpandedMatrixType; n=10)
flat = flatten(MatrixType, instance; rows=3, cols=4)
unflatten(MatrixType, flat; rows=3, cols=4)
in favour of
zero(of(ExpandedMatrixType; n=10))
rand(of(ExpandedMatrixType; n=10))
flat = flatten(of(MatrixType; rows=3, cols=4), instance)
unflatten(of(MatrixType; rows=3, cols=4), flat)
for the principle that there should be only one way of doing things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done now
the design doc is updated |
Excellent -- we now have a complete |
address #324