| 1 |
|
| 2 |
package dr.evomodel.antigenic.phyloclustering.misc.obsolete; |
| 3 |
|
| 4 |
import java.util.HashMap; |
| 5 |
import java.util.LinkedList; |
| 6 |
import java.util.Map; |
| 7 |
|
| 8 |
import dr.evolution.tree.NodeRef; |
| 9 |
import dr.evomodel.tree.TreeModel; |
| 10 |
import dr.inference.model.MatrixParameter; |
| 11 |
import dr.inference.model.Parameter; |
| 12 |
import dr.inference.operators.GibbsOperator; |
| 13 |
import dr.inference.operators.MCMCOperator; |
| 14 |
import dr.inference.operators.SimpleMCMCOperator; |
| 15 |
import dr.math.MathUtils; |
| 16 |
import dr.xml.*; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class TreeClusterSequentialSampling extends SimpleMCMCOperator implements GibbsOperator{ |
| 27 |
|
| 28 |
Parameter virusOffsetsParameter; |
| 29 |
private double sigmaSq =1; |
| 30 |
private int numdata = 0; |
| 31 |
|
| 32 |
|
| 33 |
private MatrixParameter mu = null; |
| 34 |
private Parameter clusterLabels = null; |
| 35 |
private Parameter K = null; |
| 36 |
|
| 37 |
private MatrixParameter virusLocations = null; |
| 38 |
|
| 39 |
private int maxLabel = 0; |
| 40 |
private int[] muLabels = null; |
| 41 |
|
| 42 |
private int[] groupSize; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
private double numAcceptMoveMu = 0; |
| 47 |
private double numProposeMoveMu = 0; |
| 48 |
|
| 49 |
private double numAcceptMoveC = 0; |
| 50 |
private double numProposeMoveC = 0; |
| 51 |
|
| 52 |
private int isMoveMu = -1; |
| 53 |
|
| 54 |
|
| 55 |
private double[] old_vLoc0 ; |
| 56 |
private double[] old_vLoc1 ; |
| 57 |
|
| 58 |
private Parameter clusterOffsetsParameter; |
| 59 |
private AGLikelihoodTreeCluster clusterLikelihood = null; |
| 60 |
|
| 61 |
private int groupSelectedChange = -1; |
| 62 |
private int virusIndexChange = -1; |
| 63 |
private double originalValueChange = -1; |
| 64 |
private int dimSelectChange = -1; |
| 65 |
|
| 66 |
private double[] mu0_offset; |
| 67 |
|
| 68 |
private Parameter breakPoints = null; |
| 69 |
|
| 70 |
private int binSize=20; |
| 71 |
|
| 72 |
|
| 73 |
private Parameter status; |
| 74 |
|
| 75 |
private TreeModel treeModel; |
| 76 |
|
| 77 |
int []membershipToClusterLabelIndexes = null; |
| 78 |
|
| 79 |
private int numNodes; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public TreeClusterSequentialSampling(MatrixParameter virusLocations, MatrixParameter mu, Parameter clusterLabels, Parameter K, double weight, Parameter virusOffsetsParameter, Parameter clusterOffsetsParameter, Parameter breakPointsParameter, Parameter statusParameter, TreeModel treeModel_in, AGLikelihoodTreeCluster clusterLikelihood_in) { |
| 87 |
|
| 88 |
|
| 89 |
System.out.println("Loading the constructor for Sequential sampler"); |
| 90 |
|
| 91 |
this.clusterLikelihood = clusterLikelihood_in; |
| 92 |
this.treeModel= treeModel_in; |
| 93 |
this.mu = mu; |
| 94 |
this.K = K; |
| 95 |
this.clusterLabels = clusterLabels; |
| 96 |
|
| 97 |
this.virusLocations = virusLocations; |
| 98 |
this.virusOffsetsParameter = virusOffsetsParameter; |
| 99 |
|
| 100 |
this.clusterOffsetsParameter = clusterOffsetsParameter; |
| 101 |
this.breakPoints= breakPointsParameter; |
| 102 |
|
| 103 |
this.status = statusParameter; |
| 104 |
|
| 105 |
|
| 106 |
numdata = virusOffsetsParameter.getSize(); |
| 107 |
System.out.println("numdata="+ numdata); |
| 108 |
|
| 109 |
|
| 110 |
int K_int = (int) K.getParameterValue(0); |
| 111 |
|
| 112 |
|
| 113 |
System.out.println("K_int=" + K_int); |
| 114 |
groupSize = new int[binSize]; |
| 115 |
for(int i=0; i < binSize; i++){ |
| 116 |
groupSize[i] = 0; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
for(int i=0; i < numdata; i++){ |
| 121 |
|
| 122 |
int index = (int) clusterLabels.getParameterValue(i); |
| 123 |
groupSize[ index]++; |
| 124 |
} |
| 125 |
|
| 126 |
for(int i=0; i < numdata;i++){ |
| 127 |
if(maxLabel < (int) clusterLabels.getParameterValue(i)){ |
| 128 |
maxLabel = (int) clusterLabels.getParameterValue(i); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
muLabels = new int[binSize]; |
| 140 |
|
| 141 |
for(int i=0; i < maxLabel; i++){ |
| 142 |
int j=0; |
| 143 |
if(groupSize[i] >0){ |
| 144 |
muLabels[j] = i; |
| 145 |
j++; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
setWeight(weight); |
| 154 |
|
| 155 |
System.out.println("Finished loading the constructor for ClusterAlgorithmOperator"); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
public final double doOperation() { |
| 167 |
|
| 168 |
System.out.println("do operation of sequential sampling"); |
| 169 |
|
| 170 |
setMembershipToClusterLabelIndexes(); |
| 171 |
|
| 172 |
numNodes = treeModel.getNodeCount(); |
| 173 |
|
| 174 |
updateK(); |
| 175 |
int K_int = (int) K.getParameterValue(0); |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
int[] cutNode = new int[K_int]; |
| 180 |
|
| 181 |
int[] oldclusterLabelArray = new int[numNodes]; |
| 182 |
int[] clusterLabelArray = null; |
| 183 |
|
| 184 |
int[] onPoints = new int[K_int]; |
| 185 |
int numOn=0; |
| 186 |
for(int i=0; i < binSize; i++){ |
| 187 |
if( (int)status.getParameterValue(i) ==1 ){ |
| 188 |
onPoints[numOn] = i; |
| 189 |
numOn++; |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
cutNode = new int[1]; |
| 199 |
cutNode[0] = 785; |
| 200 |
onPoints = new int[1]; |
| 201 |
onPoints[0] = 0; |
| 202 |
|
| 203 |
resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode); |
| 208 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 209 |
for(int i=0; i < numdata; i++){ |
| 210 |
clusterLabels.setParameterValue(i, clusterLabelArray[i]); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
setVirusLocationAutoCorrelatedModel(); |
| 215 |
|
| 216 |
double topLogProb = clusterLikelihood.getLogLikelihood(); |
| 217 |
System.out.println(topLogProb); |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
cutNode = new int[2]; |
| 223 |
cutNode[0] = 785; |
| 224 |
onPoints = new int[2]; |
| 225 |
onPoints[0] = 0; |
| 226 |
onPoints[1] = 1; |
| 227 |
|
| 228 |
double []logNumerator = new double[numNodes]; |
| 229 |
|
| 230 |
for(int curTest=0; curTest < numNodes; curTest++){ |
| 231 |
|
| 232 |
int hasBeenAdded = checkSiteHasBeenAddedToOnIndicators(curTest); |
| 233 |
if(hasBeenAdded ==0){ |
| 234 |
|
| 235 |
cutNode = new int[2]; |
| 236 |
cutNode[0] = 785; |
| 237 |
cutNode[1] = curTest; |
| 238 |
|
| 239 |
resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints); |
| 240 |
|
| 241 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode); |
| 242 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 243 |
|
| 244 |
|
| 245 |
for(int i=0; i < numdata; i++){ |
| 246 |
clusterLabels.setParameterValue(i, clusterLabelArray[i]); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
setVirusLocationAutoCorrelatedModel(); |
| 251 |
|
| 252 |
|
| 253 |
logNumerator[curTest] += clusterLikelihood.getLogLikelihood() ; |
| 254 |
} |
| 255 |
else{ |
| 256 |
logNumerator[curTest] = Double.NEGATIVE_INFINITY; |
| 257 |
System.out.println("Don't calculate for node" + cutNode[0]); |
| 258 |
} |
| 259 |
|
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
double answer = verifyAssumption(topLogProb, logNumerator); |
| 264 |
|
| 265 |
|
| 266 |
System.out.println("the ratio is " + answer); |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
System.exit(0); |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
double tmpMu1 = mu.getParameter(onPoints[7] +1).getParameterValue(0); |
| 289 |
double tmpMu2 = mu.getParameter(onPoints[7] +1).getParameterValue(1); |
| 290 |
|
| 291 |
mu.getParameter(onPoints[7] +1).setParameterValue(0, mu.getParameter(onPoints[8] +1).getParameterValue(0)); |
| 292 |
mu.getParameter(onPoints[7] +1).setParameterValue(1, mu.getParameter(onPoints[8] +1).getParameterValue(1)); |
| 293 |
|
| 294 |
mu.getParameter(onPoints[8] +1).setParameterValue(0, tmpMu1); |
| 295 |
mu.getParameter(onPoints[8] +1).setParameterValue(1, tmpMu2); |
| 296 |
|
| 297 |
|
| 298 |
for(int curNode=8; curNode < K_int; curNode++){ |
| 299 |
|
| 300 |
cutNode[0] = 785; |
| 301 |
cutNode[1] = 775; |
| 302 |
cutNode[2] = 763; |
| 303 |
cutNode[3] = 697; |
| 304 |
cutNode[4] = 747; |
| 305 |
cutNode[5] = 679; |
| 306 |
cutNode[6] = 662; |
| 307 |
|
| 308 |
cutNode[7] = 638; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
double []logNumeratorProb = new double[numNodes]; |
| 314 |
|
| 315 |
|
| 316 |
for(int curTest=0; curTest < numNodes; curTest++){ |
| 317 |
|
| 318 |
int hasBeenAdded = checkSiteHasBeenAddedToOnIndicators(curTest); |
| 319 |
if(hasBeenAdded ==0){ |
| 320 |
int[] testCutNode = new int[curNode+1]; |
| 321 |
for(int i=0; i < curNode; i++){ |
| 322 |
testCutNode[i] = cutNode[i]; |
| 323 |
} |
| 324 |
testCutNode[curNode] = curTest; |
| 325 |
|
| 326 |
resetStatusAndBreakpointsGivenCutNodes(testCutNode, onPoints); |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(testCutNode); |
| 359 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 360 |
|
| 361 |
|
| 362 |
for(int i=0; i < numdata; i++){ |
| 363 |
clusterLabels.setParameterValue(i, clusterLabelArray[i]); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
setVirusLocationAutoCorrelatedModel(); |
| 369 |
|
| 370 |
|
| 371 |
if(curNode == 0 && curTest == 0){ |
| 372 |
for(int i=0; i < numdata; i++){ |
| 373 |
Parameter v = virusLocations.getParameter(i); |
| 374 |
|
| 375 |
|
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
logNumeratorProb[curTest] = clusterLikelihood.getLogLikelihood(); |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
} |
| 394 |
else{ |
| 395 |
logNumeratorProb[curTest] = Double.NEGATIVE_INFINITY; |
| 396 |
} |
| 397 |
|
| 398 |
} |
| 399 |
|
| 400 |
double []condDistribution = calculateConditionalProbabilityGivenLogNumeratorProb(logNumeratorProb); |
| 401 |
|
| 402 |
|
| 403 |
for(int i=0; i < numNodes; i++){ |
| 404 |
|
| 405 |
System.out.println("node " + i + " p=" + condDistribution[i]); |
| 406 |
|
| 407 |
} |
| 408 |
System.out.println("==============================="); |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
int site_add = MathUtils.randomChoicePDF(condDistribution); |
| 414 |
|
| 415 |
|
| 416 |
int[] newCutNode = new int[curNode+1]; |
| 417 |
for(int i=0; i < curNode; i++){ |
| 418 |
newCutNode[i] = cutNode[i]; |
| 419 |
} |
| 420 |
newCutNode[curNode] = site_add; |
| 421 |
cutNode = newCutNode; |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(newCutNode); |
| 427 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 428 |
|
| 429 |
oldclusterLabelArray = clusterLabelArray; |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
printCutNode(cutNode); |
| 441 |
|
| 442 |
|
| 443 |
resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode); |
| 457 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 458 |
for(int i=0; i < numdata; i++){ |
| 459 |
clusterLabels.setParameterValue(i, clusterLabelArray[i]); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
setVirusLocationAutoCorrelatedModel(); |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
System.out.println(clusterLikelihood.getLogLikelihood()); |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
cutNode[0] = 785; |
| 478 |
cutNode[1] = 775; |
| 479 |
cutNode[2] = 763; |
| 480 |
cutNode[3] = 697; |
| 481 |
cutNode[4] = 747; |
| 482 |
cutNode[5] = 679; |
| 483 |
cutNode[6] = 662; |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
cutNode[7] = 638; |
| 488 |
cutNode[8] = 521; |
| 489 |
|
| 490 |
resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints); |
| 491 |
|
| 492 |
clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode); |
| 493 |
relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); |
| 494 |
for(int i=0; i < numdata; i++){ |
| 495 |
clusterLabels.setParameterValue(i, clusterLabelArray[i]); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
setVirusLocationAutoCorrelatedModel(); |
| 500 |
|
| 501 |
System.out.println(clusterLikelihood.getLogLikelihood()); |
| 502 |
System.exit(0); |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
return(Double.POSITIVE_INFINITY); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
private void resetStatusAndBreakpointsGivenCutNodes(int[] testCutNode, int[] onPoints) { |
| 522 |
|
| 523 |
for(int i=0; i < binSize; i++){ |
| 524 |
status.setParameterValue(i, 0); |
| 525 |
breakPoints.setParameterValue(i, -1); |
| 526 |
} |
| 527 |
|
| 528 |
int numOn = testCutNode.length; |
| 529 |
int countOn=0; |
| 530 |
for(int i=0; i < binSize; i++){ |
| 531 |
if(countOn < numOn){ |
| 532 |
status.setParameterValue(onPoints[countOn], 1); |
| 533 |
breakPoints.setParameterValue(onPoints[countOn],testCutNode[countOn]); |
| 534 |
countOn++; |
| 535 |
} |
| 536 |
|
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
private void updateK() { |
| 543 |
|
| 544 |
|
| 545 |
int K_count = 0; |
| 546 |
for(int i=0; i < binSize; i++){ |
| 547 |
K_count += (int) status.getParameterValue(i); |
| 548 |
} |
| 549 |
|
| 550 |
K.setParameterValue(0, K_count); |
| 551 |
|
| 552 |
|
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
private void printCutNode(int[] cutNode) { |
| 557 |
System.out.print("sampled:\t["); |
| 558 |
for(int i=0; i < cutNode.length ; i++){ |
| 559 |
System.out.print(cutNode[i] + ","); |
| 560 |
} |
| 561 |
System.out.println("]"); |
| 562 |
|
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
private double[] calculateConditionalProbabilityGivenLogNumeratorProb( |
| 568 |
double[] logNumeratorProb) { |
| 569 |
int numNodes = logNumeratorProb.length; |
| 570 |
double maxLogProb = logNumeratorProb[0]; |
| 571 |
for(int i=0; i < numNodes; i++ ){ |
| 572 |
if(logNumeratorProb[i] > maxLogProb){ |
| 573 |
maxLogProb = logNumeratorProb[i]; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
double sumLogDenominator = 0; |
| 578 |
for(int i=0; i < numNodes; i++){ |
| 579 |
if(logNumeratorProb[i] != Double.NEGATIVE_INFINITY){ |
| 580 |
sumLogDenominator += Math.exp((logNumeratorProb[i]-maxLogProb)); |
| 581 |
} |
| 582 |
} |
| 583 |
sumLogDenominator = Math.log(sumLogDenominator) + maxLogProb; |
| 584 |
|
| 585 |
double sumProb = 0; |
| 586 |
double []condProb = new double[numNodes]; |
| 587 |
for(int i=0; i < numNodes; i++){ |
| 588 |
condProb[i] = Math.exp( logNumeratorProb[i] - sumLogDenominator ); |
| 589 |
|
| 590 |
sumProb +=condProb[i]; |
| 591 |
if(condProb[i] > 0.01){ |
| 592 |
|
| 593 |
} |
| 594 |
} |
| 595 |
return(condProb); |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
private double verifyAssumption( double topLogMarginal,double[] logNumeratorProb) { |
| 602 |
|
| 603 |
|
| 604 |
for(int i=0; i < numNodes; i++){ |
| 605 |
System.out.println(logNumeratorProb[i]); |
| 606 |
} |
| 607 |
int numNodes = logNumeratorProb.length; |
| 608 |
double maxLogProb = logNumeratorProb[0]; |
| 609 |
for(int i=0; i < numNodes; i++ ){ |
| 610 |
if(logNumeratorProb[i] > maxLogProb){ |
| 611 |
maxLogProb = logNumeratorProb[i]; |
| 612 |
} |
| 613 |
} |
| 614 |
System.out.println("maxLogProb = " + maxLogProb); |
| 615 |
|
| 616 |
double sumLogDenominator = 0; |
| 617 |
for(int i=0; i < numNodes; i++){ |
| 618 |
if(logNumeratorProb[i] != Double.NEGATIVE_INFINITY){ |
| 619 |
sumLogDenominator += Math.exp((logNumeratorProb[i]-maxLogProb)); |
| 620 |
} |
| 621 |
} |
| 622 |
System.out.println("tmp sum = " + sumLogDenominator); |
| 623 |
sumLogDenominator = Math.log(sumLogDenominator) + maxLogProb; |
| 624 |
|
| 625 |
System.out.println("topLogMarginal = " + topLogMarginal); |
| 626 |
System.out.println("sumLogDenominator = " + sumLogDenominator); |
| 627 |
double ratio = Math.exp( Math.log(numNodes-1) + topLogMarginal - sumLogDenominator ); |
| 628 |
|
| 629 |
return(ratio); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
private int checkSiteHasBeenAddedToOnIndicators(int curTest){ |
| 636 |
int hasBeenAdded=0; |
| 637 |
for(int i=0; i < binSize; i++){ |
| 638 |
if((int)status.getParameterValue(i) == 1 ){ |
| 639 |
if( (int) breakPoints.getParameterValue(i) == curTest){ |
| 640 |
hasBeenAdded=1; |
| 641 |
break; |
| 642 |
} |
| 643 |
} |
| 644 |
} |
| 645 |
return(hasBeenAdded); |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
private void setVirusLocationAndOffsets() { |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
double[] meanYear = new double[binSize]; |
| 655 |
double[] groupCount = new double[binSize]; |
| 656 |
for(int i=0; i < numdata; i++){ |
| 657 |
int label = (int) clusterLabels.getParameterValue(i); |
| 658 |
double year = 0; |
| 659 |
if (virusOffsetsParameter != null) { |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
year = virusOffsetsParameter.getParameterValue(i); |
| 664 |
|
| 665 |
} |
| 666 |
else{ |
| 667 |
System.out.println("virus Offeset Parameter NOT present. We expect one though. Something is wrong."); |
| 668 |
} |
| 669 |
meanYear[ label] = meanYear[ label] + year; |
| 670 |
|
| 671 |
groupCount[ label ] = groupCount[ label ] +1; |
| 672 |
} |
| 673 |
|
| 674 |
for(int i=0; i < binSize; i++){ |
| 675 |
if(groupCount[i] > 0){ |
| 676 |
meanYear[i] = meanYear[i]/groupCount[i]; |
| 677 |
} |
| 678 |
|
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
mu0_offset = new double[binSize]; |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
for(int i=0; i < binSize; i++){ |
| 689 |
|
| 690 |
mu0_offset[i] = meanYear[i]; |
| 691 |
|
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
for(int i=0; i < numdata; i++){ |
| 699 |
int label = (int) clusterLabels.getParameterValue(i); |
| 700 |
Parameter vLoc = virusLocations.getParameter(i); |
| 701 |
|
| 702 |
double muValue = mu.getParameter(label).getParameterValue(0); |
| 703 |
vLoc.setParameterValue(0, muValue); |
| 704 |
double muValue2 = mu.getParameter(label).getParameterValue(1); |
| 705 |
vLoc.setParameterValue(1, muValue2); |
| 706 |
|
| 707 |
} |
| 708 |
|
| 709 |
for(int i=0; i < numdata; i++){ |
| 710 |
int label = (int) clusterLabels.getParameterValue(i); |
| 711 |
|
| 712 |
if(clusterOffsetsParameter != null){ |
| 713 |
|
| 714 |
|
| 715 |
clusterOffsetsParameter.setParameterValue( i , mu0_offset[label]); |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
private void setVirusLocationAutoCorrelatedModel() { |
| 738 |
int numNodes = treeModel.getNodeCount(); |
| 739 |
double[][] nodeloc = new double[numNodes][2]; |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
int[] nodeStatus = new int[numNodes]; |
| 748 |
for(int i=0; i < numNodes; i ++){ |
| 749 |
nodeStatus[i] = -1; |
| 750 |
} |
| 751 |
|
| 752 |
for(int i=0; i < (binSize ); i++){ |
| 753 |
if((int) status.getParameterValue(i) ==1){ |
| 754 |
nodeStatus[(int)breakPoints.getParameterValue(i)] = i; |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
NodeRef cNode = treeModel.getRoot(); |
| 773 |
LinkedList<NodeRef> visitlist = new LinkedList<NodeRef>(); |
| 774 |
|
| 775 |
visitlist.add(cNode); |
| 776 |
|
| 777 |
int countProcessed=0; |
| 778 |
while(visitlist.size() > 0){ |
| 779 |
|
| 780 |
|
| 781 |
countProcessed++; |
| 782 |
|
| 783 |
if(treeModel.getParent(cNode) == null){ |
| 784 |
Parameter curMu = mu.getParameter(0); |
| 785 |
nodeloc[cNode.getNumber()][0] = curMu.getParameterValue(0); |
| 786 |
nodeloc[cNode.getNumber() ][1] = curMu.getParameterValue(1); |
| 787 |
} |
| 788 |
else{ |
| 789 |
nodeloc[cNode.getNumber()][0] = nodeloc[treeModel.getParent(cNode).getNumber()][0]; |
| 790 |
nodeloc[cNode.getNumber()][1] = nodeloc[treeModel.getParent(cNode).getNumber()][1]; |
| 791 |
|
| 792 |
if(nodeStatus[cNode.getNumber()] != -1){ |
| 793 |
|
| 794 |
Parameter curMu = mu.getParameter(nodeStatus[cNode.getNumber()] +1); |
| 795 |
nodeloc[cNode.getNumber()][0] += curMu.getParameterValue(0); |
| 796 |
nodeloc[cNode.getNumber()][1] += curMu.getParameterValue(1); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
for(int childNum=0; childNum < treeModel.getChildCount(cNode); childNum++){ |
| 803 |
NodeRef node= treeModel.getChild(cNode,childNum); |
| 804 |
visitlist.add(node); |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
visitlist.pop(); |
| 809 |
|
| 810 |
if(visitlist.size() > 0){ |
| 811 |
cNode = visitlist.getFirst(); |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
for(int i=0; i < numdata; i++){ |
| 819 |
Parameter vLocParameter = virusLocations.getParameter(i); |
| 820 |
vLocParameter.setParameterValue(0, nodeloc[membershipToClusterLabelIndexes[i]][0]); |
| 821 |
vLocParameter.setParameterValue(1, nodeloc[membershipToClusterLabelIndexes[i]][1]); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
private void relabelClusterLabels(int[] clusterLabel, int[] oldclusterLabel) { |
| 844 |
|
| 845 |
int maxOldLabel = 0; |
| 846 |
for(int i=0; i < oldclusterLabel.length; i++){ |
| 847 |
if(maxOldLabel < oldclusterLabel[i]){ |
| 848 |
maxOldLabel = oldclusterLabel[i]; |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
Map<Integer, Integer> m = new HashMap<Integer, Integer>(); |
| 854 |
int[] isOldUsed = new int[ clusterLabel.length ]; |
| 855 |
|
| 856 |
for(int i=0; i < clusterLabel.length; i++){ |
| 857 |
|
| 858 |
|
| 859 |
if(m.get(new Integer(clusterLabel[i])) == null ){ |
| 860 |
if(isOldUsed[oldclusterLabel[i]] == 0){ |
| 861 |
m.put(new Integer(clusterLabel[i]), new Integer(oldclusterLabel[i])); |
| 862 |
isOldUsed[oldclusterLabel[i]] = 1; |
| 863 |
} |
| 864 |
else{ |
| 865 |
maxOldLabel++; |
| 866 |
m.put(new Integer(clusterLabel[i]), new Integer(maxOldLabel)); |
| 867 |
} |
| 868 |
|
| 869 |
} |
| 870 |
|
| 871 |
clusterLabel[i] = m.get(new Integer( clusterLabel[i])).intValue(); |
| 872 |
|
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
private int[] setClusterLabelsByTestCutNodeByNodeOrder(int[] testCutNode) { |
| 879 |
int []membership = determine_membershipByNodeOrder(treeModel, testCutNode, testCutNode.length); |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
int[] clusterLabel = new int[numdata]; |
| 889 |
|
| 890 |
for(int i=0; i < numdata; i++){ |
| 891 |
clusterLabel[i] = membership[membershipToClusterLabelIndexes[i]]; |
| 892 |
} |
| 893 |
return(clusterLabel); |
| 894 |
} |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
private void setMembershipToClusterLabelIndexes(){ |
| 899 |
int numNodes = treeModel.getNodeCount(); |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
membershipToClusterLabelIndexes = new int[numdata]; |
| 904 |
for(int i=0; i < numdata; i++){ |
| 905 |
Parameter v = virusLocations.getParameter(i); |
| 906 |
String curName = v.getParameterName(); |
| 907 |
|
| 908 |
int isFound = 0; |
| 909 |
for(int j=0; j < numNodes; j++){ |
| 910 |
String treeId = treeModel.getTaxonId(j); |
| 911 |
if(curName.equals(treeId) ){ |
| 912 |
|
| 913 |
membershipToClusterLabelIndexes[i] = j; |
| 914 |
isFound=1; |
| 915 |
break; |
| 916 |
} |
| 917 |
} |
| 918 |
if(isFound ==0){ |
| 919 |
System.out.println("not found. Exit now."); |
| 920 |
System.exit(0); |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
private int[] setClusterLabelsByTestCutNode(int[] testCutNode) { |
| 927 |
|
| 928 |
int []membership = determine_membership(treeModel, testCutNode, testCutNode.length); |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
int[] clusterLabel = new int[numdata]; |
| 938 |
|
| 939 |
for(int i=0; i < numdata; i++){ |
| 940 |
clusterLabel[i] = membership[membershipToClusterLabelIndexes[i]]; |
| 941 |
} |
| 942 |
|
| 943 |
return(clusterLabel); |
| 944 |
|
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
private void setClusterLabels(int K_int) { |
| 953 |
|
| 954 |
int numNodes = treeModel.getNodeCount(); |
| 955 |
int[] cutNodes = new int[K_int]; |
| 956 |
int cutNum = 0; |
| 957 |
String content = ""; |
| 958 |
for(int i=0; i < binSize; i++){ |
| 959 |
if( (int) status.getParameterValue( i ) ==1 ){ |
| 960 |
cutNodes[cutNum] = (int) breakPoints.getParameterValue(i); |
| 961 |
content += (int) breakPoints.getParameterValue(i) + ","; |
| 962 |
cutNum++; |
| 963 |
} |
| 964 |
|
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
if(cutNum != K_int){ |
| 969 |
System.out.println("cutNum != K_int. we got a problem"); |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
int []membership = determine_membership(treeModel, cutNodes, K_int); |
| 978 |
|
| 979 |
double uniqueCode = 0; |
| 980 |
for(int i=0; i < numNodes; i++){ |
| 981 |
uniqueCode += membership[i]*i; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
int []membershipToClusterLabelIndexes = new int[numdata]; |
| 1020 |
for(int i=0; i < numdata; i++){ |
| 1021 |
Parameter v = virusLocations.getParameter(i); |
| 1022 |
String curName = v.getParameterName(); |
| 1023 |
|
| 1024 |
int isFound = 0; |
| 1025 |
for(int j=0; j < numNodes; j++){ |
| 1026 |
String treeId = treeModel.getTaxonId(j); |
| 1027 |
if(curName.equals(treeId) ){ |
| 1028 |
|
| 1029 |
membershipToClusterLabelIndexes[i] = j; |
| 1030 |
isFound=1; |
| 1031 |
break; |
| 1032 |
} |
| 1033 |
|
| 1034 |
} |
| 1035 |
if(isFound ==0){ |
| 1036 |
System.out.println("not found. Exit now."); |
| 1037 |
System.exit(0); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
for(int i=0; i < numdata; i++){ |
| 1050 |
|
| 1051 |
|
| 1052 |
Parameter vloc = virusLocations.getParameter(i); |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
clusterLabels.setParameterValue( i, membership[membershipToClusterLabelIndexes[i]]); |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
private static boolean isCutNode(int number, int cutNodes[], int numCut) { |
| 1070 |
if(numCut > 0){ |
| 1071 |
for(int i=0; i < numCut; i++){ |
| 1072 |
if(number == cutNodes[i]){ |
| 1073 |
return true; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
} |
| 1077 |
return false; |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
static int[] determine_membership(TreeModel treeModel, int[] cutNodes, int numCuts){ |
| 1084 |
|
| 1085 |
|
| 1086 |
NodeRef root = treeModel.getRoot(); |
| 1087 |
|
| 1088 |
int numClusters = 1; |
| 1089 |
LinkedList<NodeRef> list = new LinkedList<NodeRef>(); |
| 1090 |
list.addFirst(root); |
| 1091 |
|
| 1092 |
int[] membership = new int[treeModel.getNodeCount()]; |
| 1093 |
for(int i=0; i < treeModel.getNodeCount(); i++){ |
| 1094 |
membership[i] = -1; |
| 1095 |
} |
| 1096 |
membership[root.getNumber()] = 0; |
| 1097 |
|
| 1098 |
while(!list.isEmpty()){ |
| 1099 |
|
| 1100 |
NodeRef curElement = list.pop(); |
| 1101 |
|
| 1102 |
String content = "node #" + curElement.getNumber() +", taxon= " ; |
| 1103 |
if(treeModel.getNodeTaxon(curElement)== null){ |
| 1104 |
content += "internal node\t"; |
| 1105 |
} |
| 1106 |
else{ |
| 1107 |
content += treeModel.getNodeTaxon(curElement).getId() + "\t"; |
| 1108 |
|
| 1109 |
} |
| 1110 |
|
| 1111 |
if(treeModel.getParent(curElement)== null){ |
| 1112 |
|
| 1113 |
} |
| 1114 |
else{ |
| 1115 |
|
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
if(!treeModel.isRoot(curElement)){ |
| 1120 |
if(isCutNode(curElement.getNumber(), cutNodes, numCuts)){ |
| 1121 |
|
| 1122 |
numClusters++ ; |
| 1123 |
membership[ curElement.getNumber() ] = numClusters - 1; |
| 1124 |
} |
| 1125 |
else{ |
| 1126 |
|
| 1127 |
membership[curElement.getNumber()] = membership[treeModel.getParent(curElement).getNumber()]; |
| 1128 |
} |
| 1129 |
|
| 1130 |
} |
| 1131 |
content += " cluster = " + membership[curElement.getNumber()] ; |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
for(int childNum=0; childNum < treeModel.getChildCount(curElement); childNum++){ |
| 1137 |
list.addFirst(treeModel.getChild(curElement,childNum)); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
return(membership); |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
static int[] determine_membershipByNodeOrder(TreeModel treeModel, int[] cutNodes, int numCuts){ |
| 1147 |
|
| 1148 |
|
| 1149 |
Map<Integer, Integer> m = new HashMap<Integer, Integer>(); |
| 1150 |
for(int i=0; i < numCuts; i++){ |
| 1151 |
m.put(new Integer(cutNodes[i]), new Integer(i+1)); |
| 1152 |
|
| 1153 |
|
| 1154 |
} |
| 1155 |
|
| 1156 |
|
| 1157 |
NodeRef root = treeModel.getRoot(); |
| 1158 |
|
| 1159 |
int numClusters = 1; |
| 1160 |
LinkedList<NodeRef> list = new LinkedList<NodeRef>(); |
| 1161 |
list.addFirst(root); |
| 1162 |
|
| 1163 |
int[] membership = new int[treeModel.getNodeCount()]; |
| 1164 |
for(int i=0; i < treeModel.getNodeCount(); i++){ |
| 1165 |
membership[i] = -1; |
| 1166 |
} |
| 1167 |
membership[root.getNumber()] = 0; |
| 1168 |
|
| 1169 |
while(!list.isEmpty()){ |
| 1170 |
|
| 1171 |
NodeRef curElement = list.pop(); |
| 1172 |
|
| 1173 |
String content = "node #" + curElement.getNumber() +", taxon= " ; |
| 1174 |
if(treeModel.getNodeTaxon(curElement)== null){ |
| 1175 |
content += "internal node\t"; |
| 1176 |
} |
| 1177 |
else{ |
| 1178 |
content += treeModel.getNodeTaxon(curElement).getId() + "\t"; |
| 1179 |
|
| 1180 |
} |
| 1181 |
|
| 1182 |
if(treeModel.getParent(curElement)== null){ |
| 1183 |
|
| 1184 |
} |
| 1185 |
else{ |
| 1186 |
|
| 1187 |
} |
| 1188 |
|
| 1189 |
|
| 1190 |
if(!treeModel.isRoot(curElement)){ |
| 1191 |
if(isCutNode(curElement.getNumber(), cutNodes, numCuts)){ |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
membership[ curElement.getNumber()] = m.get(new Integer( curElement.getNumber())); |
| 1197 |
|
| 1198 |
} |
| 1199 |
else{ |
| 1200 |
|
| 1201 |
membership[curElement.getNumber()] = membership[treeModel.getParent(curElement).getNumber()]; |
| 1202 |
} |
| 1203 |
|
| 1204 |
} |
| 1205 |
content += " cluster = " + membership[curElement.getNumber()] ; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
for(int childNum=0; childNum < treeModel.getChildCount(curElement); childNum++){ |
| 1211 |
list.addFirst(treeModel.getChild(curElement,childNum)); |
| 1212 |
} |
| 1213 |
} |
| 1214 |
|
| 1215 |
return(membership); |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
public void accept(double deviation) { |
| 1221 |
super.accept(deviation); |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
} |
| 1241 |
|
| 1242 |
public void reject(){ |
| 1243 |
super.reject(); |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
System.out.println(" * Rejected!"); |
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
public final static String TREE_CLUSTERSEQUENTIAL_OPERATOR = "TreeClusterSequentialSampling"; |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
public final String getOperatorName() { |
| 1309 |
return TREE_CLUSTERSEQUENTIAL_OPERATOR; |
| 1310 |
} |
| 1311 |
|
| 1312 |
public final void optimize(double targetProb) { |
| 1313 |
|
| 1314 |
throw new RuntimeException("This operator cannot be optimized!"); |
| 1315 |
} |
| 1316 |
|
| 1317 |
public boolean isOptimizing() { |
| 1318 |
return false; |
| 1319 |
} |
| 1320 |
|
| 1321 |
public void setOptimizing(boolean opt) { |
| 1322 |
throw new RuntimeException("This operator cannot be optimized!"); |
| 1323 |
} |
| 1324 |
|
| 1325 |
public double getMinimumAcceptanceLevel() { |
| 1326 |
return 0.1; |
| 1327 |
} |
| 1328 |
|
| 1329 |
public double getMaximumAcceptanceLevel() { |
| 1330 |
return 0.4; |
| 1331 |
} |
| 1332 |
|
| 1333 |
public double getMinimumGoodAcceptanceLevel() { |
| 1334 |
return 0.20; |
| 1335 |
} |
| 1336 |
|
| 1337 |
public double getMaximumGoodAcceptanceLevel() { |
| 1338 |
return 0.30; |
| 1339 |
} |
| 1340 |
|
| 1341 |
public String getPerformanceSuggestion() { |
| 1342 |
if (Utils.getAcceptanceProbability(this) < getMinimumAcceptanceLevel()) { |
| 1343 |
return ""; |
| 1344 |
} else if (Utils.getAcceptanceProbability(this) > getMaximumAcceptanceLevel()) { |
| 1345 |
return ""; |
| 1346 |
} else { |
| 1347 |
return ""; |
| 1348 |
} |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 1356 |
|
| 1357 |
|
| 1358 |
public final static String VIRUSLOCATIONS = "virusLocations"; |
| 1359 |
public final static String MU = "mu"; |
| 1360 |
public final static String CLUSTERLABELS = "clusterLabels"; |
| 1361 |
public final static String K = "k"; |
| 1362 |
public final static String OFFSETS = "offsets"; |
| 1363 |
|
| 1364 |
|
| 1365 |
public final static String CLUSTER_OFFSETS = "clusterOffsetsParameter"; |
| 1366 |
|
| 1367 |
public final static String INDICATORS = "indicators"; |
| 1368 |
|
| 1369 |
public final static String EXCISION_POINTS = "excisionPoints"; |
| 1370 |
|
| 1371 |
|
| 1372 |
public String getParserName() { |
| 1373 |
return TREE_CLUSTERSEQUENTIAL_OPERATOR; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 1385 |
|
| 1386 |
|
| 1387 |
XMLObject cxo = xo.getChild(VIRUSLOCATIONS); |
| 1388 |
MatrixParameter virusLocations = (MatrixParameter) cxo.getChild(MatrixParameter.class); |
| 1389 |
|
| 1390 |
|
| 1391 |
cxo = xo.getChild(MU); |
| 1392 |
MatrixParameter mu = (MatrixParameter) cxo.getChild(MatrixParameter.class); |
| 1393 |
|
| 1394 |
cxo = xo.getChild(CLUSTERLABELS); |
| 1395 |
Parameter clusterLabels = (Parameter) cxo.getChild(Parameter.class); |
| 1396 |
|
| 1397 |
cxo = xo.getChild(K); |
| 1398 |
Parameter k = (Parameter) cxo.getChild(Parameter.class); |
| 1399 |
|
| 1400 |
cxo = xo.getChild(OFFSETS); |
| 1401 |
Parameter offsets = (Parameter) cxo.getChild(Parameter.class); |
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
Parameter clusterOffsetsParameter = null; |
| 1407 |
if (xo.hasChildNamed(CLUSTER_OFFSETS)) { |
| 1408 |
clusterOffsetsParameter = (Parameter) xo.getElementFirstChild(CLUSTER_OFFSETS); |
| 1409 |
} |
| 1410 |
|
| 1411 |
cxo = xo.getChild(INDICATORS); |
| 1412 |
Parameter indicators = (Parameter) cxo.getChild(Parameter.class); |
| 1413 |
|
| 1414 |
cxo = xo.getChild(EXCISION_POINTS); |
| 1415 |
Parameter excisionPoints = (Parameter) cxo.getChild(Parameter.class); |
| 1416 |
|
| 1417 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 1418 |
|
| 1419 |
AGLikelihoodTreeCluster agLikelihood = (AGLikelihoodTreeCluster) xo.getChild(AGLikelihoodTreeCluster.class); |
| 1420 |
|
| 1421 |
|
| 1422 |
return new TreeClusterSequentialSampling(virusLocations, mu, clusterLabels, k, weight, offsets, clusterOffsetsParameter, indicators, excisionPoints, treeModel, agLikelihood); |
| 1423 |
|
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
public String getParserDescription() { |
| 1431 |
return "An operator that picks a new allocation of an item to a cluster under the Dirichlet process."; |
| 1432 |
} |
| 1433 |
|
| 1434 |
public Class getReturnType() { |
| 1435 |
return TreeClusterSequentialSampling.class; |
| 1436 |
} |
| 1437 |
|
| 1438 |
|
| 1439 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 1440 |
return rules; |
| 1441 |
} |
| 1442 |
|
| 1443 |
private final XMLSyntaxRule[] rules = { |
| 1444 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 1445 |
|
| 1446 |
new ElementRule(VIRUSLOCATIONS, Parameter.class), |
| 1447 |
new ElementRule(MU, Parameter.class), |
| 1448 |
new ElementRule(CLUSTERLABELS, Parameter.class), |
| 1449 |
new ElementRule(K, Parameter.class), |
| 1450 |
new ElementRule(OFFSETS, Parameter.class), |
| 1451 |
|
| 1452 |
|
| 1453 |
new ElementRule(CLUSTER_OFFSETS, Parameter.class, "Parameter of cluster offsets of all virus"), |
| 1454 |
new ElementRule(INDICATORS, Parameter.class), |
| 1455 |
new ElementRule(EXCISION_POINTS, Parameter.class), |
| 1456 |
new ElementRule(TreeModel.class), |
| 1457 |
|
| 1458 |
|
| 1459 |
}; |
| 1460 |
|
| 1461 |
}; |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
public int getStepCount() { |
| 1466 |
return 1; |
| 1467 |
} |
| 1468 |
|
| 1469 |
} |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|