Skip to content

Create Marginal class as common return type for inference methods

Jan Pöppel requested to merge jpoeppel:marginals into master

Created by: jpoeppel

This is a work in progress. So far I've started creating fundamental tests for the different use cases that we have considered. They still need to be expanded upon with more complex marginals as well as other convenience functions. The reason I am already opening the PR is to discuss the proposed interface, which is already quite flexible, but I am not too sure about the dictionary return yet.

Currently I handle a request like m.get_probabilities({"A":["True","False"]}, returnDict=True}) for a marginal containing the binary variables A and B like so:

{"True": np.array([P(A=True, B=True), P(A=True, B=False)]), "False": np.array([P(A=False, B=True), P(A=False, B=False)])}.

A request such as: m.get_probabilities({"A":["True", "False"], "B": "False"}, returnDict=True}) [note that you do not have to insert single instantiations in lists, but can just specify them as values directly] yields:

{A: {"True": np.array([P(A=True, B=False)]), "False":np.array(P(A=False,B=False))}, B: {"False": np.array([P(A=True,B=False)])}}

since the request desires the probability for this combination. When returnDict=False this method basically behaves as Factor.get_potential with the additional convencience of not having to specify single instantiations in lists as well as allowing things like "get_probabilities("A")".

Merge request reports