1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.pppm.parameters;
17
18 import james.core.serialization.SerialisationUtils;
19
20 import java.io.IOException;
21 import java.io.Serializable;
22
23 import p3j.misc.Misc;
24 import p3j.misc.math.Matrix;
25 import p3j.misc.math.Matrix2D;
26 import p3j.pppm.IStochasticOccurrence;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class ParameterAssignment implements Serializable, IStochasticOccurrence {
47
48
49 private static final long serialVersionUID = 5672796759108189718L;
50
51
52 private int id;
53
54
55 private ParameterInstance paramInstance;
56
57
58 private Matrix matrix;
59
60
61 private String name = "";
62
63
64 private String description = "";
65
66
67 private double probability;
68
69
70
71
72
73
74 private double deviation;
75
76
77
78
79
80
81
82 public ParameterAssignment(ParameterInstance instance) {
83 paramInstance = instance;
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public ParameterAssignment(ParameterInstance instance, String assignName,
103 String desc, double prob, double dev, Matrix val) {
104 paramInstance = instance;
105 name = assignName;
106 description = desc;
107 probability = prob;
108 deviation = dev;
109 matrix = val;
110 }
111
112 public ParameterAssignment() {
113 }
114
115
116
117
118
119
120
121 public ParameterAssignment(String matrixString, ParameterInstance instance,
122 String assignName, String desc, double prob, double dev)
123 throws ClassNotFoundException, IOException {
124 this(instance, assignName, desc, prob, dev, (Matrix) SerialisationUtils
125 .deserializeFromB64String(matrixString));
126 }
127
128
129
130
131
132
133
134
135
136 public void setMatrixBinary(String matrixString)
137 throws ClassNotFoundException, IOException {
138 matrix = (Matrix) SerialisationUtils.deserializeFromB64String(matrixString);
139 }
140
141
142
143
144
145
146
147 public String getMatrixBinary() throws IOException {
148 return SerialisationUtils.serializeToB64String(matrix);
149 }
150
151
152
153
154
155
156
157 public ParameterAssignment getCopy() {
158
159 ParameterAssignment returnAssignment = new ParameterAssignment(
160 getParamInstance());
161 returnAssignment.description = description;
162 returnAssignment.name = name;
163 returnAssignment.probability = probability;
164 returnAssignment.matrix = matrix.copy();
165
166 return returnAssignment;
167 }
168
169 @Override
170 public String toString() {
171 return getName() + " (" + Misc.round(getProbability(), 2) + ")";
172 }
173
174
175
176 @Override
177 public double getProbability() {
178 return probability;
179 }
180
181 @Override
182 public void setProbability(double probability) {
183 this.probability = probability;
184 }
185
186 public String getDescription() {
187 return description;
188 }
189
190 public void setDescription(String description) {
191 this.description = description;
192 }
193
194 public String getName() {
195 return name;
196 }
197
198 public void setName(String name) {
199 this.name = name;
200 }
201
202 public Matrix getMatrix() {
203 return matrix;
204 }
205
206 public void setMatrix(Matrix matrix) {
207 this.matrix = matrix;
208 }
209
210
211
212
213
214
215
216 public void setMatrixValue(Matrix2D matrix2D) {
217
218
219 if (matrix2D.rows() == 0 && matrix2D.columns() == 0) {
220 return;
221 }
222
223 if (matrix == null) {
224 matrix = new Matrix(matrix2D);
225 } else {
226 matrix.setValue(matrix2D);
227 }
228 }
229
230
231
232
233
234
235 public Matrix2D getMatrixValue() {
236 return matrix.getValue();
237 }
238
239 public ParameterInstance getParamInstance() {
240 return paramInstance;
241 }
242
243 public void setParamInstance(ParameterInstance paramInstance) {
244 this.paramInstance = paramInstance;
245 }
246
247 public int getID() {
248 return id;
249 }
250
251 public void setID(int uniqueID) {
252 id = uniqueID;
253 }
254
255 public Double getDeviation() {
256 return deviation;
257 }
258
259
260
261
262
263
264
265
266
267
268 public void setDeviation(Double newDeviation) {
269 if (newDeviation == null || newDeviation < 0) {
270 this.deviation = 0;
271 } else {
272 this.deviation = newDeviation;
273 }
274 }
275
276 }