Debian Codegraph @

src/dr/evomodel/antigenic/phyloclustering/misc/obsolete/TreeClusterSequentialSampling.java

raw symbols SCIP
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 * A Gibbs operator for allocation of items to clusters under a distance dependent Chinese restaurant process.
21 *
22 * @author Charles Cheung
23 * @author Trevor Bedford
24 */
25
26 public class TreeClusterSequentialSampling extends SimpleMCMCOperator implements GibbsOperator{
27 //Parameter locationDrift; // no longer need to know
28 Parameter virusOffsetsParameter;
29 private double sigmaSq =1;
30 private int numdata = 0; //NEED TO UPDATE
31 //private double[] groupSize;
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 // public ClusterViruses clusterLikelihood = null;
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 // private int[] piIndicator = new int[numSites];
83
84
85 //public ClusterAlgorithmOperator(MatrixParameter virusLocations, MatrixParameter mu, Parameter clusterLabels, Parameter K, double weight, Parameter virusOffsetsParameter, Parameter locationDrift_in, Parameter clusterOffsetsParameter) {
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 // this.clusterLikelihood = clusterLikelihood;
97 this.virusLocations = virusLocations;
98 this.virusOffsetsParameter = virusOffsetsParameter;
99 // this.locationDrift = locationDrift_in; //no longer need
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 //System.out.println("i="+ i);
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 //NEED maxGROUP
133
134 //for(int i=0; i < K_int; i++){
135 //System.out.println("groupSize=" + groupSize[i]);
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 //muLabels ...
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 * change the parameter and return the log hastings ratio.
165 */
166 public final double doOperation() {
167
168 System.out.println("do operation of sequential sampling");
169
170 setMembershipToClusterLabelIndexes(); //run once in case the tree changes.
171
172 numNodes = treeModel.getNodeCount();
173
174 updateK();
175 int K_int = (int) K.getParameterValue(0);
176
177 //System.out.println("K_int is " + K_int);
178
179 int[] cutNode = new int[K_int]; //to store which nodes to add...
180
181 int[] oldclusterLabelArray = new int[numNodes]; //everything 0.
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 //Verify relationship
195 //P(H|E0=a, Y, mu) = sum P(H|E0=a, E1=e1, Y, mu) x P(E1=e1| E0=a)
196
197
198 cutNode = new int[1];
199 cutNode[0] = 785;
200 onPoints = new int[1];
201 onPoints[0] = 0;
202 //now translate the cutNodes into the breakpoints that are on [although here we don't use the indicators - elsewhere does
203 resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints);//need to reset the status breakpoints by the testCutNode
204
205
206 //use the tree to re-partition according to the change.
207 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode);
208 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
209 for(int i=0; i < numdata; i++){
210 clusterLabels.setParameterValue(i, clusterLabelArray[i]); //set cluster label parameter
211 }
212
213 //setVirusLocationAndOffsets(); //set virus locations, given the clusterlabels parameter
214 setVirusLocationAutoCorrelatedModel();
215
216 double topLogProb = clusterLikelihood.getLogLikelihood();
217 System.out.println(topLogProb);
218
219
220
221 //now test the sum...
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 //calculate the distribution for calculating introducing an excision point in each node
230 for(int curTest=0; curTest < numNodes; curTest++){
231
232 int hasBeenAdded = checkSiteHasBeenAddedToOnIndicators(curTest); //check if a site has already been added
233 if(hasBeenAdded ==0){
234
235 cutNode = new int[2];
236 cutNode[0] = 785;
237 cutNode[1] = curTest;
238
239 resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints);//need to reset the status breakpoints by the testCutNode
240 //use the tree to re-partition according to the change.
241 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode); //note that instead of using the indicators, it uses the testCutNodes directly
242 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
243
244 //set cluster label parameter for testing
245 for(int i=0; i < numdata; i++){
246 clusterLabels.setParameterValue(i, clusterLabelArray[i]);
247 }
248
249 //setVirusLocationAndOffsets(); //this uses the clusterLabels parameter
250 setVirusLocationAutoCorrelatedModel(); //which depends on the status and breakpoints
251
252
253 logNumerator[curTest] += clusterLikelihood.getLogLikelihood() ; //Calculate likelihood
254 }
255 else{
256 logNumerator[curTest] = Double.NEGATIVE_INFINITY;
257 System.out.println("Don't calculate for node" + cutNode[0]);
258 }
259
260 } //finished curTest
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 //switch
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 //cutNode[7] = 521; //although 526 will be better than 521
308 cutNode[7] = 638;
309
310
311
312 //calculate the conditional distribution of the curNode, given the current set of nodes
313 double []logNumeratorProb = new double[numNodes];
314
315 //calculate the distribution for calculating introducing an excision point in each node
316 for(int curTest=0; curTest < numNodes; curTest++){
317
318 int hasBeenAdded = checkSiteHasBeenAddedToOnIndicators(curTest); //check if a site has already been added
319 if(hasBeenAdded ==0){
320 int[] testCutNode = new int[curNode+1]; //create the testCutNode, with adding the current test node
321 for(int i=0; i < curNode; i++){
322 testCutNode[i] = cutNode[i];
323 }
324 testCutNode[curNode] = curTest;
325
326 resetStatusAndBreakpointsGivenCutNodes(testCutNode, onPoints);//need to reset the status breakpoints by the testCutNode
327
328
329 /*
330 System.out.print("Currently selected: [");
331 for(int i=0; i < binSize; i++){
332 if((int) status.getParameterValue(i) ==1){
333 System.out.print( (int) breakPoints.getParameterValue(i) + ",");
334 }
335 }
336 System.out.println("]");
337 */
338 //I suspect I need to change this as I modify the code..
339 //set the indicators, based on the cutnodes
340
341 /*
342 int addCount=0;
343 for(int i=0; i < binSize; i++){
344 if( (int)status.getParameterValue(i) == 1){
345 breakPoints.setParameterValue(i, testCutNode[addCount]);
346 addCount++;
347 }
348 if(addCount == (curNode+1)){
349 break;
350 }
351 }
352 */
353 //System.out.println("currently added " + addCount + " nodes");
354
355
356
357 //use the tree to re-partition according to the change.
358 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(testCutNode); //note that instead of using the indicators, it uses the testCutNodes directly
359 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
360
361 //set cluster label parameter for testing
362 for(int i=0; i < numdata; i++){
363 clusterLabels.setParameterValue(i, clusterLabelArray[i]);
364 }
365
366
367 //setVirusLocationAndOffsets(); //this uses the clusterLabels parameter
368 setVirusLocationAutoCorrelatedModel(); //which depends on the status and breakpoints
369
370
371 if(curNode == 0 && curTest == 0){
372 for(int i=0; i < numdata; i++){
373 Parameter v = virusLocations.getParameter(i);
374 //v.setParameterValue(0, 0);
375 //v.setParameterValue(1, 0);
376 }
377 }
378
379 logNumeratorProb[curTest] = clusterLikelihood.getLogLikelihood(); //Calculate likelihood
380
381 //if(curNode == 0 && curTest == 0){
382
383
384 //for(int i=0; i < numdata; i++){
385 // Parameter v = virusLocations.getParameter(i);
386 // System.out.print(v.getParameterValue(0) +"," + v.getParameterValue(1)+"\t");
387 //}
388 //System.out.println("");
389
390 //System.out.println(" * " + logNumeratorProb[curTest]);
391 //System.exit(0);
392 //}
393 }
394 else{
395 logNumeratorProb[curTest] = Double.NEGATIVE_INFINITY; //dummy probability
396 }
397
398 } //finished curTest
399
400 double []condDistribution = calculateConditionalProbabilityGivenLogNumeratorProb(logNumeratorProb);
401
402
403 for(int i=0; i < numNodes; i++){
404 // if(condDistribution[i] > 0.0000001){
405 System.out.println("node " + i + " p=" + condDistribution[i]);
406 // }
407 }
408 System.out.println("===============================");
409
410
411 // System.exit(0);
412
413 int site_add = MathUtils.randomChoicePDF(condDistribution); //sample a site, given the conditioanl distribution
414
415 //update the cutNode using a temporary array newCutNode - first copy the existing element, then add the new site
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; //add the new site.
421 cutNode = newCutNode;
422
423
424 //now , after adding the node to cutNode, we need to update clusterLabel such that the labeling is consistent with the old cluster labels..
425 // because ie. cluster i always get mu i.
426 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(newCutNode);
427 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
428
429 oldclusterLabelArray = clusterLabelArray; // keep the oldcluster label to build on top of it..
430 } //curNode
431
432
433
434
435 //====================================================================================================
436 //After finishing the proposal
437 //====================================================================================================
438
439 //Display:
440 printCutNode(cutNode);
441
442 //now translate the cutNodes into the breakpoints that are on [although here we don't use the indicators - elsewhere does
443 resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints);//need to reset the status breakpoints by the testCutNode
444 /*
445 int addCount=0;
446 for(int i=0; i < binSize; i++){
447 if( (int)status.getParameterValue(i) == 1){
448 breakPoints.setParameterValue(i, cutNode[addCount]);
449 addCount++;
450 }
451 }
452 */
453
454
455 //use the tree to re-partition according to the change.
456 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode);
457 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
458 for(int i=0; i < numdata; i++){
459 clusterLabels.setParameterValue(i, clusterLabelArray[i]); //set cluster label parameter
460 }
461
462 //setVirusLocationAndOffsets(); //set virus locations, given the clusterlabels parameter
463 setVirusLocationAutoCorrelatedModel();
464
465
466
467 System.out.println(clusterLikelihood.getLogLikelihood());
468
469
470
471
472
473
474
475
476 //add manually to test...
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 //cutNode[7] = 521;
485 //cutNode[8] = 638;
486
487 cutNode[7] = 638;
488 cutNode[8] = 521;
489
490 resetStatusAndBreakpointsGivenCutNodes(cutNode, onPoints);//need to reset the status breakpoints by the testCutNode
491 //use the tree to re-partition according to the change.
492 clusterLabelArray = setClusterLabelsByTestCutNodeByNodeOrder(cutNode);
493 relabelClusterLabels(clusterLabelArray, oldclusterLabelArray); //will move it out
494 for(int i=0; i < numdata; i++){
495 clusterLabels.setParameterValue(i, clusterLabelArray[i]); //set cluster label parameter
496 }
497
498 //setVirusLocationAndOffsets(); //set virus locations, given the clusterlabels parameter
499 setVirusLocationAutoCorrelatedModel();
500
501 System.out.println(clusterLikelihood.getLogLikelihood());
502 System.exit(0);
503
504
505
506
507 //NEED TO SET THE OTHER BREAKPOINTS TO MAKE SURE THERE ARE NO DUPLICATES AT THE END...
508 //SO OTHER PROPOSALS WOULD FUNCTION OK OK
509
510
511
512 return(Double.POSITIVE_INFINITY); //it should be anything... always accept for the Gibbs move.
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]); //reset breakPoints accordingly
534 countOn++;
535 }
536
537 }
538 }
539
540
541
542 private void updateK() {
543
544 //K is changed accordingly..
545 int K_count = 0; //K_int gets updated
546 for(int i=0; i < binSize; i++){
547 K_count += (int) status.getParameterValue(i);
548 }
549 //System.out.println("K now becomes " + K_count);
550 K.setParameterValue(0, K_count); //update
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 //System.out.println("condProb of site " + i + " = " + condProb[i]);
590 sumProb +=condProb[i];
591 if(condProb[i] > 0.01){
592 // System.out.println("**site " + i + " with prob=" + condProb[i] + " steps from previous=" + numStepsFromOrigin[i]);
593 }
594 }
595 return(condProb);
596 }
597
598
599
600 //Expect the ratio to be 1.
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 //change the mu in the toBin and fromBIn
652 //borrow from getLogLikelihood:
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 // System.out.print("virus Offeset Parameter present"+ ": ");
661 // System.out.print( virusOffsetsParameter.getParameterValue(i) + " ");
662 // System.out.print(" drift= " + drift + " ");
663 year = virusOffsetsParameter.getParameterValue(i); //just want year[i]
664 //make sure that it is equivalent to double offset = year[virusIndex] - firstYear;
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 //System.out.println(meanYear[i]);
679 }
680
681
682 mu0_offset = new double[binSize];
683 //double[] mu1 = new double[maxLabel];
684
685
686 //System.out.println("maxLabel=" + maxLabel);
687 //now, change the mu..
688 for(int i=0; i < binSize; i++){
689 //System.out.println(meanYear[i]*beta);
690 mu0_offset[i] = meanYear[i];
691 //System.out.println("group " + i + "\t" + mu0_offset[i]);
692 }
693 // System.out.println("=====================");
694
695
696 //Set the vLoc to be the corresponding mu values , and clusterOffsetsParameter to be the corresponding offsets
697 //virus in the same cluster has the same position
698 for(int i=0; i < numdata; i++){
699 int label = (int) clusterLabels.getParameterValue(i);
700 Parameter vLoc = virusLocations.getParameter(i);
701 //setting the virus locs to be equal to the corresponding mu
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 //System.out.println("vloc="+ muValue + "," + muValue2);
707 }
708
709 for(int i=0; i < numdata; i++){
710 int label = (int) clusterLabels.getParameterValue(i);
711 //if we want to apply the mean year virus cluster offset to the cluster
712 if(clusterOffsetsParameter != null){
713 //setting the clusterOffsets to be equal to the mean year of the virus cluster
714 // by doing this, the virus changes cluster AND updates the offset simultaneously
715 clusterOffsetsParameter.setParameterValue( i , mu0_offset[label]);
716 }
717 // System.out.println("mu0_offset[label]=" + mu0_offset[label]);
718 // System.out.println("clusterOffsets " + i +" now becomes =" + clusterOffsetsParameter.getParameterValue(i) );
719 }
720
721
722
723
724 // System.out.println("===The on nodes===");
725 // for(int i=0; i < binSize; i++){
726 // if((int) excisionPoints.getParameterValue(i) == 1){
727 // System.out.println("Cluster node " + i + " = " + (int) indicators.getParameterValue(i) + "\tstatus=" + (int) excisionPoints.getParameterValue(i));
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 //new - Trevor's autocorrelated model.
742 // System.out.println("Autocorrelated tree model");
743
744 //given mu, excision points, and which ones are on...
745
746
747 int[] nodeStatus = new int[numNodes];
748 for(int i=0; i < numNodes; i ++){
749 nodeStatus[i] = -1;
750 }
751 //convert to easy process format.
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 //Testing:
760 //muValue[0] = 1;
761 //muValue2[0] = 1.5;
762 //nodeStatus[696] = 0;
763 //muValue[1] = 10;
764 //muValue2[1] = 20;
765 //nodeStatus[607] = 1;
766 //muValue[2] = 200;
767 //muValue2[2] = 300;
768
769
770 //process the tree and get the vLoc of the viruses..
771 //breadth first depth first..
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 //assign value to the current node...
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 //System.out.println("Run new location");
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 //add all the children to the queue
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(); //now that we have finished visiting this node, pops it out of the queue
809
810 if(visitlist.size() > 0){
811 cNode = visitlist.getFirst(); //set the new first node in the queue to visit
812 }
813
814
815 }
816
817 //write the virus locations
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 //for(int i=0; i < numdata; i++){
826 //Parameter vLocP= virusLocations.getParameter(i);
827 //System.out.println("virus " + vLocP.getId() + "\t" + vLocP.getParameterValue(0) + "," + vLocP.getParameterValue(1) );
828 //}
829
830
831
832 //System.out.println("Processed " + countProcessed + " nodes");
833
834 //System.out.println("Done");
835
836 //System.exit(0);
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 ]; //an overkill - basically just need the max label in the old cluster
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); // the time consuming step here.
880
881 //The assumption that the first nodes being external node corresponding to the cluster labels IS FALSE
882 //so I have to search for the matching indexes
883 // for(int i=0; i < numdata; i++){
884 // clusterLabels.setParameterValue( i, membership[membershipToClusterLabelIndexes[i]]);
885 //}
886
887 //to speed up the code
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 //I suspect this is an expensive operation, so I don't want to do it many times,
902 //which is also unnecessary - MAY have to update whenever a different tree is used.
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 // System.out.println(curName);
908 int isFound = 0;
909 for(int j=0; j < numNodes; j++){
910 String treeId = treeModel.getTaxonId(j);
911 if(curName.equals(treeId) ){
912 // System.out.println(" isFound at j=" + j);
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 //private void setClusterLabelsByTestCutNode(int[] testCutNode) {
926 private int[] setClusterLabelsByTestCutNode(int[] testCutNode) {
927
928 int []membership = determine_membership(treeModel, testCutNode, testCutNode.length); // the time consuming step here.
929
930 //The assumption that the first nodes being external node corresponding to the cluster labels IS FALSE
931 //so I have to search for the matching indexes
932 // for(int i=0; i < numdata; i++){
933 // clusterLabels.setParameterValue( i, membership[membershipToClusterLabelIndexes[i]]);
934 //}
935
936 //to speed up the code
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 //This function uses the breakPoints, but the doOperation doesn't use this anymore..
951 //instead, it uses the cutNodes explicitly.
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 // System.out.println(content);
967
968 if(cutNum != K_int){
969 System.out.println("cutNum != K_int. we got a problem");
970 }
971
972 // for(int i=0; i < K_int; i++){
973 // System.out.println(cutNodes[i]);
974 // }
975
976 //int []membership = determine_membership(treeModel, cutNodes, K_int-1);
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 // System.out.println(" sum = " + uniqueCode);
984
985 // System.out.println("number of nodes = " + treeModel.getNodeCount());
986 // for(int i=0; i < treeModel.getNodeCount(); i++){
987 // System.out.println(membership[i]);
988 // }
989
990
991 //System.out.println("Done");
992
993 // for(int i=0; i < numdata; i++){
994 // Parameter v = virusLocations.getParameter(i);
995 // String curName = v.getParameterName();
996 // System.out.println("i=" + i + " = " + curName);
997 // }
998
999 // for(int j=0; j < numdata; j++){
1000 // System.out.println("j=" + j + " = " + treeModel.getTaxonId(j));
1001 // }
1002
1003
1004 // Parameter vv = virusLocations.getParameter(0);
1005 // String curNamev = vv.getParameterName();
1006
1007 // System.out.println(curNamev + " and " +treeModel.getTaxonId(392) );
1008 //System.out.println( curNamev.equals(treeModel.getTaxonId(392) ) );
1009
1010
1011 //System.exit(0);
1012
1013 // System.out.println("numNodes=" + numNodes);
1014 // System.exit(0);
1015 //create dictionary:
1016
1017 //I suspect this is an expensive operation, so I don't want to do it many times,
1018 //which is also unnecessary - MAY have to update whenever a different tree is used.
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 // System.out.println(curName);
1024 int isFound = 0;
1025 for(int j=0; j < numNodes; j++){
1026 String treeId = treeModel.getTaxonId(j);
1027 if(curName.equals(treeId) ){
1028 // System.out.println(" isFound at j=" + j);
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 // System.exit(0);
1043
1044 // for(int i=0; i < numdata; i++){
1045 // System.out.println(membershipToClusterLabelIndexes[i]);
1046 // }
1047 // System.exit(0);
1048
1049 for(int i=0; i < numdata; i++){
1050 //The assumption that the first nodes being external node corresponding to the cluster labels IS FALSE
1051 //so I have to search for the matching indexes
1052 Parameter vloc = virusLocations.getParameter(i);
1053
1054
1055 //must uncomment out because this sets the new partitioning ... now i am doing code testing.
1056 clusterLabels.setParameterValue( i, membership[membershipToClusterLabelIndexes[i]]);
1057 //System.out.println(vloc.getParameterName() + " i="+ i + " membership=" + (int) clusterLabels.getParameterValue(i));
1058
1059 // Parameter v = virusLocations.getParameter(i);
1060 // System.out.println(v.getParameterName());
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 //traverse down the tree, top down, do calculation
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; //root always given the first cluster
1097
1098 while(!list.isEmpty()){
1099 //do things with the current object
1100 NodeRef curElement = list.pop();
1101 //String content = "node #" + curElement.getNumber() +", taxon=" + treeModel.getNodeTaxon(curElement) + " and parent is = " ;
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 //content += treeModel.getTaxonIndex(treeModel.getNodeTaxon(curElement)) + "\t";
1109 }
1110
1111 if(treeModel.getParent(curElement)== null){
1112 //content += "no parent";
1113 }
1114 else{
1115 //content += "parent node#=" + treeModel.getParent(curElement).getNumber();
1116 }
1117
1118 //cluster assignment:
1119 if(!treeModel.isRoot(curElement)){
1120 if(isCutNode(curElement.getNumber(), cutNodes, numCuts)){
1121 //if(isCutNode(curElement.getNumber())){
1122 numClusters++ ;
1123 membership[ curElement.getNumber() ] = numClusters - 1;
1124 }
1125 else{
1126 //inherit from parent's cluster assignment
1127 membership[curElement.getNumber()] = membership[treeModel.getParent(curElement).getNumber()];
1128 }
1129
1130 }//is not Root
1131 content += " cluster = " + membership[curElement.getNumber()] ;
1132
1133 // System.out.println(content);
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 //traverse down the tree, top down, do calculation
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 // System.out.println(cutNodes[i] + "\t" + (i+1) );
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; //root always given the first cluster
1168
1169 while(!list.isEmpty()){
1170 //do things with the current object
1171 NodeRef curElement = list.pop();
1172 //String content = "node #" + curElement.getNumber() +", taxon=" + treeModel.getNodeTaxon(curElement) + " and parent is = " ;
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 //content += treeModel.getTaxonIndex(treeModel.getNodeTaxon(curElement)) + "\t";
1180 }
1181
1182 if(treeModel.getParent(curElement)== null){
1183 //content += "no parent";
1184 }
1185 else{
1186 //content += "parent node#=" + treeModel.getParent(curElement).getNumber();
1187 }
1188
1189 //cluster assignment:
1190 if(!treeModel.isRoot(curElement)){
1191 if(isCutNode(curElement.getNumber(), cutNodes, numCuts)){
1192 //if(isCutNode(curElement.getNumber())){
1193 //numClusters++ ;
1194 //membership[ curElement.getNumber() ] = numClusters - 1;
1195 // System.out.println("get: curElement" + curElement.getNumber() + "\t" + m.get(new Integer( curElement.getNumber())));
1196 membership[ curElement.getNumber()] = m.get(new Integer( curElement.getNumber()));
1197
1198 }
1199 else{
1200 //inherit from parent's cluster assignment
1201 membership[curElement.getNumber()] = membership[treeModel.getParent(curElement).getNumber()];
1202 }
1203
1204 }//is not Root
1205 content += " cluster = " + membership[curElement.getNumber()] ;
1206
1207 // System.out.println(content);
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 if(isMoveMu==1){
1225 numAcceptMoveMu++;
1226 numProposeMoveMu++;
1227 System.out.println("% accept move Mu = " + numAcceptMoveMu/(double)numProposeMoveMu);
1228 }
1229 else{
1230 numAcceptMoveC++;
1231 numProposeMoveC++;
1232 System.out.println("% accept move C = " + numAcceptMoveC/(double)numProposeMoveC);
1233 }
1234 */
1235
1236 // if(virusIndexChange <5){
1237 // System.out.println(" - Accepted!");
1238 // }
1239
1240 }
1241
1242 public void reject(){
1243 super.reject();
1244
1245
1246 /*
1247 //manually change mu back..
1248 if(isMoveMu==1){
1249 mu.getParameter(groupSelectedChange).setParameterValue(dimSelectChange, originalValueChange);
1250 }
1251 //manually change all the affected vLoc back...
1252 for(int i=0; i < numdata; i++){
1253 int label = (int) clusterLabels.getParameterValue(i);
1254 Parameter vLoc = virusLocations.getParameter(i);
1255 // double muValue = mu.getParameter(label).getParameterValue(0);
1256 // vLoc.setParameterValue(0, muValue);
1257 // double muValue2 = mu.getParameter(label).getParameterValue(1);
1258 // vLoc.setParameterValue(1, muValue2);
1259
1260 clusterOffsetsParameter.setParameterValue( i , mu0_offset[label]);
1261 }
1262 */
1263
1264
1265 /*
1266 if(isMoveMu==1){
1267 numProposeMoveMu++;
1268 System.out.println("% accept move Mu = " + numAcceptMoveMu/(double)numProposeMoveMu);
1269 }
1270 else{
1271 numProposeMoveC++;
1272 System.out.println("% accept move C = " + numAcceptMoveC/(double)numProposeMoveC);
1273 }
1274 */
1275 //if(virusIndexChange < 5){
1276 System.out.println(" * Rejected!");
1277 //}
1278
1279
1280 /*
1281 for(int i=0; i < numdata; i++){
1282 Parameter vLoc = virusLocations.getParameter(i);
1283
1284 if( vLoc.getParameterValue(0) != old_vLoc0[i]){
1285
1286 System.out.println("virus " + i + " is different: " + vLoc.getParameterValue(0) + " and " + old_vLoc0[i]);
1287 }
1288
1289 //System.out.println(old_vLoc0[i] + ", " + old_vLoc1[i]);
1290 vLoc.setParameterValue(0, old_vLoc0[i]);
1291 vLoc.setParameterValue(1, old_vLoc1[i]);
1292
1293 }
1294 */
1295 //System.exit(0);
1296
1297
1298
1299
1300 }
1301
1302
1303
1304 public final static String TREE_CLUSTERSEQUENTIAL_OPERATOR = "TreeClusterSequentialSampling";
1305
1306
1307 //MCMCOperator INTERFACE
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 // public final static String LOCATION_DRIFT = "locationDrift"; //no longer need
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 /* (non-Javadoc)
1377 * @see dr.xml.AbstractXMLObjectParser#parseXMLObject(dr.xml.XMLObject)
1378 */
1379 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
1380
1381 //System.out.println("Parser run. Exit now");
1382 //System.exit(0);
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 // cxo = xo.getChild(LOCATION_DRIFT);
1404 // Parameter locationDrift = (Parameter) cxo.getChild(Parameter.class);
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 //return new ClusterAlgorithmOperator(virusLocations, mu, clusterLabels, k, weight, offsets, locationDrift, clusterOffsetsParameter);
1422 return new TreeClusterSequentialSampling(virusLocations, mu, clusterLabels, k, weight, offsets, clusterOffsetsParameter, indicators, excisionPoints, treeModel, agLikelihood);
1423
1424 }
1425
1426 //************************************************************************
1427 // AbstractXMLObjectParser implementation
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 // new ElementRule(LOCATION_DRIFT, Parameter.class), //no longer needed
1452 //
1453 new ElementRule(CLUSTER_OFFSETS, Parameter.class, "Parameter of cluster offsets of all virus"), // no longer REQUIRED
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