Summary:
Modify code to test whether variables are marginalizable without throwing an exception if they are not.
Then use that to go over entire graph finding marginalizable variables and marginalizing each of them in sequence.
Checking whether a variable is marginalizable is somewhat complex because we need to determine the set of deterministic nodes directly affected by it. Because this involves computing the entire support, we now cache that. We therefore also add a mechanism to cache this and to invalidate this cache whenever appropriate.
Summary: Modify code to test whether variables are marginalizable without throwing an exception if they are not. Then use that to go over entire graph finding marginalizable variables and marginalizing each of them in sequence. Checking whether a variable is marginalizable is somewhat complex because we need to determine the set of deterministic nodes directly affected by it. Because this involves computing the entire support, we now cache that. We therefore also add a mechanism to cache this and to invalidate this cache whenever appropriate.
Reviewed By: gafter
Differential Revision: D40872470