-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cpt.java
50 lines (40 loc) · 1.04 KB
/
Cpt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Arrays;
import java.util.HashMap;
import java.util.Vector;
/**
* this class represents Conditional Probability Tables
* name contains all nodes presents
* cpt contains HashMap: Key=vector of values for nodes in name, Value=probability
* @author igork
*
*/
public class Cpt {
Vector<String> name;
HashMap<Vector<String>, Float> cpt;
public Cpt(Vector<String> n) {
cpt = new HashMap<Vector<String>, Float>();
name = (Vector<String>) n.clone();
}
public void addCPT(Vector<String> keys, float prob) {
cpt.put(keys, prob);
}
public Cpt clone() {
Cpt cloneCpt = new Cpt((Vector<String>) name.clone());
for(Vector<String> c : cpt.keySet()) {
cloneCpt.addCPT((Vector<String>) c.clone(), cpt.get(c));
}
return cloneCpt;
}
public HashMap<Vector<String>, Float> getCpt(){
return cpt;
}
public Vector<String> getName() {
return name;
}
public int cptSize() {
return cpt.size();
}
public String toString() {
return name + "\n" +cpt.toString();
}
}