Debian Codegraph @

src/dr/evomodel/treedatalikelihood/continuous/RootProcessDelegate.java

raw symbols SCIP
1 /*
2 * RootProcessDelegate.java
3 *
4 * Copyright (c) 2002-2016 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.treedatalikelihood.continuous;
27
28 import dr.evomodel.treedatalikelihood.continuous.cdi.ContinuousDiffusionIntegrator;
29 import dr.evomodel.treedatalikelihood.continuous.cdi.PrecisionType;
30
31 /**
32 * @author Marc A. Suchard
33 * @version $Id$
34 */
35 public interface RootProcessDelegate {
36
37 int getExtraPartialBufferCount();
38
39 int getExtraMatrixBufferCount();
40
41 void calculateRootLogLikelihood(ContinuousDiffusionIntegrator cdi, int rootIndex, final double[] logLike,
42 boolean incrementOuterProducts);
43
44 void setRootPartial(ContinuousDiffusionIntegrator cdi);
45
46 double getPseudoObservations();
47
48 int getPriorBufferIndex();
49
50 // int getDegreesOfFreedom();
51
52 abstract class Abstract implements RootProcessDelegate {
53
54 protected final ConjugateRootTraitPrior prior;
55 private final PrecisionType precisionType;
56 private final int priorBufferIndex;
57 private final int numTraits;
58
59 public abstract double getPseudoObservations();
60
61 public Abstract(final ConjugateRootTraitPrior prior,
62 final PrecisionType precisionType, int numTraits,
63 int partialBufferCount, int matrixBufferCount) {
64 this.prior = prior;
65 this.precisionType = precisionType;
66 this.numTraits = numTraits;
67
68 this.priorBufferIndex = partialBufferCount;
69 }
70
71 @Override
72 public int getExtraPartialBufferCount() {
73 return 2; // TODO Why does 1 not work?
74 }
75
76 @Override
77 public int getExtraMatrixBufferCount() {
78 return 0;
79 }
80
81 @Override
82 public int getPriorBufferIndex() { return priorBufferIndex; }
83
84 @Override
85 public void calculateRootLogLikelihood(ContinuousDiffusionIntegrator cdi, int rootBufferIndex,
86 final double[] logLike, boolean incrementOuterProducts) {
87 cdi.calculateRootLogLikelihood(rootBufferIndex, priorBufferIndex, logLike, incrementOuterProducts);
88 }
89
90 @Override
91 public void setRootPartial(ContinuousDiffusionIntegrator cdi) {
92 double[] mean = prior.getMean();
93 final int dimTrait = mean.length;
94
95 final int length = dimTrait + precisionType.getMatrixLength(dimTrait);
96 double[] partial = new double[length * numTraits];
97
98 int offset = 0;
99 for (int trait = 0; trait < numTraits; ++trait) {
100 System.arraycopy(mean, 0, partial, offset, dimTrait);
101
102 final double precision = getPseudoObservations();
103 for (int i = 0; i < dimTrait; ++i) {
104 precisionType.fillPrecisionInPartials(partial, offset, i, precision, dimTrait);
105 }
106
107 // partial[offset + dimTrait] = getPseudoObservations();
108 offset += length;
109 }
110
111 cdi.setPostOrderPartial(priorBufferIndex, partial);
112 }
113 }
114
115 class Fixed extends Abstract {
116
117 public Fixed(ConjugateRootTraitPrior prior, PrecisionType precisionType,
118 int numTraits, int partialBufferCount, int matrixBufferCount) {
119 super(prior, precisionType, numTraits, partialBufferCount, matrixBufferCount);
120 }
121
122 @Override
123 public double getPseudoObservations() {
124 return Double.POSITIVE_INFINITY;
125 }
126
127 // @Override
128 // public int getDegreesOfFreedom() { return 0; }
129 }
130
131 class FullyConjugate extends Abstract {
132
133 public FullyConjugate(ConjugateRootTraitPrior prior, PrecisionType precisionType,
134 int numTraits, int partialBufferCount, int matrixBufferCount) {
135 super(prior, precisionType, numTraits, partialBufferCount, matrixBufferCount);
136 }
137
138 @Override
139 public double getPseudoObservations() {
140 return prior.getPseudoObservations();
141 }
142
143 // @Override
144 // public int getDegreesOfFreedom() { return 1; }
145 }
146 }