| 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.evomodel.coalescent.operators; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood; |
| 31 |
import dr.evomodel.tree.TreeModel; |
| 32 |
import dr.evomodelxml.coalescent.operators.GaussianProcessSkytrackTreeOperatorParser; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
import dr.inference.operators.AbstractAdaptableOperator; |
| 35 |
import dr.inference.operators.AdaptationMode; |
| 36 |
import dr.inference.operators.OperatorUtils; |
| 37 |
import dr.math.MathUtils; |
| 38 |
import dr.util.ComparableDouble; |
| 39 |
import dr.util.HeapSort; |
| 40 |
import no.uib.cipr.matrix.*; |
| 41 |
|
| 42 |
|
| 43 |
import java.util.ArrayList; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public class GaussianProcessSkytrackTreeOperator extends AbstractAdaptableOperator { |
| 52 |
|
| 53 |
private TreeModel tree = null; |
| 54 |
private double scaleFactor; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
private Parameter popSizeParameter; |
| 62 |
private Parameter changePoints; |
| 63 |
|
| 64 |
private Parameter CoalCounts; |
| 65 |
private Parameter GPtype; |
| 66 |
private Parameter coalfactor; |
| 67 |
private Parameter precisionParameter; |
| 68 |
private Parameter lambdaParameter; |
| 69 |
private GaussianProcessSkytrackBlockUpdateOperator GPOperator; |
| 70 |
|
| 71 |
GaussianProcessSkytrackLikelihood gpLikelihood; |
| 72 |
|
| 73 |
private double[] zeros; |
| 74 |
|
| 75 |
public GaussianProcessSkytrackTreeOperator(TreeModel treeModel, GaussianProcessSkytrackLikelihood gpLikelihood, |
| 76 |
double weight, double scaleFactor, AdaptationMode mode) { |
| 77 |
super(mode); |
| 78 |
GPOperator=new GaussianProcessSkytrackBlockUpdateOperator(); |
| 79 |
this.tree=treeModel; |
| 80 |
this.gpLikelihood = gpLikelihood; |
| 81 |
popSizeParameter = gpLikelihood.getPopSizeParameter(); |
| 82 |
changePoints=gpLikelihood.getChangePoints(); |
| 83 |
GPtype=gpLikelihood.getGPtype(); |
| 84 |
CoalCounts=gpLikelihood.getCoalCounts(); |
| 85 |
coalfactor=gpLikelihood.getcoalfactor(); |
| 86 |
precisionParameter=gpLikelihood.getPrecisionParameter(); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
this.scaleFactor = scaleFactor; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
setWeight(weight); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
private static void collectAllTimes(Tree tree, NodeRef top, NodeRef[] excludeBelow, |
| 107 |
ArrayList<ComparableDouble> times, ArrayList<Integer> childs) { |
| 108 |
|
| 109 |
times.add(new ComparableDouble(tree.getNodeHeight(top))); |
| 110 |
childs.add(tree.getChildCount(top)); |
| 111 |
|
| 112 |
for (int i = 0; i < tree.getChildCount(top); i++) { |
| 113 |
NodeRef child = tree.getChild(top, i); |
| 114 |
if (excludeBelow == null) { |
| 115 |
collectAllTimes(tree, child, excludeBelow, times, childs); |
| 116 |
} else { |
| 117 |
|
| 118 |
boolean include = true; |
| 119 |
for (NodeRef anExcludeBelow : excludeBelow) { |
| 120 |
if (anExcludeBelow.getNumber() == child.getNumber()) { |
| 121 |
include = false; |
| 122 |
break; |
| 123 |
} |
| 124 |
} |
| 125 |
if (include) |
| 126 |
collectAllTimes(tree, child, excludeBelow, times, childs); |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
private class Trip1GP{ |
| 135 |
private double[] array1; |
| 136 |
private int[] array2; |
| 137 |
private int array3; |
| 138 |
|
| 139 |
public Trip1GP (double[] array1, int [] array2, int array3){ |
| 140 |
this.array1=array1; |
| 141 |
this.array2=array2; |
| 142 |
this.array3=array3; |
| 143 |
|
| 144 |
} |
| 145 |
public double [] getInterval() {return array1;} |
| 146 |
public int[] getLineages() {return array2;} |
| 147 |
public int getnIntervals() {return array3;} |
| 148 |
} |
| 149 |
|
| 150 |
private class TripGP{ |
| 151 |
private double[] array1; |
| 152 |
private double[] array2; |
| 153 |
private int array3; |
| 154 |
|
| 155 |
public TripGP (double[] array1, double [] array2, int array3){ |
| 156 |
this.array1=array1; |
| 157 |
this.array2=array2; |
| 158 |
this.array3=array3; |
| 159 |
|
| 160 |
} |
| 161 |
public double [] getTimes() {return array1;} |
| 162 |
public double[] getFactor() {return array2;} |
| 163 |
public int getnIntervals() {return array3;} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
public Trip1GP getTreeIntervals(Tree tree, NodeRef root, NodeRef[] exclude){ |
| 168 |
int maxIntervalCount = tree.getNodeCount(); |
| 169 |
|
| 170 |
double [] intervals = new double[maxIntervalCount]; |
| 171 |
int [] lineageCounts = new int[maxIntervalCount]; |
| 172 |
int nIntervals; |
| 173 |
|
| 174 |
double MULTIFURCATION_LIMIT = 1e-9; |
| 175 |
|
| 176 |
|
| 177 |
ArrayList<ComparableDouble> times = new ArrayList<ComparableDouble>(); |
| 178 |
ArrayList<Integer> childs = new ArrayList<Integer>(); |
| 179 |
collectAllTimes(tree, root, exclude, times, childs); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
int[] indices = new int[times.size()]; |
| 185 |
|
| 186 |
HeapSort.sort(times, indices); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
double start = times.get(indices[0]).doubleValue(); |
| 192 |
|
| 193 |
int numLines = 0; |
| 194 |
int i = 0; |
| 195 |
int intervalCount = 0; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
while (i < times.size()) { |
| 200 |
|
| 201 |
|
| 202 |
int lineagesRemoved = 0; |
| 203 |
int lineagesAdded = 0; |
| 204 |
|
| 205 |
final double finish = times.get(indices[i]).doubleValue(); |
| 206 |
|
| 207 |
double next = finish; |
| 208 |
|
| 209 |
while (Math.abs(next - finish) < MULTIFURCATION_LIMIT) { |
| 210 |
final int children = childs.get(indices[i]); |
| 211 |
|
| 212 |
if (children == 0) { |
| 213 |
|
| 214 |
lineagesAdded += 1; |
| 215 |
} else { |
| 216 |
lineagesRemoved += (children - 1); |
| 217 |
|
| 218 |
} |
| 219 |
i += 1; |
| 220 |
|
| 221 |
if (i == times.size()) break; |
| 222 |
|
| 223 |
next = times.get(indices[i]).doubleValue(); |
| 224 |
|
| 225 |
} |
| 226 |
|
| 227 |
if (lineagesAdded > 0) { |
| 228 |
|
| 229 |
|
| 230 |
if (intervalCount > 0 || ((finish - start) > MULTIFURCATION_LIMIT)) { |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
intervals[intervalCount] = finish - start; |
| 236 |
|
| 237 |
lineageCounts[intervalCount] = numLines; |
| 238 |
|
| 239 |
intervalCount += 1; |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
start = finish; |
| 244 |
|
| 245 |
} |
| 246 |
|
| 247 |
numLines += lineagesAdded; |
| 248 |
|
| 249 |
|
| 250 |
if (lineagesRemoved > 0) { |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
intervals[intervalCount] = finish - start; |
| 255 |
|
| 256 |
lineageCounts[intervalCount] = numLines; |
| 257 |
intervalCount += 1; |
| 258 |
|
| 259 |
start = finish; |
| 260 |
|
| 261 |
} |
| 262 |
|
| 263 |
numLines -= lineagesRemoved; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
nIntervals = intervalCount; |
| 268 |
return new Trip1GP(intervals,lineageCounts,nIntervals); |
| 269 |
} |
| 270 |
|
| 271 |
private double[] getoldCoalTimes(int ncoal){ |
| 272 |
|
| 273 |
double [] coaltimes= new double[ncoal]; |
| 274 |
int k=0; |
| 275 |
for (int j=0; j<changePoints.getSize();j++){ |
| 276 |
if (GPtype.getParameterValue(j)==1) { |
| 277 |
coaltimes[k]=changePoints.getParameterValue(j); |
| 278 |
|
| 279 |
k++; |
| 280 |
} |
| 281 |
|
| 282 |
} |
| 283 |
return coaltimes; |
| 284 |
} |
| 285 |
|
| 286 |
private int wherePoint(double newval,double [] intervals){ |
| 287 |
double prevle=0; |
| 288 |
double length=0; |
| 289 |
int res=0; |
| 290 |
for (int j=0;j<intervals.length;j++){ |
| 291 |
length+=intervals[j]; |
| 292 |
|
| 293 |
if (newval<length & newval>prevle){ |
| 294 |
res=j; |
| 295 |
break;} |
| 296 |
} |
| 297 |
return res; |
| 298 |
} |
| 299 |
|
| 300 |
private TripGP getNewCoalTimes(double[] intervals,int nIntervals, int[] lineageCounts){ |
| 301 |
double [] NewCoalTimes=new double[nIntervals]; |
| 302 |
double [] NewCoalFactor=new double[nIntervals]; |
| 303 |
int k=0; |
| 304 |
int res=0; |
| 305 |
double length=0.0; |
| 306 |
for (int i=0;i<nIntervals;i++){ |
| 307 |
length+=intervals[i]; |
| 308 |
res=getEventType(i,nIntervals,lineageCounts); |
| 309 |
if (res > 0) { |
| 310 |
NewCoalTimes[k]=length; |
| 311 |
NewCoalFactor[k]=lineageCounts[i]*(lineageCounts[i]-1.0) / 2.0; |
| 312 |
k++; |
| 313 |
} |
| 314 |
} |
| 315 |
return new TripGP(NewCoalTimes,NewCoalFactor,k); |
| 316 |
} |
| 317 |
|
| 318 |
private final int getEventType(int i,int nIntervals,int[] lineageCounts) { |
| 319 |
|
| 320 |
if (i >= nIntervals) throw new IllegalArgumentException(); |
| 321 |
if (i < nIntervals - 1) { |
| 322 |
return lineageCounts[i] - lineageCounts[i + 1]; |
| 323 |
} else { |
| 324 |
return lineageCounts[i] - 1; |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
public double doOperation() { |
| 334 |
|
| 335 |
|
| 336 |
double hRatio = 0; |
| 337 |
Trip1GP intervalInfo= getTreeIntervals(tree,tree.getRoot(),null); |
| 338 |
double [] intervals =intervalInfo.getInterval(); |
| 339 |
int [] lineageCount=intervalInfo.getLineages(); |
| 340 |
int nIntervals=intervalInfo.getnIntervals(); |
| 341 |
boolean rootIssue=false; |
| 342 |
int k=0; |
| 343 |
int count=0; |
| 344 |
double newval; |
| 345 |
int score=0; |
| 346 |
int oldnum=changePoints.getSize(); |
| 347 |
TripGP newCoalTimes=getNewCoalTimes(intervals,nIntervals,lineageCount); |
| 348 |
|
| 349 |
double [] newTimes=newCoalTimes.getTimes(); |
| 350 |
double [] factor=newCoalTimes.getFactor(); |
| 351 |
double [] oldTimes=getoldCoalTimes(newCoalTimes.getnIntervals()); |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
System.err.println("Makes GP proposal for coalescent times"); |
| 362 |
|
| 363 |
if (changePoints.getParameterValue(changePoints.getSize()-1)!=newTimes[newCoalTimes.getnIntervals()-1]){ |
| 364 |
rootIssue=true; |
| 365 |
} else{ |
| 366 |
rootIssue=false; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
if (rootIssue==false){ |
| 373 |
int mycase=0; |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
for (int j=0;j<changePoints.getSize();j++){ |
| 378 |
if (GPtype.getParameterValue(j)==1){ |
| 379 |
mycase=0; |
| 380 |
|
| 381 |
if (changePoints.getParameterValue(j)!=newTimes[k]){ |
| 382 |
if (changePoints.getParameterValue(j)<newTimes[k] & k<= (newCoalTimes.getnIntervals()-1)){ |
| 383 |
mycase=1; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
if (changePoints.getParameterValue(j)>newTimes[k]){ |
| 389 |
mycase=2; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
if (mycase==1){ |
| 394 |
|
| 395 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 396 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 397 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 398 |
|
| 399 |
hRatio+=GPOperator.getDensity(currentChangePoints,currentGPvalues,changePoints.getParameterValue(j),currentPrecision,j); |
| 400 |
changePoints.removeDimension(j+1); |
| 401 |
GPtype.removeDimension(j+1); |
| 402 |
popSizeParameter.removeDimension(j+1); |
| 403 |
coalfactor.removeDimension(j+1); |
| 404 |
j--; |
| 405 |
k--; |
| 406 |
} |
| 407 |
if (mycase==2){ |
| 408 |
|
| 409 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 410 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 411 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 412 |
double[] val=GPOperator.getGPvalue(currentChangePoints,currentGPvalues,newTimes[k],currentPrecision); |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
popSizeParameter.addDimension((int) val[2],val[0]); |
| 427 |
changePoints.addDimension((int) val[2],newTimes[k]); |
| 428 |
GPtype.addDimension((int) val[2],1); |
| 429 |
coalfactor.addDimension((int) val[2],factor[k]); |
| 430 |
j=(int) val[2]; |
| 431 |
hRatio-=val[1]; |
| 432 |
|
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
k++; |
| 449 |
if (k==newCoalTimes.getnIntervals()){ |
| 450 |
break;} |
| 451 |
} |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
if (rootIssue==true){ |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
int k2=0; |
| 461 |
int pos=0; |
| 462 |
int last=0; |
| 463 |
int count2=0; |
| 464 |
double oldlow=0.0; |
| 465 |
double oldupp=oldTimes[k2]; |
| 466 |
double newlow=0.0; |
| 467 |
double newupp=newTimes[k2]; |
| 468 |
int mycase=0; |
| 469 |
|
| 470 |
System.err.println("size before"+changePoints.getSize()); |
| 471 |
for (int j=0; j<changePoints.getSize();j++){ |
| 472 |
mycase=0; |
| 473 |
|
| 474 |
if (changePoints.getParameterValue(j)<newupp & j<(changePoints.getSize()-1)){ |
| 475 |
if (GPtype.getParameterValue(j)==-1){ |
| 476 |
if (changePoints.getParameterValue(j)>Math.max(oldlow,newlow) & changePoints.getParameterValue(j)<Math.min(oldupp,newupp)){ |
| 477 |
count2++; |
| 478 |
|
| 479 |
} else { |
| 480 |
|
| 481 |
mycase=1; |
| 482 |
} |
| 483 |
}else { |
| 484 |
|
| 485 |
mycase=1; |
| 486 |
|
| 487 |
} |
| 488 |
|
| 489 |
} |
| 490 |
if (changePoints.getParameterValue(j)<newupp & j==(changePoints.getSize()-1)){ |
| 491 |
mycase=2; |
| 492 |
|
| 493 |
} |
| 494 |
|
| 495 |
if (changePoints.getParameterValue(j)>=newupp){ |
| 496 |
|
| 497 |
if (count2<CoalCounts.getParameterValue(k2)){ |
| 498 |
mycase=3; |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
} else { |
| 503 |
if (changePoints.getParameterValue(j)>newupp & k2<newCoalTimes.getnIntervals()-1){ |
| 504 |
mycase=4; |
| 505 |
} |
| 506 |
if (changePoints.getParameterValue(j)==newupp & k2<newCoalTimes.getnIntervals()-1){ |
| 507 |
mycase=5; |
| 508 |
} |
| 509 |
if (changePoints.getParameterValue(j)==newupp & k2==newCoalTimes.getnIntervals()-1){ |
| 510 |
if (j<changePoints.getSize()-1) { |
| 511 |
mycase=7; |
| 512 |
} |
| 513 |
if (j==(changePoints.getSize()-1)){ |
| 514 |
break; |
| 515 |
} |
| 516 |
} |
| 517 |
if (changePoints.getParameterValue(j)>newupp & k2==newCoalTimes.getnIntervals()-1){ |
| 518 |
mycase=6; |
| 519 |
} |
| 520 |
|
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
if (mycase==1){ |
| 525 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 526 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 527 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 528 |
|
| 529 |
hRatio+=GPOperator.getDensity(currentChangePoints,currentGPvalues,changePoints.getParameterValue(j),currentPrecision,j); |
| 530 |
hRatio-=Math.log(oldupp-oldlow); |
| 531 |
changePoints.removeDimension(j+1); |
| 532 |
GPtype.removeDimension(j+1); |
| 533 |
popSizeParameter.removeDimension(j+1); |
| 534 |
coalfactor.removeDimension(j+1); |
| 535 |
j--; |
| 536 |
} |
| 537 |
if (mycase==2){ |
| 538 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 539 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 540 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 541 |
|
| 542 |
hRatio+=GPOperator.getDensity(currentChangePoints,currentGPvalues,changePoints.getParameterValue(j),currentPrecision,j); |
| 543 |
|
| 544 |
double[] val=GPOperator.getGPvalueroot(currentChangePoints,currentGPvalues,newupp,currentPrecision); |
| 545 |
|
| 546 |
|
| 547 |
popSizeParameter.setParameterValue(j,val[0]); |
| 548 |
changePoints.setParameterValue(j,newupp); |
| 549 |
|
| 550 |
coalfactor.setParameterValue(j,factor[k2-1]); |
| 551 |
hRatio-=val[1]; |
| 552 |
j--; |
| 553 |
} |
| 554 |
if (mycase==3){ |
| 555 |
int should=(int) CoalCounts.getParameterValue(k2)-count2; |
| 556 |
j=j+(int) CoalCounts.getParameterValue(k2)-count2-1; |
| 557 |
for (int i=0;i<should;i++){ |
| 558 |
newval=MathUtils.uniform(newlow,newupp); |
| 559 |
pos=wherePoint(newval,intervals); |
| 560 |
|
| 561 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 562 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 563 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 564 |
double[] val=GPOperator.getGPvalue(currentChangePoints,currentGPvalues,newval,currentPrecision); |
| 565 |
|
| 566 |
popSizeParameter.addDimension((int) val[2],val[0]); |
| 567 |
changePoints.addDimension((int) val[2],newval); |
| 568 |
GPtype.addDimension((int) val[2],-1); |
| 569 |
coalfactor.addDimension((int) val[2],0.5*lineageCount[pos]*(lineageCount[pos]-1)); |
| 570 |
hRatio-=val[1]; |
| 571 |
hRatio+=Math.log(newupp-newlow); |
| 572 |
count2++; |
| 573 |
} |
| 574 |
|
| 575 |
} |
| 576 |
if (mycase==4){ |
| 577 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 578 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 579 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 580 |
|
| 581 |
double[] val=GPOperator.getGPvalue(currentChangePoints,currentGPvalues,newupp,currentPrecision); |
| 582 |
|
| 583 |
popSizeParameter.addDimension((int) val[2],val[0]); |
| 584 |
changePoints.addDimension((int) val[2],newupp); |
| 585 |
GPtype.addDimension((int) val[2],1); |
| 586 |
coalfactor.addDimension((int) val[2],factor[k2]); |
| 587 |
hRatio-=val[1]; |
| 588 |
|
| 589 |
count2=0; |
| 590 |
k2++; |
| 591 |
last=pos; |
| 592 |
newlow=newupp; |
| 593 |
oldlow=oldupp; |
| 594 |
newupp=newTimes[k2]; |
| 595 |
oldupp=oldTimes[k2]; |
| 596 |
} |
| 597 |
if (mycase==5){ |
| 598 |
count2=0; |
| 599 |
k2++; |
| 600 |
last=pos; |
| 601 |
newlow=newupp; |
| 602 |
oldlow=oldupp; |
| 603 |
newupp=newTimes[k2]; |
| 604 |
oldupp=oldTimes[k2]; |
| 605 |
|
| 606 |
|
| 607 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 608 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 609 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 610 |
if (j==changePoints.getSize()-1){ |
| 611 |
double[] val=GPOperator.getGPvalueroot(currentChangePoints,currentGPvalues,newupp,currentPrecision); |
| 612 |
popSizeParameter.addDimension(j+1,val[0]); |
| 613 |
changePoints.addDimension(j+1,newupp); |
| 614 |
GPtype.addDimension(j+1,1); |
| 615 |
coalfactor.addDimension(j+1,factor[k2]); |
| 616 |
hRatio-=val[1]; |
| 617 |
}else{ |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
} |
| 625 |
} |
| 626 |
if (mycase==6){ |
| 627 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 628 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 629 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 630 |
double[] val=GPOperator.getGPvalue(currentChangePoints,currentGPvalues,newupp,currentPrecision); |
| 631 |
popSizeParameter.addDimension(j,val[0]); |
| 632 |
changePoints.addDimension(j,newupp); |
| 633 |
GPtype.addDimension(j,1); |
| 634 |
coalfactor.addDimension(j,factor[k2]); |
| 635 |
hRatio-=val[1]; |
| 636 |
j--; |
| 637 |
} |
| 638 |
if (mycase==7){ |
| 639 |
double [] currentChangePoints = (double []) changePoints.getParameterValues(); |
| 640 |
DenseVector currentGPvalues= new DenseVector(popSizeParameter.getParameterValues()); |
| 641 |
double currentPrecision = precisionParameter.getParameterValue(0); |
| 642 |
|
| 643 |
hRatio+=GPOperator.getDensity(currentChangePoints,currentGPvalues,changePoints.getParameterValue(j+1),currentPrecision,j+1); |
| 644 |
hRatio-=Math.log(oldupp-oldlow); |
| 645 |
if (j<changePoints.getSize()-2){ |
| 646 |
changePoints.removeDimension(j+2); |
| 647 |
GPtype.removeDimension(j+2); |
| 648 |
popSizeParameter.removeDimension(j+2); |
| 649 |
coalfactor.removeDimension(j+2); |
| 650 |
}else{ |
| 651 |
changePoints.setDimension(j+1); |
| 652 |
GPtype.setDimension(j+1); |
| 653 |
popSizeParameter.setDimension(j+1); |
| 654 |
coalfactor.setDimension(j+1); |
| 655 |
} |
| 656 |
|
| 657 |
j--; |
| 658 |
} |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
System.err.println("size after"+changePoints.getSize()+"and ratio"+hRatio); |
| 663 |
return hRatio; |
| 664 |
|
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
public final String getOperatorName() { |
| 670 |
return GaussianProcessSkytrackTreeOperatorParser.BLOCK_UPDATE_OPERATOR; |
| 671 |
} |
| 672 |
|
| 673 |
public double getAdaptableParameter() { |
| 674 |
|
| 675 |
return Math.sqrt(scaleFactor - 1); |
| 676 |
} |
| 677 |
|
| 678 |
public void setAdaptableParameter(double value) { |
| 679 |
|
| 680 |
scaleFactor = 1 + value * value; |
| 681 |
} |
| 682 |
|
| 683 |
public double getRawParameter() { |
| 684 |
return scaleFactor; |
| 685 |
} |
| 686 |
|
| 687 |
public double getScaleFactor() { |
| 688 |
return scaleFactor; |
| 689 |
} |
| 690 |
|
| 691 |
public String getAdaptableParameterName() { |
| 692 |
return "scaleFactor"; |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
} |