april-tools / cirkit

a python framework to build, learn and reason about probabilistic circuits and tensor networks
https://cirkit-docs.readthedocs.io/en/latest/
GNU General Public License v3.0
71 stars 1 forks source link

Materialize marginalized circuits #94

Closed loreloc closed 1 year ago

loreloc commented 1 year ago

Add the following methods to the PC class.

Materialize marginalized circuits to compute the partition function and any marginal probability.

arranger1044 commented 1 year ago

for the partition func, let's try to materialize it as a circuit

loreloc commented 1 year ago

I was thinking having something like this:

arranger1044 commented 1 year ago

We need to distinguish two cases for marginalization, and hence for MarginalizedInputLayers.

First, we want to create a new circuit marginalizing out a fixed set of vars. This is essentially implementing marginalization as an operation in the atlas. For it, it is fine to create a fresh new computational graph (layer).

However, if we want to allow for marginalizing many different (not known a priori) sets of variables (which is the use case of the current marginalization routines), having a different input layer per var set can be wasteful. Instead, we need to use sets of masks. The difference with the current implementation shall be that i) masks should not be stored as state properties of the layer and ii) we shall allow for batched computations. I.e., having a batch of input examples, each one with its possibly different mask of variables to marginalize.