-
Notifications
You must be signed in to change notification settings - Fork 9
Variables refactor #136
Variables refactor #136
Conversation
@StannisZhou I have pushed a first sketch for this PR. Let's discuss it next week Here are some observation:
(Personal note: we cannot use a set to represent the variables in the graph as we will get Here are some questions / follow-up we should discuss:
|
Codecov Report
@@ Coverage Diff @@
## master #136 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 967 916 -51
=========================================
- Hits 967 916 -51
Continue to review full report at Codecov.
|
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.
Left some comments, but looks pretty good on a high level.
One major thing (something I didn't realize before) is that it looks like with the refactors we no longer need to implement the current add_factor
/add_factor_by_type
/add_factor_group
. Instead, we can instantiate those outside the factor graph and have a generic add_factor
that takes as input the constructed factors/factor groups directly. This is the benefit of using a more intuitive way to represent variables (instead of relying on names like before which requires access to a variable_group object that's only available in a factor graph).
Thanks for your detailed review @StannisZhou! |
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.
Made another round of comments. Major issues are:
- We should consider alternative ways for implementing variable group hashes. And checking for duplicate variables is probably not necessary if we implement our hash right.
- Hash for
VariableDict
seems wrong - Remove
name
for factors/factor groups, and unifyadd_factor
/add_factor_group
- Properly implement flatten/unflatten for variable number of states in
NDVariableArray
(quite straightforward)
@StannisZhou the PR is ready to be reviewed! Here is an approximate timing comparisons from before / after on two examples RBM after:
RBM before:
PMP after:
PMP before:
|
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.
Partial review. Will finish the rest tomorrow...
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.
More comments
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.
LGTM. Thanks for patiently addressing all the comments!
We update the way of representing variables. In particular:
Variables
andCompositeVariableGroup
classes. A variable is now represented by a tuple(variable hash, variable num_states)
In particular, a FactorGraph can then directly be instantiated as
fg = graph.FactorGraph(variables=[hidden_variables, visible_variables])
Similarly, Factors are defined by directly passing the variables involved, as
[hidden_variables[ii], visible_variables[jj]]
NDVariableArray
so that the user can access variables by relying on the use of numpy arrays. We also optimize some follow-up computations.