| 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 |
package dr.inference.model; |
| 27 |
|
| 28 |
import dr.inference.parallel.MPIServices; |
| 29 |
import dr.xml.Reportable; |
| 30 |
import org.w3c.dom.Document; |
| 31 |
import org.w3c.dom.Element; |
| 32 |
|
| 33 |
import java.util.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public interface Parameter extends Statistic, Variable<Double> { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
double getParameterValue(int dim); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
double[] getParameterValues(); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
void setParameterValue(int dim, double value); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
void setParameterValueQuietly(int dim, double value); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
void setParameterValueNotifyChangedAll(int dim, double value); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
String getParameterName(); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
void addParameterListener(VariableListener listener); |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
void removeParameterListener(VariableListener listener); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
void storeParameterValues(); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
void restoreParameterValues(); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
void acceptParameterValues(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
void adoptParameterValues(Parameter source); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
boolean isWithinBounds(); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
void setDimension(int dim); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
void addBounds(Bounds<Double> bounds); |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
Bounds<Double> getBounds(); |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
void addDimension(int index, double value); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
double removeDimension(int index); |
| 161 |
|
| 162 |
void fireParameterChangedEvent(); |
| 163 |
|
| 164 |
void fireParameterChangedEvent(int index, Parameter.ChangeType type); |
| 165 |
|
| 166 |
boolean isUsed(); |
| 167 |
|
| 168 |
Set<Parameter> FULL_PARAMETER_SET = new LinkedHashSet<Parameter>(); |
| 169 |
Set<Parameter> CONNECTED_PARAMETER_SET = new LinkedHashSet<Parameter>(); |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
abstract class Abstract extends Statistic.Abstract implements Parameter, Reportable { |
| 175 |
|
| 176 |
protected Abstract() { |
| 177 |
FULL_PARAMETER_SET.add(this); |
| 178 |
} |
| 179 |
|
| 180 |
protected Abstract(final String name) { |
| 181 |
super(name); |
| 182 |
FULL_PARAMETER_SET.add(this); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
void sendState(int toRank) { |
| 191 |
double[] value = getParameterValues(); |
| 192 |
MPIServices.sendDoubleArray(value, toRank); |
| 193 |
} |
| 194 |
|
| 195 |
void receiveState(int fromRank) { |
| 196 |
final int length = getDimension(); |
| 197 |
double[] values = MPIServices.receiveDoubleArray(fromRank, length); |
| 198 |
for (int i = 0; i < length; i++) |
| 199 |
setParameterValueQuietly(i, values[i]); |
| 200 |
this.fireParameterChangedEvent(); |
| 201 |
} |
| 202 |
|
| 203 |
public int getDimension() { |
| 204 |
return 1; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public void fireParameterChangedEvent() { |
| 211 |
fireParameterChangedEvent(-1, Parameter.ChangeType.VALUE_CHANGED); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public void fireParameterChangedEvent(int index, Parameter.ChangeType type) { |
| 221 |
if (listeners != null) { |
| 222 |
for (VariableListener listener : listeners) { |
| 223 |
listener.variableChangedEvent(this, index, type); |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
public final void addParameterListener(VariableListener listener) { |
| 229 |
if (listeners == null) { |
| 230 |
listeners = new ArrayList<VariableListener>(); |
| 231 |
} |
| 232 |
listeners.add(listener); |
| 233 |
} |
| 234 |
|
| 235 |
public final void removeParameterListener(VariableListener listener) { |
| 236 |
if (listeners != null) { |
| 237 |
listeners.remove(listener); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
public final String getStatisticName() { |
| 242 |
return getParameterName(); |
| 243 |
} |
| 244 |
|
| 245 |
public final double getStatisticValue(int dim) { |
| 246 |
return getParameterValue(dim); |
| 247 |
} |
| 248 |
|
| 249 |
@Override |
| 250 |
public String getDimensionName(int dim) { |
| 251 |
if (dimensionNames == null) { |
| 252 |
return super.getDimensionName(dim); |
| 253 |
} |
| 254 |
return dimensionNames[dim]; |
| 255 |
} |
| 256 |
|
| 257 |
public final void setDimensionNames(String[] names) { |
| 258 |
if (names != null && names.length != getDimension()) { |
| 259 |
throw new IllegalArgumentException("Length of dimension name array doesn't match the number of dimensions"); |
| 260 |
} |
| 261 |
dimensionNames = names; |
| 262 |
} |
| 263 |
|
| 264 |
public void setDimension(int dim) { |
| 265 |
throw new UnsupportedOperationException(); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
public double[] getParameterValues() { |
| 274 |
|
| 275 |
double[] copyOfValues = new double[getDimension()]; |
| 276 |
for (int i = 0; i < copyOfValues.length; i++) { |
| 277 |
copyOfValues[i] = getParameterValue(i); |
| 278 |
} |
| 279 |
return copyOfValues; |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
public final void storeParameterValues() { |
| 284 |
if (isValid) { |
| 285 |
storeValues(); |
| 286 |
|
| 287 |
isValid = false; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
public final void restoreParameterValues() { |
| 292 |
if (!isValid) { |
| 293 |
restoreValues(); |
| 294 |
|
| 295 |
isValid = true; |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
public final void acceptParameterValues() { |
| 300 |
if (!isValid) { |
| 301 |
acceptValues(); |
| 302 |
|
| 303 |
isValid = true; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
public final void adoptParameterValues(Parameter source) { |
| 308 |
|
| 309 |
adoptValues(source); |
| 310 |
|
| 311 |
isValid = true; |
| 312 |
} |
| 313 |
|
| 314 |
public boolean isWithinBounds() { |
| 315 |
Bounds<Double> bounds = getBounds(); |
| 316 |
for (int i = 0; i < getDimension(); i++) { |
| 317 |
final double value = getParameterValue(i); |
| 318 |
if (value < bounds.getLowerLimit(i) || value > bounds.getUpperLimit(i)) { |
| 319 |
return false; |
| 320 |
} |
| 321 |
} |
| 322 |
return true; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
public final String getVariableName() { |
| 333 |
return getParameterName(); |
| 334 |
} |
| 335 |
|
| 336 |
public final Double getValue(int index) { |
| 337 |
return getParameterValue(index); |
| 338 |
} |
| 339 |
|
| 340 |
public final void setValue(int index, Double value) { |
| 341 |
setParameterValue(index, value); |
| 342 |
} |
| 343 |
|
| 344 |
public Double[] getValues() { |
| 345 |
Double[] copyOfValues = new Double[getDimension()]; |
| 346 |
for (int i = 0; i < getDimension(); i++) { |
| 347 |
copyOfValues[i] = getValue(i); |
| 348 |
} |
| 349 |
return copyOfValues; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
public int getSize() { |
| 356 |
return getDimension(); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public final void addVariableListener(VariableListener listener) { |
| 365 |
addParameterListener(listener); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
public final void removeVariableListener(VariableListener listener) { |
| 374 |
removeParameterListener(listener); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public void storeVariableValues() { |
| 381 |
storeParameterValues(); |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
public void restoreVariableValues() { |
| 388 |
restoreParameterValues(); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
public void acceptVariableValues() { |
| 395 |
acceptParameterValues(); |
| 396 |
} |
| 397 |
|
| 398 |
public boolean isUsed() { |
| 399 |
return listeners != null && listeners.size() > 0; |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
protected abstract void storeValues(); |
| 405 |
|
| 406 |
protected abstract void restoreValues(); |
| 407 |
|
| 408 |
protected abstract void acceptValues(); |
| 409 |
|
| 410 |
protected abstract void adoptValues(Parameter source); |
| 411 |
|
| 412 |
public String toString() { |
| 413 |
StringBuilder buffer = new StringBuilder(String.valueOf(getParameterValue(0))); |
| 414 |
Bounds bounds = null; |
| 415 |
try { |
| 416 |
bounds = getBounds(); |
| 417 |
} catch (NullPointerException e) { |
| 418 |
|
| 419 |
} |
| 420 |
final String id = getId(); |
| 421 |
if (id != null) buffer.append(", ").append(id); |
| 422 |
if (bounds != null) { |
| 423 |
buffer.append("=[").append(String.valueOf(bounds.getLowerLimit(0))); |
| 424 |
buffer.append(", ").append(String.valueOf(bounds.getUpperLimit(0))).append("]"); |
| 425 |
} |
| 426 |
|
| 427 |
for (int i = 1; i < getDimension(); i++) { |
| 428 |
buffer.append(", ").append(String.valueOf(getParameterValue(i))); |
| 429 |
if (bounds != null) { |
| 430 |
buffer.append("[").append(String.valueOf(bounds.getLowerLimit(i))); |
| 431 |
buffer.append(", ").append(String.valueOf(bounds.getUpperLimit(i))).append("]"); |
| 432 |
} |
| 433 |
} |
| 434 |
return buffer.toString(); |
| 435 |
} |
| 436 |
|
| 437 |
public String getReport() { |
| 438 |
StringBuilder sb = new StringBuilder(); |
| 439 |
Bounds bounds = null; |
| 440 |
try { |
| 441 |
bounds = getBounds(); |
| 442 |
} catch (NullPointerException e) { |
| 443 |
|
| 444 |
} |
| 445 |
|
| 446 |
for (int i = 0; i < getDimension(); ++i) { |
| 447 |
if (getDimensionName(i) != null) { |
| 448 |
sb.append(getDimensionName(i)).append("="); |
| 449 |
} |
| 450 |
sb.append(String.valueOf(getParameterValue(i))); |
| 451 |
|
| 452 |
if (bounds != null) { |
| 453 |
sb.append("["); |
| 454 |
try { |
| 455 |
sb.append(String.valueOf(bounds.getLowerLimit(i))); |
| 456 |
sb.append(", ").append(String.valueOf(bounds.getUpperLimit(i))); |
| 457 |
} catch (NullPointerException npe) { |
| 458 |
sb.append("no bounds"); |
| 459 |
} |
| 460 |
sb.append("]"); |
| 461 |
} |
| 462 |
|
| 463 |
if (i < getDimension() - 1) { |
| 464 |
sb.append(", "); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
return sb.toString(); |
| 469 |
} |
| 470 |
|
| 471 |
public Element createElement(Document document) { |
| 472 |
throw new IllegalArgumentException(); |
| 473 |
} |
| 474 |
|
| 475 |
private boolean isValid = true; |
| 476 |
|
| 477 |
private ArrayList<VariableListener> listeners; |
| 478 |
|
| 479 |
private String[] dimensionNames = null; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
class Default extends Abstract { |
| 487 |
|
| 488 |
public Default(String id, int dimension) { |
| 489 |
this(dimension); |
| 490 |
setId(id); |
| 491 |
} |
| 492 |
|
| 493 |
public Default(String id) { |
| 494 |
this(1); |
| 495 |
setId(id); |
| 496 |
} |
| 497 |
|
| 498 |
public Default(int dimension) { |
| 499 |
this(dimension, 1.0); |
| 500 |
} |
| 501 |
|
| 502 |
public Default(String id, double initialValue) { |
| 503 |
this(initialValue); |
| 504 |
setId(id); |
| 505 |
} |
| 506 |
|
| 507 |
public Default(double initialValue) { |
| 508 |
values = new double[1]; |
| 509 |
values[0] = initialValue; |
| 510 |
this.bounds = null; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public Default(String id, double initialValue, double lower, double upper) { |
| 520 |
this(initialValue); |
| 521 |
setId(id); |
| 522 |
addBounds(new DefaultBounds(upper, lower, 1)); |
| 523 |
} |
| 524 |
|
| 525 |
public Default(int dimension, double initialValue) { |
| 526 |
values = new double[dimension]; |
| 527 |
for (int i = 0; i < dimension; i++) { |
| 528 |
values[i] = initialValue; |
| 529 |
} |
| 530 |
this.bounds = null; |
| 531 |
} |
| 532 |
|
| 533 |
public Default(String id, double[] values) { |
| 534 |
this(values); |
| 535 |
setId(id); |
| 536 |
} |
| 537 |
|
| 538 |
public Default(double[] values) { |
| 539 |
this.values = new double[values.length]; |
| 540 |
System.arraycopy(values, 0, this.values, 0, values.length); |
| 541 |
} |
| 542 |
|
| 543 |
public Default(String id, int dimension, double initialValue) { |
| 544 |
this(dimension, initialValue); |
| 545 |
setId(id); |
| 546 |
} |
| 547 |
|
| 548 |
public void addBounds(Bounds<Double> boundary) { |
| 549 |
if (bounds == null) { |
| 550 |
bounds = boundary; |
| 551 |
} else { |
| 552 |
if (!(bounds instanceof IntersectionBounds)) { |
| 553 |
IntersectionBounds newBounds = new IntersectionBounds(getDimension()); |
| 554 |
newBounds.addBounds(bounds); |
| 555 |
bounds = newBounds; |
| 556 |
} |
| 557 |
|
| 558 |
((IntersectionBounds) bounds).addBounds(boundary); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
public final int getDimension() { |
| 570 |
return values.length; |
| 571 |
} |
| 572 |
|
| 573 |
public final int getSize() { |
| 574 |
return getDimension(); |
| 575 |
} |
| 576 |
|
| 577 |
public final double getParameterValue(int i) { |
| 578 |
return values[i]; |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
public final double[] getParameterValues() { |
| 587 |
|
| 588 |
double[] copyOfValues = new double[values.length]; |
| 589 |
System.arraycopy(values, 0, copyOfValues, 0, copyOfValues.length); |
| 590 |
return copyOfValues; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
public final double[] inspectParameterValues() { |
| 599 |
return values; |
| 600 |
} |
| 601 |
|
| 602 |
public Bounds<Double> getBounds() { |
| 603 |
if (bounds == null) { |
| 604 |
throw new NullPointerException(getParameterName() + " parameter: Bounds not set"); |
| 605 |
} |
| 606 |
return bounds; |
| 607 |
} |
| 608 |
|
| 609 |
public String getParameterName() { |
| 610 |
return getId(); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
public void setDimension(int dim) { |
| 622 |
final int oldDim = getDimension(); |
| 623 |
if (oldDim == dim) { |
| 624 |
return; |
| 625 |
} |
| 626 |
|
| 627 |
assert storedValues == null : |
| 628 |
"Can't change dimension after store has been called! storedValues=" + |
| 629 |
Arrays.toString(storedValues) + " bounds=" + bounds; |
| 630 |
|
| 631 |
|
| 632 |
double[] newValues = new double[dim]; |
| 633 |
|
| 634 |
System.arraycopy(values, 0, newValues, 0, Math.min(oldDim, dim)); |
| 635 |
|
| 636 |
for (int i = oldDim; i < dim; i++) { |
| 637 |
newValues[i] = values[0]; |
| 638 |
} |
| 639 |
values = newValues; |
| 640 |
|
| 641 |
if (bounds != null) { |
| 642 |
|
| 643 |
for (int k = 1; k < oldDim; ++k) { |
| 644 |
assert ((double) bounds.getLowerLimit(k) == bounds.getLowerLimit(0)) && |
| 645 |
((double) bounds.getUpperLimit(k) == bounds.getUpperLimit(0)) : |
| 646 |
"Can't change dimension when bounds are not all equal"; |
| 647 |
} |
| 648 |
final double low = bounds.getLowerLimit(0); |
| 649 |
final double high = bounds.getUpperLimit(0); |
| 650 |
bounds = null; |
| 651 |
addBounds(low, high); |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
public void addDimension(int index, double value) { |
| 661 |
assert bounds == null; |
| 662 |
|
| 663 |
final int n = values.length; |
| 664 |
double[] newValues = new double[n + 1]; |
| 665 |
System.arraycopy(values, 0, newValues, 0, index); |
| 666 |
newValues[index] = value; |
| 667 |
System.arraycopy(values, index, newValues, index + 1, n - index); |
| 668 |
values = newValues; |
| 669 |
fireParameterChangedEvent(index, Parameter.ChangeType.ADDED); |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
public double removeDimension(int index) { |
| 679 |
assert bounds == null; |
| 680 |
|
| 681 |
final int n = values.length; |
| 682 |
final double value = values[index]; |
| 683 |
|
| 684 |
final double[] newValues = new double[n - 1]; |
| 685 |
System.arraycopy(values, 0, newValues, 0, index); |
| 686 |
System.arraycopy(values, index, newValues, index - 1, n - index); |
| 687 |
values = newValues; |
| 688 |
fireParameterChangedEvent(index, Parameter.ChangeType.REMOVED); |
| 689 |
return value; |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
public void setParameterValue(int i, double val) { |
| 694 |
values[i] = val; |
| 695 |
fireParameterChangedEvent(i, Parameter.ChangeType.VALUE_CHANGED); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
public void setParameterValueQuietly(int dim, double value) { |
| 705 |
values[dim] = value; |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
public void setParameterValueNotifyChangedAll(int i, double val) { |
| 716 |
values[i] = val; |
| 717 |
fireParameterChangedEvent(-1, Parameter.ChangeType.ALL_VALUES_CHANGED); |
| 718 |
} |
| 719 |
|
| 720 |
protected final void storeValues() { |
| 721 |
|
| 722 |
|
| 723 |
if (storedValues == null || storedValues.length != values.length) { |
| 724 |
storedValues = new double[values.length]; |
| 725 |
} |
| 726 |
System.arraycopy(values, 0, storedValues, 0, storedValues.length); |
| 727 |
} |
| 728 |
|
| 729 |
protected final void restoreValues() { |
| 730 |
|
| 731 |
|
| 732 |
double[] temp = storedValues; |
| 733 |
storedValues = values; |
| 734 |
values = temp; |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
protected final void acceptValues() { |
| 745 |
} |
| 746 |
|
| 747 |
protected final void adoptValues(Parameter source) { |
| 748 |
|
| 749 |
|
| 750 |
if (getDimension() != source.getDimension()) { |
| 751 |
throw new RuntimeException("The two parameters don't have the same number of dimensions"); |
| 752 |
} |
| 753 |
|
| 754 |
for (int i = 0, n = getDimension(); i < n; i++) { |
| 755 |
values[i] = source.getParameterValue(i); |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
private double[] values; |
| 760 |
|
| 761 |
private double[] storedValues; |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
private Bounds<Double> bounds = null; |
| 766 |
|
| 767 |
public void addBounds(double lower, double upper) { |
| 768 |
addBounds(new DefaultBounds(upper, lower, getDimension())); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
class DefaultBounds implements Bounds<Double> { |
| 773 |
|
| 774 |
public DefaultBounds(double upper, double lower, int dimension) { |
| 775 |
|
| 776 |
this.uppers = new double[dimension]; |
| 777 |
this.lowers = new double[dimension]; |
| 778 |
for (int i = 0; i < dimension; i++) { |
| 779 |
uppers[i] = upper; |
| 780 |
lowers[i] = lower; |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
public DefaultBounds(double[] uppers, double[] lowers) { |
| 799 |
|
| 800 |
if (uppers.length != lowers.length) { |
| 801 |
throw new IllegalArgumentException("upper and lower limits must be defined on the same number of dimensions."); |
| 802 |
} |
| 803 |
this.uppers = uppers; |
| 804 |
this.lowers = lowers; |
| 805 |
} |
| 806 |
|
| 807 |
public Double getUpperLimit(int i) { |
| 808 |
return uppers[i]; |
| 809 |
} |
| 810 |
|
| 811 |
public Double getLowerLimit(int i) { |
| 812 |
return lowers[i]; |
| 813 |
} |
| 814 |
|
| 815 |
public int getBoundsDimension() { |
| 816 |
return uppers.length; |
| 817 |
} |
| 818 |
|
| 819 |
public boolean isConstant() { |
| 820 |
return true; |
| 821 |
} |
| 822 |
|
| 823 |
private final double[] uppers, lowers; |
| 824 |
} |
| 825 |
|
| 826 |
} |