@@ -10,45 +10,49 @@ learning and inference algorithms for credal models.
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
13
import ch.idsia.crema.core.ObservationBuilder ;
16
14
import ch.idsia.crema.core.Strides ;
15
+ import ch.idsia.crema.factor.credal.vertex.separate.VertexFactor ;
16
+ import ch.idsia.crema.factor.credal.vertex.separate.VertexFactorFactory ;
17
+ import ch.idsia.crema.inference.ve.CredalVariableElimination ;
18
+ import ch.idsia.crema.model.graphical.DAGModel ;
17
19
import ch.idsia.crema.model.graphical.GraphicalModel ;
18
20
19
21
public class Starting {
20
- public static void main (String [] args ) {
21
- double p = 0.2 ;
22
- double eps = 0.0001 ;
23
-
24
- /* CN defined with vertex Factor */
25
-
26
- // Define the model (with vertex factors)
27
- GraphicalModel<VertexFactor > model = new DAGModel<> ();
28
- int A = model. addVariable(3 );
29
- int B = model. addVariable(2 );
30
-
31
- model. addParent(B ,A );
32
-
33
- // Define a credal set of the partent node
34
- VertexFactor fu = new VertexFactor (model. getDomain(A ), Strides . empty());
35
- fu. addVertex(new double []{0. , 1 - p, p});
36
- fu. addVertex(new double []{1 - p, 0. , p});
37
-
38
- model. setFactor(A ,fu);
39
-
40
- // Define the credal set of the child
41
- VertexFactor fx = new VertexFactor (model. getDomain(B ), model. getDomain(A ));
42
- fx. addVertex(new double []{1. , 0. ,}, 0 );
43
- fx. addVertex(new double []{1. , 0. ,}, 1 );
44
- fx. addVertex(new double []{0. , 1. ,}, 2 );
45
-
46
- model. setFactor(B ,fx);
47
-
48
- // Run exact inference
49
- CredalVariableElimination<VertexFactor > inf = new CredalVariableElimination<> (model);
50
- inf. query(A , ObservationBuilder . observe(B ,0 ));
51
- }
22
+ public static void main (String [] args ) {
23
+ double p = 0.2 ;
24
+ double eps = 0.0001 ;
25
+
26
+ /* CN defined with vertex Factor */
27
+
28
+ // Define the model (with vertex factors)
29
+ GraphicalModel<VertexFactor > model = new DAGModel<> ();
30
+ int A = model. addVariable(3 );
31
+ int B = model. addVariable(2 );
32
+
33
+ model. addParent(B , A );
34
+
35
+ // Define a credal set of the partent node
36
+ VertexFactor fu = VertexFactorFactory . factory(). domain(model. getDomain(A ), Strides . empty())
37
+ .addVertex(new double []{0. , 1 - p, p})
38
+ .addVertex(new double []{1 - p, 0. , p})
39
+ .get();
40
+
41
+ model. setFactor(A , fu);
42
+
43
+ // Define the credal set of the child
44
+ VertexFactor fx = VertexFactorFactory . factory(). domain(model. getDomain(B ), model. getDomain(A ))
45
+ .addVertex(new double []{1. , 0. ,}, 0 )
46
+ .addVertex(new double []{1. , 0. ,}, 1 )
47
+ .addVertex(new double []{0. , 1. ,}, 2 )
48
+ .get();
49
+
50
+ model. setFactor(B , fx);
51
+
52
+ // Run exact inference
53
+ CredalVariableElimination inf = new CredalVariableElimination ();
54
+ inf. query(model, ObservationBuilder . observe(B , 0 ), A );
55
+ }
52
56
}
53
57
```
54
58
@@ -68,7 +72,7 @@ Add the following code in the pom.xml of your project:
68
72
<dependency >
69
73
<groupId >ch.idsia</groupId >
70
74
<artifactId >crema</artifactId >
71
- <version >0.1.6 </version >
75
+ <version >0.1.7 </version >
72
76
<scope >compile</scope >
73
77
</dependency >
74
78
</dependencies >
0 commit comments