Debian Codegraph @

src/dr/evomodel/antigenic/DistanceDependentCRPGibbsOperator.java

raw symbols SCIP
1 /*
2 * DistanceDependentCRPGibbsOperator.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evomodel.antigenic;
27
28 import java.util.logging.Logger;
29
30 import dr.inference.model.Likelihood;
31 import dr.inference.model.Parameter;
32 import dr.inference.operators.GibbsOperator;
33 import dr.inference.operators.MCMCOperator;
34 import dr.inference.operators.SimpleMCMCOperator;
35 import dr.math.MathUtils;
36 import dr.xml.*;
37
38
39 /**
40 * A Gibbs operator for allocation of items to clusters under a distance dependent Chinese restaurant process.
41 *
42 * @author Gabriela Cybis
43 * @author Marc Suchard
44 */
45
46 public class DistanceDependentCRPGibbsOperator extends SimpleMCMCOperator implements GibbsOperator {
47
48
49
50 public final static String DDCRP_GIBBS_OPERATOR = "distanceDependentCRPGibbsOperator";
51
52
53 private final Parameter chiParameter;
54 private final double[][] depMatrix;
55 public NPAntigenicLikelihood modelLikelihood;
56 private Parameter links = null;
57 private Parameter assignments = null;
58 // double[][] x;
59 double k0;
60 double v0;
61 double[] m;
62 double[][] T0Inv;
63 double logDetT0;
64
65
66 public DistanceDependentCRPGibbsOperator(Parameter links, Parameter assignments,
67 Parameter chiParameter,
68 NPAntigenicLikelihood Likelihood,
69 double weight) {
70
71 this.links = links;
72 this.assignments = assignments;
73 this.modelLikelihood = Likelihood;
74 this.chiParameter = chiParameter;
75 this.depMatrix = Likelihood.getLogDepMatrix();
76
77 for (int i=0;i<links.getDimension();i++){
78 links.setParameterValue(i, i);
79 }
80
81
82 setWeight(weight);
83
84 // double[][] x=modelLikelihood.getData();
85 // modelLikelihood.printInformtion(x[0][0]);
86
87 this.m = new double[2];
88 m[0]= modelLikelihood.priorMean.getParameterValue(0);
89 m[1]= modelLikelihood.priorMean.getParameterValue(1);
90
91
92 this.v0 = 2;
93
94 this.k0= modelLikelihood.priorPrec.getParameterValue(0)/modelLikelihood.clusterPrec.getParameterValue(0);
95
96
97 this.T0Inv= new double[2][2];
98 T0Inv[0][0]= v0/modelLikelihood.clusterPrec.getParameterValue(0);
99 T0Inv[1][1]= v0/modelLikelihood.clusterPrec.getParameterValue(0);
100 T0Inv[1][0]= 0.0;
101 T0Inv[0][1]= 0.0;
102
103
104 this.logDetT0= -Math.log(T0Inv[0][0]*T0Inv[1][1]);
105
106
107
108
109
110 }
111
112
113
114 /**
115 * @return the parameter this operator acts on.
116 */
117 public Parameter getParameter() {
118 return (Parameter) links;
119 }
120
121 /**
122 * @return the Variable this operator acts on.
123
124 public Variable getVariable() {
125 return clusteringParameter;
126 }
127 */
128 /**
129 * change the parameter and return the hastings ratio.
130 */
131 public final double doOperation() {
132
133
134 int index = MathUtils.nextInt(links.getDimension());
135
136 int oldGroup = (int)assignments.getParameterValue(index);
137
138 /*
139 * Set index customer link to index and all connected to it to a new assignment (min value empty)
140 */
141 int minEmp = minEmpty(modelLikelihood.getLogLikelihoodsVector());
142 links.setParameterValue(index, index);
143 int[] visited = connected(index, links);
144
145 int ii = 0;
146 while (visited[ii]!=0){
147 assignments.setParameterValue(visited[ii]-1, minEmp);
148 ii++;
149 }
150
151
152
153
154
155 /*
156 * Adjust likvector for group separated
157 */
158
159
160 modelLikelihood.setLogLikelihoodsVector(oldGroup,modelLikelihood.getLogLikGroup(oldGroup) );
161
162 modelLikelihood.setLogLikelihoodsVector(minEmp,modelLikelihood.getLogLikGroup(minEmp) );
163
164
165 int maxFull = maxFull( modelLikelihood.getLogLikelihoodsVector());
166
167 double[] liks = modelLikelihood.getLogLikelihoodsVector();
168 /*
169 * computing likelihoods of joint groups
170 */
171
172 double[] crossedLiks = new double[maxFull+1];
173
174 for (int ll=0;ll<maxFull+1;ll++ ){
175 if (ll!=minEmp){
176 crossedLiks[ll]=getLogLik2Group(ll,minEmp);
177 }
178 }
179
180
181 /*
182 * Add logPrior
183 */
184 double[] logP = new double[links.getDimension()];
185
186 for (int jj=0; jj<links.getDimension(); jj++){
187 logP[jj] += depMatrix[index][jj];
188
189 int n = (int)assignments.getParameterValue(jj);
190 if (n!= minEmp){
191 logP[jj]+=crossedLiks[n] - liks[n] - liks[minEmp];
192 }
193 }
194
195 logP[index]= Math.log(chiParameter.getParameterValue(0));
196
197
198 /*
199 * possibilidade de mandar p zero as probs muito pequenas
200 */
201
202
203
204 /*
205 * Gibbs sampling
206 */
207
208
209 this.rescale(logP); // Improve numerical stability
210 this.exp(logP); // Transform back to probability-scale
211
212 int k = MathUtils.randomChoicePDF(logP);
213
214 links.setParameterValue(index, k);
215
216 int newGroup = (int)assignments.getParameterValue(k);
217 ii = 0;
218 while (visited[ii]!=0){
219 assignments.setParameterValue(visited[ii]-1, newGroup);
220 ii++;
221 }
222
223
224
225 /*
226 * updating conditional likelihood vector
227 */
228 modelLikelihood.setLogLikelihoodsVector(newGroup, modelLikelihood.getLogLikGroup(newGroup));
229 if (newGroup!=minEmp){
230 modelLikelihood.setLogLikelihoodsVector(minEmp, 0);
231
232 }
233
234 sampleMeans(maxFull);
235
236 return 0.0;
237
238 }
239
240
241
242
243
244
245 /*
246 * find min Empty
247 */
248
249 public int minEmpty(double[] logLikVector){
250 int isEmpty=0;
251 int i =0;
252 while (isEmpty==0){
253 if(logLikVector[i]==0){
254 isEmpty=1;}
255 else {
256 if(i==logLikVector.length-1){isEmpty=1;}
257 i++;}
258 }
259 return i;
260 }
261
262
263
264 /*
265 * find max Full
266 */
267
268
269 public int maxFull(double[] logLikVector){
270 int isEmpty=1;
271 int i =logLikVector.length-1;
272 while (isEmpty==1){
273 if(logLikVector[i]!=0){
274 isEmpty=0;}
275 else {i--;}
276 }
277 return i;
278 }
279 /*
280 * find customers connected to i
281 */
282
283 public int[] connected(int i, Parameter clusteringParameter){
284 int n = clusteringParameter.getDimension();
285 int[] visited = new int[n+1];
286 visited[0]=i+1;
287 int tv=1;
288
289 for(int j=0;j<n;j++){
290 if(visited[j]!=0){
291 int curr = visited[j]-1;
292
293 /*look forward
294 */
295
296 int forward = (int) clusteringParameter.getParameterValue(curr);
297 visited[tv] = forward+1;
298 tv++;
299 // Check to see if is isn't already on the list
300
301 for(int ii=0; ii<tv-1; ii++){
302 if(visited[ii]==forward+1){
303 tv--;
304 visited[tv]=0;
305 }
306 }
307
308
309 /*look back
310 */
311 for (int jj=0; jj<n;jj++){
312 if((int)clusteringParameter.getParameterValue(jj)==curr){
313 visited[tv]= jj+1;
314 tv++;
315
316 for(int ii=0; ii<tv-1; ii++){
317 if(visited[ii]==jj+1){
318 tv--;
319 visited[tv]=0;
320 }
321 }
322
323 }
324 }
325
326 }}
327 return visited;
328
329 }
330
331
332
333
334 private void printInformtion(Parameter par) {
335 StringBuffer sb = new StringBuffer("parameter \n");
336 for(int j=0; j<par.getDimension(); j++){
337 sb.append(par.getParameterValue(j));
338 }
339
340 Logger.getLogger("dr.evomodel").info(sb.toString()); };
341
342
343
344
345
346
347 /* OLD
348
349 public double getLogLikGroup(int groupNumber){
350 double L =0.0;
351
352
353 int ngroup=0;
354 for (int i=0;i<assignments.getDimension(); i++){
355 if((int) assignments.getParameterValue(i) == groupNumber){
356 ngroup++;}}
357
358
359 if (ngroup != 0){
360 double[] group = new double[2*ngroup];
361
362 int count = 0;
363 for (int i=0;i<assignments.getDimension(); i++){
364 if((int) assignments.getParameterValue(i) == groupNumber){
365 group[count] = modelLikelihood.getData()[i][0];
366 group[ngroup+count] = modelLikelihood.getData()[i][1];
367 count+=1;}}
368
369
370 double[][] var = new double[2*ngroup][2*ngroup];
371 double[] mean = new double[2*ngroup];
372
373 double m0 = modelLikelihood.getPriorMean().getParameterValue(0);
374 double m1 = modelLikelihood.getPriorMean().getParameterValue(1);
375 double vp = modelLikelihood.getPriorPrec().getParameterValue(0);
376 double vc = modelLikelihood.getClusterPrec().getParameterValue(0);
377
378
379 for (int i=0; i<ngroup; i++){
380 mean[i]=m0;
381 mean[ngroup+i]=m1;
382
383
384 for (int l=0;l<ngroup;l++){
385 var[i][ngroup+l]=0;
386 var[ngroup+i][l]=0;
387
388 if (l==i){var[i][l]= vp+ vc;
389 var[ngroup+i][ngroup+l]= vp+ vc;}
390
391 else { var[i][l] = vp;
392 var[ngroup+i][ngroup+l]= vp;}
393 }
394 }
395
396
397
398
399 double[][] precision = new SymmetricMatrix(var).inverse().toComponents();
400 L = new MultivariateNormalDistribution(mean, precision).logPdf(group);
401
402 }
403
404
405
406 return L;
407
408 }
409
410
411 */
412
413 public double getLogLik2Group(int group1, int group2){
414 throw new UnsupportedOperationException("This method has been commented out because of build errors");
415
416 // double L =0.0;
417 //
418 //
419 // int ngroup1=0;
420 // for (int i=0;i<assignments.getDimension(); i++){
421 // if((int) assignments.getParameterValue(i) == group1 ){
422 // ngroup1++;}}
423 //
424 // int ngroup2=0;
425 // for (int i=0;i<assignments.getDimension(); i++){
426 // if((int) assignments.getParameterValue(i) == group2 ){
427 // ngroup2++;}}
428 //
429 // int ngroup = (ngroup1+ngroup2);
430 //
431 // if (ngroup != 0){
432 // double[][] group = new double[ngroup][2];
433 //
434 // double mean[]=new double[2];
435 //
436 //
437 // int count = 0;
438 // for (int i=0;i<assignments.getDimension(); i++){
439 // if((int) assignments.getParameterValue(i) == group1 ){
440 // group[count][0] = modelLikelihood.getData()[i][0];
441 // group[count][1] = modelLikelihood.getData()[i][1];
442 // mean[0]+=group[count][0];
443 // mean[1]+=group[count][1];
444 // count+=1;}}
445 //
446 // for (int i=0;i<assignments.getDimension(); i++){
447 // if((int) assignments.getParameterValue(i) == group2 ){
448 // group[count][0] = modelLikelihood.getData()[i][0];
449 // group[count][1] = modelLikelihood.getData()[i][1];
450 // mean[0]+=group[count][0];
451 // mean[1]+=group[count][1];
452 // count+=1;}}
453 //
454 //
455 //
456 // mean[0]/=ngroup;
457 // mean[1]/=ngroup;
458 //
459 //
460 //
461 // double kn= k0+ngroup;
462 // double vn= v0+ngroup;
463 //
464 //
465 // double[][] sumdif=new double[2][2];
466 //
467 // for(int i=0;i<ngroup;i++){
468 // sumdif[0][0]+= (group[i][0]-mean[0])*(group[i][0]-mean[0]);
469 // sumdif[0][1]+= (group[i][0]-mean[0])*(group[i][1]-mean[1]);
470 // sumdif[1][0]+= (group[i][0]-mean[0])*(group[i][1]-mean[1]);
471 // sumdif[1][1]+= (group[i][1]-mean[1])*(group[i][1]-mean[1]);
472 // }
473 //
474 //
475 //
476 // double[][] TnInv = new double[2][2];
477 // TnInv[0][0]=T0Inv[0][0]+ngroup*(k0/kn)*(mean[0]-m[0])*(mean[0]-m[0])+sumdif[0][0];
478 // TnInv[0][1]=T0Inv[0][1]+ngroup*(k0/kn)*(mean[1]-m[1])*(mean[0]-m[0])+sumdif[0][1];
479 // TnInv[1][0]=T0Inv[1][0]+ngroup*(k0/kn)* (mean[0]-m[0])*(mean[1]-m[1])+sumdif[1][0];
480 // TnInv[1][1]=T0Inv[1][1]+ngroup*(k0/kn)* (mean[1]-m[1])*(mean[1]-m[1])+sumdif[1][1];
481 //
482 //
483 // double logDetTn=-Math.log(TnInv[0][0]*TnInv[1][1]-TnInv[0][1]*TnInv[1][0]);
484 //
485 //
486 // L+= -(ngroup)*Math.log(Math.PI);
487 // L+= Math.log(k0) - Math.log(kn);
488 // L+= (vn/2)*logDetTn - (v0/2)*logDetT0;
489 // L+= GammaFunction.lnGamma(vn/2)+ GammaFunction.lnGamma((vn/2)-0.5);
490 // L+=-GammaFunction.lnGamma(v0/2)- GammaFunction.lnGamma((v0/2)-0.5);
491 //
492 //
493 //
494 //
495 //
496 //
497 //
498 //
499 // }
500 //
501 // return L;
502
503 }
504
505
506
507 /*public double getLogLik2Group(int group1, int group2){
508 double L =0.0;
509
510
511 int ngroup1=0;
512 for (int i=0;i<assignments.getDimension(); i++){
513 if((int) assignments.getParameterValue(i) == group1 ){
514 ngroup1++;}}
515
516 int ngroup2=0;
517 for (int i=0;i<assignments.getDimension(); i++){
518 if((int) assignments.getParameterValue(i) == group2 ){
519 ngroup2++;}}
520
521 int ngroup = (ngroup1+ngroup2);
522
523 if (ngroup != 0){
524 double[] group = new double[2*ngroup];
525
526 int count = 0;
527 for (int i=0;i<assignments.getDimension(); i++){
528 if((int) assignments.getParameterValue(i) == group1 ){
529 group[count] = modelLikelihood.getData()[i][0];
530 group[count+ngroup] = modelLikelihood.getData()[i][1];
531 count+=1;}}
532
533 for (int i=0;i<assignments.getDimension(); i++){
534 if((int) assignments.getParameterValue(i) == group2 ){
535 group[count] = modelLikelihood.getData()[i][0];
536 group[count+ngroup] = modelLikelihood.getData()[i][1];
537 count+=1;}}
538
539
540
541
542 double[][] var = new double[2*ngroup][2*ngroup];
543 double[] mean = new double[2*ngroup];
544
545 double m0 = modelLikelihood.getPriorMean().getParameterValue(0);
546 double m1 = modelLikelihood.getPriorMean().getParameterValue(1);
547 double vp = modelLikelihood.getPriorPrec().getParameterValue(0);
548 double vc = modelLikelihood.getClusterPrec().getParameterValue(0);
549
550
551 for (int i=0; i<ngroup; i++){
552 mean[i]=m0;
553 mean[i+ngroup]=m1;
554
555 for (int l=0;l<ngroup;l++){
556 var[i][ngroup+l]=0;
557 var[ngroup+i][l]=0;
558
559 if (l==i){var[i][l]= vp+ vc;
560 var[ngroup+i][ngroup+l]= vp+ vc;}
561
562 else { var[i][l] = vp;
563 var[ngroup+i][ngroup+l]= vp;}
564 }
565 }
566
567
568 double[][] precision = new SymmetricMatrix(var).inverse().toComponents();
569 L = new MultivariateNormalDistribution(mean, precision).logPdf(group);
570
571 }
572
573
574 return L;
575
576 }
577 */
578
579
580
581 public void sampleMeans(int maxFull){
582
583 double[][] means=new double[maxFull+2][2];
584
585 throw new UnsupportedOperationException("This method has been commented out because of build errors");
586
587 //sample mean vector for each cluster
588
589 // for (int i=0; i<maxFull+1; i++){
590 //
591 // // Find all elements in cluster
592 //
593 // int ngroup=0;
594 // for (int ii=0;ii<assignments.getDimension(); ii++){
595 // if((int) assignments.getParameterValue(ii) == i ){
596 // ngroup++;}}
597 //
598 //
599 // if (ngroup != 0){
600 // double[][] group = new double[ngroup][2];
601 // double[] groupMean=new double[2];
602 //
603 // int count = 0;
604 // for (int ii=0;ii<assignments.getDimension(); ii++){
605 // if((int) assignments.getParameterValue(ii) == i ){
606 // group[count][0] = modelLikelihood.getData()[ii][0];
607 // group[count][1] = modelLikelihood.getData()[ii][1];
608 // groupMean[0]+=group[count][0];
609 // groupMean[1]+=group[count][1];
610 // count+=1;}}
611 //
612 // groupMean[0]/=ngroup;
613 // groupMean[1]/=ngroup;
614 //
615 //
616 //
617 // double kn= k0+ngroup;
618 // double vn= v0+ngroup;
619 //
620 //
621 // double[][] sumdif=new double[2][2];
622 //
623 // for(int jj=0;jj<ngroup;jj++){
624 // sumdif[0][0]+= (group[jj][0]-groupMean[0])*(group[jj][0]-groupMean[0]);
625 // sumdif[0][1]+= (group[jj][0]-groupMean[0])*(group[jj][1]-groupMean[1]);
626 // sumdif[1][0]+= (group[jj][0]-groupMean[0])*(group[jj][1]-groupMean[1]);
627 // sumdif[1][1]+= (group[jj][1]-groupMean[1])*(group[jj][1]-groupMean[1]);
628 // }
629 //
630 //
631 //
632 // double[][] TnInv = new double[2][2];
633 // TnInv[0][0]=T0Inv[0][0]+ngroup*(k0/kn)*(groupMean[0]-m[0])*(groupMean[0]-m[0])+sumdif[0][0];
634 // TnInv[0][1]=T0Inv[0][1]+ngroup*(k0/kn)*(groupMean[1]-m[1])*(groupMean[0]-m[0])+sumdif[0][1];
635 // TnInv[1][0]=T0Inv[1][0]+ngroup*(k0/kn)* (groupMean[0]-m[0])*(groupMean[1]-m[1])+sumdif[1][0];
636 // TnInv[1][1]=T0Inv[1][1]+ngroup*(k0/kn)* (groupMean[1]-m[1])*(groupMean[1]-m[1])+sumdif[1][1];
637 //
638 // Matrix Tn = new SymmetricMatrix(TnInv).inverse();
639 //
640 //
641 // double[] posteriorMean=new double[2];
642 // // compute posterior mean
643 //
644 // posteriorMean[0]= (k0*m[0] +ngroup*groupMean[0])/(k0+ngroup);
645 // posteriorMean[1]= (k0*m[1] +ngroup*groupMean[1])/(k0+ngroup);
646 //
647 //
648 //
649 // //compute posterior Precision
650 // double[][] posteriorPrecision=new WishartDistribution(vn,Tn.toComponents()).nextWishart();
651 // posteriorPrecision[0][0]*= kn;
652 // posteriorPrecision[1][0]*= kn;
653 // posteriorPrecision[0][1]*= kn;
654 // posteriorPrecision[1][1]*= kn;
655 //
656 //
657 //
658 //
659 // double[] sample= new MultivariateNormalDistribution(posteriorMean,posteriorPrecision).nextMultivariateNormal();
660 // means[i][0]=sample[0];
661 // means[i][1]=sample[1];
662 // }
663 // }
664 //
665 // //Fill in cluster means for each observation
666 //
667 // for (int j=0; j<assignments.getDimension();j++){
668 // double[] group=new double[2];
669 // group[0]=means[(int)assignments.getParameterValue(j)][0];
670 // group[1]=means[(int)assignments.getParameterValue(j)][1];
671 //
672 // modelLikelihood.setMeans(j, group);
673 // }
674
675
676 }
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692 private void exp(double[] logX) {
693 for (int i = 0; i < logX.length; ++i) {
694 logX[i] = Math.exp(logX[i]);
695 // if(logX[i]<1E-8){logX[i]=0;}
696 }
697 }
698
699 private void rescale(double[] logX) {
700 throw new UnsupportedOperationException("This method has been commented out because of build errors");
701 // double max = this.max(logX);
702 // for (int i = 0; i < logX.length; ++i) {
703 // if(logX[i] == Double.NEGATIVE_INFINITY){
704 // modelLikelihood.printInformtion(logX[i]);
705 // logX[i]=-1E16;
706 // }
707 // if(logX[i]==Double.POSITIVE_INFINITY){
708 // modelLikelihood.printInformtion(logX[i]);
709 // logX[i]=1E16;
710 // }
711 // logX[i] -= max;
712 //
713 // }
714 }
715
716 private double max(double[] x) {
717 double max = x[0];
718 for (double xi : x) {
719 if (xi > max) {
720 max = xi;
721 }
722 }
723 return max;
724 }
725
726 //MCMCOperator INTERFACE
727 public final String getOperatorName() {
728 return DDCRP_GIBBS_OPERATOR;
729 }
730
731 public final void optimize(double targetProb) {
732
733 throw new RuntimeException("This operator cannot be optimized!");
734 }
735
736 public boolean isOptimizing() {
737 return false;
738 }
739
740 public void setOptimizing(boolean opt) {
741 throw new RuntimeException("This operator cannot be optimized!");
742 }
743
744 public double getMinimumAcceptanceLevel() {
745 return 0.1;
746 }
747
748 public double getMaximumAcceptanceLevel() {
749 return 0.4;
750 }
751
752 public double getMinimumGoodAcceptanceLevel() {
753 return 0.20;
754 }
755
756 public double getMaximumGoodAcceptanceLevel() {
757 return 0.30;
758 }
759
760 public String getPerformanceSuggestion() {
761 if (Utils.getAcceptanceProbability(this) < getMinimumAcceptanceLevel()) {
762 return "";
763 } else if (Utils.getAcceptanceProbability(this) > getMaximumAcceptanceLevel()) {
764 return "";
765 } else {
766 return "";
767 }
768 }
769
770
771
772
773
774 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
775 public final static String CHI = "chi";
776 public final static String LIKELIHOOD = "likelihood";
777 public final static String ASSIGNMENTS = "assignments";
778 public final static String LINKS = "links";
779 public final static String DEP_MATRIX = "depMatrix";
780
781 public String getParserName() {
782 return DDCRP_GIBBS_OPERATOR;
783 }
784
785 /* (non-Javadoc)
786 * @see dr.xml.AbstractXMLObjectParser#parseXMLObject(dr.xml.XMLObject)
787 */
788 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
789
790 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
791
792
793 XMLObject cxo = xo.getChild(ASSIGNMENTS);
794 Parameter assignments = (Parameter) cxo.getChild(Parameter.class);
795
796 cxo = xo.getChild(LINKS);
797 Parameter links = (Parameter) cxo.getChild(Parameter.class);
798
799 cxo = xo.getChild(CHI);
800 Parameter chiParameter = (Parameter) cxo.getChild(Parameter.class);
801
802
803
804 cxo = xo.getChild(LIKELIHOOD);
805 NPAntigenicLikelihood likelihood = (NPAntigenicLikelihood)cxo.getChild(NPAntigenicLikelihood.class);
806
807
808
809
810 return new DistanceDependentCRPGibbsOperator( links, assignments,
811 chiParameter,likelihood, weight);
812
813 }
814
815 //************************************************************************
816 // AbstractXMLObjectParser implementation
817 //************************************************************************
818
819 public String getParserDescription() {
820 return "An operator that picks a new allocation of an item to a cluster under the Dirichlet process.";
821 }
822
823 public Class getReturnType() {
824 return DistanceDependentCRPGibbsOperator.class;
825 }
826
827
828 public XMLSyntaxRule[] getSyntaxRules() {
829 return rules;
830 }
831
832 private final XMLSyntaxRule[] rules = {
833 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
834 new ElementRule(CHI, new XMLSyntaxRule[] {
835 new ElementRule(Parameter.class),
836 }),
837 new ElementRule(LIKELIHOOD, new XMLSyntaxRule[] {
838 new ElementRule(Likelihood.class),
839 }, true),
840 new ElementRule(ASSIGNMENTS,
841 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
842 new ElementRule(LINKS,
843 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
844
845 };
846
847 };
848
849
850
851 public int getStepCount() {
852 return 1;
853 }
854
855 }
856
857
858
859