idsia / credici Goto Github PK
View Code? Open in Web Editor NEWCredici: Credal Inference for Causal Inference
Home Page: https://credici.readthedocs.io/
License: GNU Lesser General Public License v3.0
Credici: Credal Inference for Causal Inference
Home Page: https://credici.readthedocs.io/
License: GNU Lesser General Public License v3.0
For example, in the party example with X4.
Create or complete the unit tests for the following classes or functionalities:
SCM
EquationBuilder
CausalVE
CredalCausalApproxLP
CredalCausalVE
ExactCredalBuilder
EMCredalBuilder
Utilities
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]
While developing #24, create a RandomUtilities class with an identical behaviour to the random generators in crema <0.2
Method to check if a SCM is markovian, quasi-markovian...
This feature have been removed because of counterfactual queries
Define API for building SCM:
Option 1: SEs + empirical model
Option 2: SEs + empirical DAG + List of factors
In branch dev-crema020-iss24
approxLP is not working for calculating causal queries due to an unfeasible exception. This is based on crema 0.2.2. Check the following examples where it fails.
https://github.com/IDSIA/credici/blob/dev-crema020-iss24/examples/not_working/Queries.java
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();
Create clases with static methods for simplifying the creation factors with some specific initialisations:
deterministicBayesian()
deterministicVertex()
deterministicHalfSapace()
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]
*/
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
branch 'dev-crema020-iss24'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.