Debian Codegraph @

src/dr/evomodel/coalescent/operators/GMRFSkyrideFixedEffectsGibbsOperator.java

raw symbols SCIP
1 /*
2 * GMRFSkyrideFixedEffectsGibbsOperator.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.coalescent.operators;
27
28 import dr.evomodel.coalescent.GMRFSkyrideLikelihood;
29 import dr.evomodelxml.coalescent.operators.GMRFSkyrideFixedEffectsGibbsOperatorParser;
30 import dr.inference.model.Parameter;
31 import dr.inference.operators.GibbsOperator;
32 import dr.inference.operators.SimpleMCMCOperator;
33 import dr.math.distributions.MultivariateDistribution;
34 import no.uib.cipr.matrix.*;
35
36 /**
37 * A Gibbs operator to update the population size parameters under a Gaussian Markov random field prior
38 *
39 * @author Erik Bloomquist
40 * @author Vladimir Minin
41 * @author Marc Suchard
42 * @version $Id: GMRFSkylineFixedEffectsGibbsOperator.java,v 1.5 2007/03/20 11:26:49 msuchard Exp $
43 */
44
45 public class GMRFSkyrideFixedEffectsGibbsOperator extends SimpleMCMCOperator implements GibbsOperator {
46
47 private GMRFSkyrideLikelihood gmrfLikelihood;
48
49 private DenseVector mean;
50 private DenseMatrix precision;
51
52 private int fieldLength;
53 private int dim;
54
55 public GMRFSkyrideFixedEffectsGibbsOperator(Parameter param,
56 GMRFSkyrideLikelihood gmrfLikelihood, MultivariateDistribution prior, double weight) {
57 this.gmrfLikelihood = gmrfLikelihood;
58 mean = new DenseVector(prior.getMean());
59 precision = new DenseMatrix(prior.getScaleMatrix());
60
61 this.fieldLength = gmrfLikelihood.getPopSizeParameter().getDimension();
62 this.dim = param.getDimension();
63
64 this.gmrfLikelihood = gmrfLikelihood;
65
66 setWeight(weight);
67 }
68
69 public double doOperation() {
70
71 DenseMatrix X = new DenseMatrix(gmrfLikelihood.getDesignMatrix().getParameterAsMatrix());
72 SymmTridiagMatrix Q = gmrfLikelihood.getScaledWeightMatrix(gmrfLikelihood.getPrecisionParameter().getParameterValue(0),
73 gmrfLikelihood.getLambdaParameter().getParameterValue(0));
74 DenseVector gamma = new DenseVector(gmrfLikelihood.getPopSizeParameter().getParameterValues());
75
76 Parameter.Abstract beta = (Parameter.Abstract) gmrfLikelihood.getBetaParameter();
77
78 //Set up the Vectors and matricies for the gibbs step
79 DenseMatrix gibbsPrecision = precision.copy();
80 UpperSPDDenseMatrix gibbsVariance;
81 DenseVector gibbsMean = new DenseVector(dim);
82 DenseMatrix workingMatrix = new DenseMatrix(dim, fieldLength);
83 DenseVector workingVector = new DenseVector(dim);
84
85 //Get the correct forms
86 X.transAmultAdd(Q, workingMatrix);
87 workingMatrix.multAdd(X, gibbsPrecision);
88
89 precision.mult(mean, workingVector);
90 workingMatrix.multAdd(gamma, workingVector);
91
92 workingMatrix = Matrices.identity(dim);
93
94 gibbsPrecision.solve(Matrices.identity(dim), workingMatrix);
95 gibbsVariance = new UpperSPDDenseMatrix(workingMatrix);
96 gibbsVariance.mult(workingVector, gibbsMean);
97
98 //Propose a new value for beta
99 DenseVector betaNew = GMRFSkyrideBlockUpdateOperator.getMultiNormal(gibbsMean, gibbsVariance);
100
101 for (int i = 0; i < dim; i++) {
102 beta.setParameterValueQuietly(i, betaNew.get(i));
103 }
104
105 beta.fireParameterChangedEvent();
106
107 return 0;
108 }
109
110 public int getStepCount() {
111 return 0;
112 }
113
114
115 public String getPerformanceSuggestion() {
116 return null;
117 }
118
119 //MCMCOperator INTERFACE
120
121 public final String getOperatorName() {
122 return GMRFSkyrideFixedEffectsGibbsOperatorParser.GMRF_GIBBS_OPERATOR;
123 }
124
125 }