Git Product home page Git Product logo

credici's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

vishalbelsare

credici's Issues

Extend unit tests

Create or complete the unit tests for the following classes or functionalities:

SCM

  • Non quasi / non
  • Endog exo links
  • getEmpiricalMap
  • getExogenousTreewidth
  • C-components

EquationBuilder
CausalVE
CredalCausalApproxLP
CredalCausalVE
ExactCredalBuilder
EMCredalBuilder
Utilities

Intervened endogenous variables are considered as exogenous

        StructuralCausalModel causalModel = Party.buildModel();
        SparseModel vcredal = causalModel.toVCredal(causalModel.getEmpiricalProbs());
        int[] U = CausalInfo.of((SparseModel) vcredal.counterfactual_do(1,0)).getExogenousVars();
        System.out.println(Arrays.toString(U)); // [1, 4, 5, 6, 7] while should be [4, 5, 6, 7]

SCMs builders

Define API for building SCM:

Option 1: SEs + empirical model
Option 2: SEs + empirical DAG + List of factors

Causal queries with approxLP using crema 0.2.x

Extract empirical factors from Bayesian network

When building a credal network from a causal model, empirical distributions can be obtained
from a Bayesian network (instead of being provided in a list). This network can have any topology, but
it should be defined over the set of endogenous variables.


        // Causal DAG
        SparseDirectedAcyclicGraph causalDAG = new SparseDirectedAcyclicGraph();
        IntStream.range(0,4).forEach(x -> causalDAG.addVariable(x));

        causalDAG.addLink(0,1);
        causalDAG.addLink(0,2);
        causalDAG.addLink(1,3);
        causalDAG.addLink(2,3);
        
        // Empirical Bayesian Network
        BayesianNetwork bnet = (BayesianNetwork) IO.read("./models/party-empirical-rev.uai") ;


        // Build causal model (with unobserved U)
        StructuralCausalModel causalModel = CausalBuilder.of(causalDAG, 2).build();

        int[] x = causalModel.getEndogenousVars();

        SparseModel hcredal = CredalBuilder.of(causalModel)
                                .setEmpirical(bnet)
                                .setToHalfSpace()
                                .build();
        

builders for deterministic factors

Create clases with static methods for simplifying the creation factors with some specific initialisations:

deterministicBayesian()
deterministicVertex()
deterministicHalfSapace()

Wrong SE in twin graph

When building the twin graph with the party example, the SE of node 10 is wrong. This could
be due to a bug with the rename or with the sort function.


    BayesianNetwork bnet = (BayesianNetwork) IO.read(prj_folder+"models/party-empirical.uai");

    // Build the causal model
    StructuralCausalModel causalModel = CausalBuilder.of(bnet).build();

    // Get the endogenous variables
    int[] x = causalModel.getEndogenousVars();

    // Convert the causal models into credal networks
    SparseModel vcredal = causalModel.toVCredal(bnet.getFactors());
    SparseModel hcredal = causalModel.toHCredal(bnet.getFactors());


    /////// Causal query P(X3 | do(X2 = 1))

    //Exact inference
    CredalCausalVE infExact = new CredalCausalVE(vcredal);

    /////// Counterfactual query P(X3' | do(X2 = 1), X2=0)

    //Exact inference

     SparseModel infModel = (SparseModel) infExact.counterfactualQuery()
             .setTarget(x[3])
             .setIntervention(x[1],1)
             .setEvidence(x[1], 0)
             .getInferenceModel();

     vcredal.getFactor(2)
     infModel.getFactor(10)

    /*

    // correct:
    K(vars[10]|[0, 0]) [1.0, 0.0]
    K(vars[10]|[0, 1]) [1.0, 0.0]
    K(vars[10]|[0, 2]) [0.0, 1.0]
    K(vars[10]|[0, 3]) [0.0, 1.0]
    K(vars[10]|[1, 0]) [1.0, 0.0]
    K(vars[10]|[1, 1]) [0.0, 1.0]
    K(vars[10]|[1, 2]) [1.0, 0.0]
    K(vars[10]|[1, 3]) [0.0, 1.0]

    // wrong
    K(vars[10]|[0, 0]) [1.0, 0.0]
    K(vars[10]|[1, 0]) [0.0, 1.0]
    K(vars[10]|[2, 0]) [1.0, 0.0]
    K(vars[10]|[3, 0]) [1.0, 0.0]
    K(vars[10]|[0, 1]) [1.0, 0.0]
    K(vars[10]|[1, 1]) [0.0, 1.0]
    K(vars[10]|[2, 1]) [0.0, 1.0]
    K(vars[10]|[3, 1]) [0.0, 1.0]

     */

no feasible solution in EquationLessFromFile example

Error when running approxLP:

Exception in thread "main" org.apache.commons.math3.optim.linear.NoFeasibleSolutionException: no feasible solution
	at org.apache.commons.math3.optim.linear.SimplexSolver.solvePhase1(SimplexSolver.java:355)
	at org.apache.commons.math3.optim.linear.SimplexSolver.doOptimize(SimplexSolver.java:380)
	at org.apache.commons.math3.optim.linear.SimplexSolver.doOptimize(SimplexSolver.java:65)
	at org.apache.commons.math3.optim.BaseOptimizer.optimize(BaseOptimizer.java:153)
	at org.apache.commons.math3.optim.BaseMultivariateOptimizer.optimize(BaseMultivariateOptimizer.java:65)
	at org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer.optimize(MultivariateOptimizer.java:63)
	at org.apache.commons.math3.optim.linear.LinearOptimizer.optimize(LinearOptimizer.java:94)
	at org.apache.commons.math3.optim.linear.SimplexSolver.optimize(SimplexSolver.java:154)
	at ch.idsia.crema.solver.commons.Simplex.solve(Simplex.java:55)
	at ch.idsia.crema.factor.convert.SeparateLinearToRandomBayesian.apply(SeparateLinearToRandomBayesian.java:63)
	at ch.idsia.crema.inference.approxlp.Neighbourhood.random(Neighbourhood.java:63)
	at ch.idsia.crema.inference.approxlp.Neighbourhood.random(Neighbourhood.java:47)
	at ch.idsia.crema.inference.approxlp.Inference.runSearcher(Inference.java:84)
	at ch.idsia.crema.inference.approxlp.Inference.query(Inference.java:57)
	at ch.idsia.crema.inference.approxlp.Inference.query(Inference.java:18)
	at ch.idsia.credici.inference.CredalCausalAproxLP.query(CredalCausalAproxLP.java:85)
	at ch.idsia.credici.inference.CredalCausalAproxLP.query(CredalCausalAproxLP.java:18)
	at ch.idsia.credici.inference.CausalInference.doQuery(CausalInference.java:36)
	at EquationlessFromFile.main(EquationlessFromFile.java:31)

error when running vertex VE:

Exception in thread "main" org.apache.commons.math3.optim.linear.NoFeasibleSolutionException: no feasible solution
	at ch.idsia.credici.model.CredalBuilder.build(CredalBuilder.java:120)
	at ch.idsia.credici.model.StructuralCausalModel.toVCredal(StructuralCausalModel.java:635)
	at ch.idsia.credici.inference.CredalCausalVE.<init>(CredalCausalVE.java:37)
	at EquationlessFromFile.main(EquationlessFromFile.java:30)

This could be due to a bad order of the variables from which coefficients/values are obtained

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.