IDSIA / crema

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

Wrong data length after filtering a SeparateHalfspaceFactor #99

Closed rcabanasdepaz closed 3 years ago

rcabanasdepaz commented 3 years ago

After using filter operation with a conditioning variable over a SeparateHalfspaceFactor, the resulting data object in the factor has a wrong length: positions non consistent with the filter are simply set with an empty list, instead of being removed.

Consider the following code:


    int x = 0, y=1, z=2;

    // P(x|y,z)
    SeparateHalfspaceFactorFactory ff = SeparateHalfspaceFactorFactory
            .factory().domain(Strides.as(x,2), Strides.as(y,2,z,2));

    ff.constraint(new double[]{1,0}, Relationship.EQ, 1.0, 0);
    ff.constraint(new double[]{0,1}, Relationship.EQ, 0.0, 0);

    ff.constraint(new double[]{1,0}, Relationship.EQ, 0.2, 1);
    ff.constraint(new double[]{0,1}, Relationship.EQ, 0.8, 1);

    ff.constraint(new double[]{1,0}, Relationship.EQ, 0.9, 2);
    ff.constraint(new double[]{0,1}, Relationship.EQ, 0.1, 2);

    ff.constraint(new double[]{1,0}, Relationship.EQ, 0.5, 3);
    ff.constraint(new double[]{0,1}, Relationship.EQ, 0.5, 3);

    SeparateHalfspaceFactor f = ff.get();

    TIntObjectMap data = f.getData();
    for(int i=0; i<data.size(); i++)
        System.out.println(i+": "+data.get(i));

    System.out.println("");

    data = f.filter(y,0).getData();
    for(int i=0; i<data.size(); i++)
        System.out.println(i+": "+data.get(i));

    /* Output:

    0: [org.apache.commons.math3.optim.linear.LinearConstraint@de6ed1f6, org.apache.commons.math3.optim.linear.LinearConstraint@607ed1f6]
    1: [org.apache.commons.math3.optim.linear.LinearConstraint@47ced1f5, org.apache.commons.math3.optim.linear.LinearConstraint@c60ed1f5]
    2: [org.apache.commons.math3.optim.linear.LinearConstraint@12bed1f7, org.apache.commons.math3.optim.linear.LinearConstraint@c65ed1f5]
    3: [org.apache.commons.math3.optim.linear.LinearConstraint@de7ed1f6, org.apache.commons.math3.optim.linear.LinearConstraint@5f9ed1f6]

    0: [org.apache.commons.math3.optim.linear.LinearConstraint@de6ed1f6, org.apache.commons.math3.optim.linear.LinearConstraint@607ed1f6]
    1: []
    2: [org.apache.commons.math3.optim.linear.LinearConstraint@12bed1f7, org.apache.commons.math3.optim.linear.LinearConstraint@c65ed1f5]
    3: []

     */

whereas the output for the filtered factor should be

    0: [org.apache.commons.math3.optim.linear.LinearConstraint@de6ed1f6, org.apache.commons.math3.optim.linear.LinearConstraint@607ed1f6]
    1: [org.apache.commons.math3.optim.linear.LinearConstraint@12bed1f7, org.apache.commons.math3.optim.linear.LinearConstraint@c65ed1f5]