IDSIA / crema

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

New Factor hierarchy #74

Closed cbonesana closed 3 years ago

cbonesana commented 3 years ago

This PR aims to rewrite and fix the whole class hierarchy used for the Factors.

The class structure in version up to 0.1.7 contains one fundamental flaw: the operations are not implemented in a seamless way across all factors. We have multiple factors that implements the same methods but from different interfaces. In Java this translates to the impossibility to use the same algorithm but with similar factors. The new hierarchy aims to fix this issue.

Another big change is that now all factors are Interface. Algorithms works with interfaces and not with the implementation. This allows us to have multiple implementations (i.e. BayesianDefaultFactor and BayesianLogFactor) for the same factor type (i.e. BayesianFactor). All implementations respond to the correct behavior and allows more flexibility for further implementation. As an example, we can now easily have BayesianSparseFactor (where the data storage is a sparse-matrix) and BayesianFunctionFactor(where there is no data and the probabilities are returned by a given function.). More work on this direction soon.

Finally, all factors are now immutable. No more setData() on a factor after its instantiation. To allow more flexibility in the creation of the factors, several Factory utility classes has been added. These classes works like a "StringBuilder" for the new factors.

Summing up the major changes are the following: