IDSIA / crema

Crema: Credal Models Algorithms
https://crema-toolbox.readthedocs.io/
GNU Lesser General Public License v3.0
10 stars 4 forks source link

Execute PR#66: New hierarchy for inference and preprocessing #66

Closed cbonesana closed 3 years ago

cbonesana commented 3 years ago

New hierarchy for Inference

There is now a unique Inference interface. This is the main interface to implement for all the inference algorithm and offers two main methods:

By default, the second method call the first with an empty TIntIntHashMap.

In the case an algorithm support the inference over multiple variables, to produce a join probability, there is the InferenceJoined interface. This interface offers the same methods but whit an array as queries.

These two classes are intended for stateless algorithm: the input model is manipulated and the inference done without keeping an internal cache of the inference used or the model used.

In case one wants this stateful behavior, there are the cascade interfaces: InferenceCascade and InferenceCascadeJoined are the same as Inference and InferenceJoined but they expect that the inference engine implement a way to keep the state of the model, so that it is possible to run multiple queries without pre-process again the model. This work is delegated to the developer.

New hierarchy for Preprocessing

Classes in the preprocess package have been refactored and a new hierarchy of interface has been added. In this ways it is much more clear for the developer to understand which method is available for each pre-processing algorithm available.

Preprocessor* interfaces are used to perform an inplace modifications to the model: they WILL change the input model the algorithm is working on. Converter* classes, instead, will generate a NEW model without change the original model (i.e. they do a copy before apply the algorithm). Finally, Transformer* interfaces are just Converter*where the types of input and output models are the same.

Currently we have three specification for these interfaces:

New Model

We have a new MixedModel: this model has the ability to mix different types of Factors and to return a Factor converted in a specific class, if possible. This model is used in particular by the BinarizeEvidenze, that will always add a new BayesianFactor node to the given model.

New test suite

We are using JUnit 5 now.

rcabanasdepaz commented 3 years ago

I have just updated the code in the examples folder for working with the new version. I have also made a tiny change at CredalApproxLP leading to a null pointer exception when running examples/PGMpaper2.java.

In general, I am ok with the changes.

cbonesana commented 3 years ago

Updated also the other code files in the examples folder and docs subfolder.

rcabanasdepaz commented 3 years ago

Examples under examples/docs are linked to the sphinx documentation by specifying the lines. If lines are added or removed, this will not be coherent with the docs. Just fixed.

cbonesana commented 3 years ago

I know and I checked that, twice. I don't know why there were missing line.