-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
105 lines (83 loc) · 2.6 KB
/
Variable.java
File metadata and controls
105 lines (83 loc) · 2.6 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
public class Variable {
private String name;
private final List<String> outcomes;
private List<Double> probabilities;
private final List<String> parents;
private final List<String> children;
private boolean isEvi=false;
private int color; //0=white(unvisited) , 1=black(visited from child), 2=gray(visited from parent)
private Map<Map<String, String>, Double> CPTtable;
public Variable() {
this.outcomes = new ArrayList<>();
this.probabilities = new ArrayList<>();
this.parents = new ArrayList<>();
this.children = new ArrayList<>();
this.CPTtable = new HashMap<>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEvi() {
return isEvi;
}
public void setEvi(boolean evi) {
isEvi = evi;
}
public List<String> getOutcomes() {
return outcomes;
}
public void addOutcome(String outcome) {
outcomes.add(outcome);
}
public List<Double> getPro() {
return probabilities;
}
public void setPro(List<Double> definitions) {
this.probabilities = definitions;
}
public void setCPT(String name, Network network) {
this.CPTtable = network.getCPT_tables().get(name);
}
public List<String> getParents() {
return parents;
}
public void addParent(String givenVar) {
parents.add(givenVar);
}
public List<String> getChildren() {
return children;
}
public void addChild(String child) {
children.add(child);
}
public int getColor() {
return color;
}
public void setColor(int color) {
this.color = color;
}
public boolean isAncestorOf(Variable var,Network network){
if (var.getParents().contains(this.name)) {
return true;
}
for (String parentName : var.getParents()) {
Variable parent = network.getVariable(parentName);
if (parent != null && this.isAncestorOf(parent,network)) {
return true;
}
}
return false;
}
@Override
public String toString() {
return "{name='" + name + "', outcomes=" + outcomes+ ", cpt=" + CPTtable +"}";
// ", parents=" + parents + ", children=" + children+ ", color="+color+ ", evi?:" +isEvi+"}";
}
}