Debian Codegraph @

src/dr/evomodel/coalescent/GMRFTestLikelihood.java

raw symbols SCIP
1 /*
2 * GMRFTestLikelihood.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;
27
28 import dr.evolution.tree.Tree;
29 import dr.inference.model.DesignMatrix;
30 import dr.inference.model.Parameter;
31 import no.uib.cipr.matrix.SymmTridiagMatrix;
32
33 /**
34 * Created by IntelliJ IDEA.
35 * User: msuchard
36 * Date: Aug 9, 2007
37 * Time: 2:14:04 PM
38 * To change this template use File | Settings | File Templates.
39 */
40 public class GMRFTestLikelihood extends GMRFSkyrideLikelihood {
41
42 public GMRFTestLikelihood(Tree tree, Parameter popParameter, Parameter precParameter, Parameter lambda, Parameter beta, DesignMatrix design) {
43 super(tree, popParameter, null, precParameter, lambda, beta, design, false, true);
44 }
45
46
47 private Parameter intervalsParameter;
48 private Parameter statsParameter;
49 private Parameter betaParameter;
50
51 public GMRFTestLikelihood(Parameter inPop, Parameter inPrec, Parameter inLambda, Parameter inBeta, DesignMatrix design, Parameter intervals, Parameter statParameter) {
52 super();
53 popSizeParameter = inPop;
54 precisionParameter = inPrec;
55 lambdaParameter = inLambda;
56 intervalsParameter = intervals;
57 statsParameter = statParameter;
58 betaParameter = inBeta;
59 fieldLength = popSizeParameter.getDimension();
60 addVariable(popSizeParameter);
61 addVariable(precisionParameter);
62 addVariable(lambdaParameter);
63 addVariable(intervalsParameter);
64 addVariable(statsParameter);
65 addVariable(betaParameter);
66
67 setupGMRFWeights();
68 }
69
70
71 protected void storeState() {
72 super.storeState();
73 System.arraycopy(coalescentIntervals, 0, storedCoalescentIntervals, 0, coalescentIntervals.length);
74 System.arraycopy(sufficientStatistics, 0, storedSufficientStatistics, 0, sufficientStatistics.length);
75 storedWeightMatrix = weightMatrix.copy();
76 }
77
78
79 protected void restoreState() {
80 super.restoreState();
81 System.arraycopy(storedCoalescentIntervals, 0, coalescentIntervals, 0, storedCoalescentIntervals.length);
82 System.arraycopy(storedSufficientStatistics, 0, sufficientStatistics, 0, storedSufficientStatistics.length);
83 weightMatrix = storedWeightMatrix;
84
85 }
86
87 public double calculateLogLikelihood() {
88 return 0;
89 }
90
91 protected void setupGMRFWeights() {
92
93 // int index = 0;
94 //
95 // double length = 0;
96 // double weight = 0;
97 // for (int i = 0; i < getIntervalCount(); i++) {
98 // length += getInterval(i);
99 // weight += getInterval(i) * getLineageCount(i) * (getLineageCount(i) - 1);
100 // if (getIntervalType(i) == CoalescentEventType.COALESCENT) {
101 // coalescentIntervals[index] = length;
102 // sufficientStatistics[index] = weight / 2.0;
103 // index++;
104 // length = 0;
105 // weight = 0;
106 // }
107 // }
108
109 coalescentIntervals = intervalsParameter.getParameterValues();
110 sufficientStatistics = statsParameter.getParameterValues();
111 storedCoalescentIntervals = new double[coalescentIntervals.length];
112 storedSufficientStatistics = new double[sufficientStatistics.length];
113
114 //Set up the weight Matrix
115 double[] offdiag = new double[fieldLength - 1];
116 double[] diag = new double[fieldLength];
117
118 // double precision = precisionParameter.getParameterValue(0);
119
120 //First set up the offdiagonal entries;
121 for (int i = 0; i < fieldLength - 1; i++) {
122 offdiag[i] = -2.0 / (coalescentIntervals[i] + coalescentIntervals[i + 1]);
123 }
124
125 //Then set up the diagonal entries;
126 for (int i = 1; i < fieldLength - 1; i++)
127 diag[i] = -(offdiag[i] + offdiag[i - 1]);
128
129 //Take care of the endpoints
130 diag[0] = -offdiag[0];
131 diag[fieldLength - 1] = -offdiag[fieldLength - 2];
132
133
134 weightMatrix = new SymmTridiagMatrix(diag, offdiag);
135
136 }
137
138 }