-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactor graph and model part of the code #80
Conversation
@yebai apologize for another PR with multiple changes, I hope it's not too confusing. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #80 +/- ##
==========================================
+ Coverage 69.20% 74.49% +5.28%
==========================================
Files 17 19 +2
Lines 1640 1635 -5
==========================================
+ Hits 1135 1218 +83
+ Misses 505 417 -88
☔ View full report in Codecov by Sentry. |
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.
This is a very big PR; I reviewed half of it. I'll try to complete it tomorrow.
@@ -1,6 +1,6 @@ | |||
name = "JuliaBUGS" | |||
uuid = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf" | |||
version = "0.1.0" | |||
version = "0.1.1" |
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.
version = "0.1.1" | |
version = "0.2" |
@@ -197,7 +201,7 @@ n_samples, n_adapts = 2000, 1000 | |||
|
|||
D = LogDensityProblems.dimension(model); initial_θ = rand(D) | |||
|
|||
samples_and_stats = AbstractMCMC.sample( | |||
@run samples_and_stats = AbstractMCMC.sample( |
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.
@run samples_and_stats = AbstractMCMC.sample( | |
samples_and_stats = AbstractMCMC.sample( |
@@ -0,0 +1,10 @@ | |||
# Evaluation of `BUGSModel` | |||
|
|||
During model evaluation, `varinfo` serves as the runtime environment, housing the current values of variables. |
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.
During model evaluation, `varinfo` serves as the runtime environment, housing the current values of variables. | |
During model evaluation, `varinfo` stores the current variables' values. |
# Evaluation of `BUGSModel` | ||
|
||
During model evaluation, `varinfo` serves as the runtime environment, housing the current values of variables. | ||
These values are always stored in their native (possibly constraint) spaces. |
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.
These values are always stored in their native (possibly constraint) spaces. | |
These variables are always stored as-is, i.e. without transformation. |
|
||
During model evaluation, `varinfo` serves as the runtime environment, housing the current values of variables. | ||
These values are always stored in their native (possibly constraint) spaces. | ||
The `varinfo` represents the state of program evaluation at different evaluation points, given a chosen order of node evaluation. |
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.
The `varinfo` represents the state of program evaluation at different evaluation points, given a chosen order of node evaluation. | |
The `varinfo` represents the state of program evaluation at different evaluation points, given a chosen ordering of node evaluations. |
@enum VariableTypes::Bool begin | ||
Logical | ||
Stochastic | ||
end | ||
|
||
@enum StochasticVariableTypes::Bool begin | ||
Observation | ||
Assumption | ||
end | ||
|
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.
Maybe merge these two types:
@enum VariableTypes Logical Observation Assumption
""" | ||
eval([m::Module, ]ni::ConcreteNodeInfo, vi) | ||
|
||
Evaluate a node under a specified module `m`. If no module is provided, the default module used is JuliaBUGS. |
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.
Evaluating nodes in JuliaBUGS
sounds terrible; why not default to Main
?
|
||
""" | ||
LogDensityContext | ||
Find the Markov blanket of `v` in `g`. `v` can be a single `VarName` or a vector of `VarName`. |
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.
Find the Markov blanket of `v` in `g`. `v` can be a single `VarName` or a vector of `VarName`. | |
Find the Markov blanket of variable(s) `v` in graph `g`. `v` can be a single `VarName` or a vector of `VarName`. |
else | ||
logp += logpdf(dist, value) | ||
end | ||
function markov_blanket(g, v::VarName) |
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.
function markov_blanket(g, v::VarName) | |
function markov_blanket(g::BUGSGraph, v::VarName) |
logp += logpdf(dist, vi[vn]) | ||
end | ||
end | ||
function markov_blanket(g, v) |
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.
function markov_blanket(g, v) | |
function markov_blanket(g::BUGSGraph,, v::Vector{VarName}) |
Thanks @yebai for the reviews, given this size of the PR and difficulty of fully reviewing, I will break it into a series of smaller PRs. |
This PR is aim to address the following points:
NodeInfo
,Model
, andContext
NodeInfo
eval
function forNodeInfo
should hide the field ofNodeInfo
, this allows storing aFunction
instead of justExpr
in theNodeInfo
by implementing aeval
function for newNodeInfo
subtypesModule
can be passed toeval
, which will allow more freedom in the evaluation, this is not yet exposedModel
get_graph
,transformation
,node_iterator
are implemented so that future model can share default implementation ofevaluate!!
Context
observe
,assume
, andlogical_evaluate
are implemented; given an order defined bynode_iterator
, one of these functions will be called on the nodesLogDensityContext
'sevaluate!!
is still implemented separately, maybe we can unify the interface further in the futureModel
, twoparam_length
s are computed, one for without transformation, the other will consider the size of the transformed distributionBijectors
), this is not essentialModel
definitions are separated into another fileVarInfo
whose values are transformedLogDensityFunction
interface at points