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.
|
StannisZhou
left a comment
There was a problem hiding this comment.
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! |
StannisZhou
left a comment
There was a problem hiding this comment.
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
VariableDictseems wrong - Remove
namefor 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:
|
StannisZhou
left a comment
There was a problem hiding this comment.
Partial review. Will finish the rest tomorrow...
StannisZhou
left a comment
There was a problem hiding this comment.
LGTM. Thanks for patiently addressing all the comments!
We update the way of representing variables. In particular:
VariablesandCompositeVariableGroupclasses. 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]]NDVariableArrayso that the user can access variables by relying on the use of numpy arrays. We also optimize some follow-up computations.