@@ -9,41 +9,49 @@ learning and inference algorithms for credal models.
9
9
10
10
An example of exact inference in a credal network is given below.
11
11
12
- ```
12
+ ``` java
13
+ import ch.idsia.crema.factor.credal.vertex.VertexFactor ;
14
+ import ch.idsia.crema.inference.ve.CredalVariableElimination ;
15
+ import ch.idsia.crema.model.ObservationBuilder ;
16
+ import ch.idsia.crema.model.Strides ;
17
+ import ch.idsia.crema.model.graphical.SparseModel ;
13
18
14
- double p = 0.2;
15
- double eps = 0.0001;
19
+ public class Starting {
20
+ public static void main (String [] args ) {
21
+ double p = 0.2 ;
22
+ double eps = 0.0001 ;
16
23
17
- /* CN defined with vertex Factor */
24
+ /* CN defined with vertex Factor */
18
25
19
- // Define the model (with vertex factors)
20
- SparseModel model = new SparseModel();
21
- int u = model.addVariable(3);
22
- int x = model.addVariable(2);
23
- model.addParent(x,u );
26
+ // Define the model (with vertex factors)
27
+ SparseModel model = new SparseModel ();
28
+ int A = model. addVariable(3 );
29
+ int B = model. addVariable(2 );
30
+ model. addParent(B , A );
24
31
25
- // Define a credal set of the partent node
26
- VertexFactor fu = new VertexFactor(model.getDomain(u ), Strides.empty());
27
- fu.addVertex(new double[]{0., 1-p, p});
28
- fu.addVertex(new double[]{1-p, 0., p});
29
- model.setFactor(u ,fu);
32
+ // Define a credal set of the partent node
33
+ VertexFactor fu = new VertexFactor (model. getDomain(A ), Strides . empty());
34
+ fu. addVertex(new double []{0. , 1 - p, p});
35
+ fu. addVertex(new double []{1 - p, 0. , p});
36
+ model. setFactor(A ,fu);
30
37
31
38
32
- System.out.println(p+" "+(1-p));
39
+ // Define the credal set of the child
40
+ VertexFactor fx = new VertexFactor (model. getDomain(B ), model. getDomain(A ));
33
41
34
- // Define the credal set of the child
35
- VertexFactor fx = new VertexFactor(model.getDomain(x), model.getDomain(u));
42
+ fx. addVertex(new double []{1. , 0. ,}, 0 );
43
+ fx. addVertex(new double []{1. , 0. ,}, 1 );
44
+ fx. addVertex(new double []{0. , 1. ,}, 2 );
36
45
37
- fx.addVertex(new double[]{1., 0.,}, 0);
38
- fx.addVertex(new double[]{1., 0.,}, 1);
39
- fx.addVertex(new double[]{0., 1.,}, 2);
46
+ model. setFactor(B ,fx);
40
47
41
- model.setFactor(x,fx);
48
+ // Run exact inference
49
+ CredalVariableElimination inf = new CredalVariableElimination (model);
50
+ inf. query(A , ObservationBuilder . observe(B ,0 ));
51
+
52
+ }
53
+ }
42
54
43
- // Run exact inference inference
44
- VariableElimination ve = new FactorVariableElimination(model.getVariables());
45
- ve.setFactors(model.getFactors());
46
- System.out.println(ve.run(x));
47
55
48
56
49
57
```
@@ -52,7 +60,7 @@ System.out.println(ve.run(x));
52
60
53
61
Add the following code in the pom.xml of your project:
54
62
55
- ```
63
+ ``` xml
56
64
<repositories >
57
65
<repository >
58
66
<id >cremaRepo</id >
@@ -64,7 +72,7 @@ Add the following code in the pom.xml of your project:
64
72
<dependency >
65
73
<groupId >ch.idsia</groupId >
66
74
<artifactId >crema</artifactId >
67
- <version>0.1.3 </version>
75
+ <version >0.1.4 </version >
68
76
<scope >compile</scope >
69
77
</dependency >
70
78
</dependencies >
0 commit comments