1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.experiment.results;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import java.util.Set;
26
27 import p3j.pppm.IProjectionModel;
28 import p3j.pppm.ProjectionModel;
29 import p3j.pppm.parameters.ParameterAssignment;
30 import p3j.pppm.parameters.ParameterInstance;
31 import p3j.pppm.sets.SetType;
32
33
34
35
36
37
38
39
40 public class ResultsOfTrial implements Serializable {
41
42
43 private static final long serialVersionUID = 2484910276641194217L;
44
45
46 private int id = -1;
47
48
49 private ProjectionModel projection;
50
51
52
53
54
55 private Map<ParameterInstance, ParameterAssignment> assignment = new HashMap<ParameterInstance, ParameterAssignment>();
56
57
58
59
60
61 private List<BasicResults> nativeResults;
62
63
64 private List<BasicResults> immigrantResults = new ArrayList<BasicResults>();
65
66
67 private List<BasicResults> emigrantResults = new ArrayList<BasicResults>();
68
69
70 private double assignmentProbability;
71
72
73
74
75
76
77
78 private double setCombinationProbability;
79
80
81
82
83 public ResultsOfTrial() {
84 }
85
86
87
88
89
90
91
92
93
94 public ResultsOfTrial(IProjectionModel projectionModel,
95 ExecutionSummary execSummary) {
96 nativeResults = new ArrayList<BasicResults>();
97 nativeResults.add(execSummary.getNativeResults());
98 projection = (ProjectionModel) projectionModel;
99 assignment.putAll(execSummary.getParamAssignments());
100 immigrantResults.addAll(execSummary.getImmigrantResults());
101 emigrantResults.addAll(execSummary.getEmigrantResults());
102 calculateAssignmentProbability();
103 }
104
105
106
107
108 private void calculateAssignmentProbability() {
109
110 double setCombProb = 1.0;
111 double assignmentCombProb = 1.0;
112
113 Set<Integer> checkedSetTypeIDs = new HashSet<Integer>();
114 for (Entry<ParameterInstance, ParameterAssignment> entry : assignment
115 .entrySet()) {
116
117 ParameterInstance paramInstance = entry.getKey();
118 ParameterAssignment paramAssignment = entry.getValue();
119 assignmentCombProb *= paramAssignment.getProbability();
120
121 SetType currentSetType = projection.getInstanceSetTypes().get(
122 paramInstance);
123 if (!checkedSetTypeIDs.contains(currentSetType.getID())) {
124 setCombProb *= getSetProbability(paramInstance, paramAssignment,
125 currentSetType);
126 checkedSetTypeIDs.add(currentSetType.getID());
127 }
128 }
129
130 setCombinationProbability = setCombProb;
131 assignmentProbability = setCombProb * assignmentCombProb;
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145 private double getSetProbability(ParameterInstance paramInstance,
146 ParameterAssignment paramAssignment, SetType currentSetType) {
147 List<p3j.pppm.sets.Set> currentSets = currentSetType.getSets();
148 for (p3j.pppm.sets.Set currentSet : currentSets) {
149 for (ParameterAssignment currentAssignment : currentSet
150 .getParameterAssignments(paramInstance).getAssignments()) {
151 if (currentAssignment.getID() == paramAssignment.getID()) {
152 return currentSet.getProbability();
153 }
154 }
155 }
156 return -1.0;
157 }
158
159 public int getID() {
160 return id;
161 }
162
163 public void setID(int id) {
164 this.id = id;
165 }
166
167 public ProjectionModel getProjection() {
168 return projection;
169 }
170
171 public void setProjection(ProjectionModel projection) {
172 this.projection = projection;
173 }
174
175 public Map<ParameterInstance, ParameterAssignment> getAssignment() {
176 return assignment;
177 }
178
179 public void setAssignment(
180 Map<ParameterInstance, ParameterAssignment> assignment) {
181 this.assignment = assignment;
182 }
183
184 public List<BasicResults> getNativeResults() {
185 return nativeResults;
186 }
187
188
189
190
191
192
193
194 public BasicResults getNativesResults() {
195 if (nativeResults.size() != 1) {
196 throw new IllegalStateException(
197 "Number of native results does not match!");
198 }
199 return nativeResults.get(0);
200 }
201
202 public void setNativeResults(List<BasicResults> nativeResults) {
203 this.nativeResults = nativeResults;
204 }
205
206 public double getAssignmentProbability() {
207 return assignmentProbability;
208 }
209
210 public void setAssignmentProbability(double assignmentProbability) {
211 this.assignmentProbability = assignmentProbability;
212 }
213
214 public List<BasicResults> getImmigrantResults() {
215 return immigrantResults;
216 }
217
218 public void setImmigrantResults(List<BasicResults> immigrantResults) {
219 this.immigrantResults = immigrantResults;
220 }
221
222 public List<BasicResults> getEmigrantResults() {
223 return emigrantResults;
224 }
225
226 public void setEmigrantResults(List<BasicResults> emigrantResults) {
227 this.emigrantResults = emigrantResults;
228 }
229
230 public double getSetCombinationProbability() {
231 return setCombinationProbability;
232 }
233
234 public void setSetCombinationProbability(double setCombinationProbability) {
235 this.setCombinationProbability = setCombinationProbability;
236 }
237 }