Debian Codegraph @

src/dr/evomodel/continuous/ConstrainedGaussianProcessRandomGenerator.java

raw symbols SCIP
1 /*
2 * ConstrainedGaussianProcess.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.continuous;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.inference.model.Likelihood;
30 import dr.inference.model.Parameter;
31 import dr.inference.operators.EllipticalSliceOperator;
32 import dr.inferencexml.operators.EllipticalSliceOperatorParser;
33 import dr.math.KroneckerOperation;
34 import dr.math.distributions.GaussianProcessRandomGenerator;
35 import dr.math.distributions.MultivariateNormalDistribution;
36 import dr.math.matrixAlgebra.CholeskyDecomposition;
37 import dr.math.matrixAlgebra.IllegalDimension;
38 import dr.math.matrixAlgebra.Matrix;
39 import dr.math.matrixAlgebra.SymmetricMatrix;
40 import dr.xml.*;
41
42 /**
43 * @author Marc A. Suchard
44 * @author Max R. Tolkoff
45 */
46 public class ConstrainedGaussianProcessRandomGenerator implements GaussianProcessRandomGenerator {
47
48 private final GaussianProcessRandomGenerator generator;
49 private final boolean translationInvariant;
50 private final boolean rotationInvariant;
51
52 public ConstrainedGaussianProcessRandomGenerator(GaussianProcessRandomGenerator generator,
53 boolean translationInvariant, boolean rotationInvariant) {
54 this.generator = generator;
55 this.translationInvariant = translationInvariant;
56 this.rotationInvariant = rotationInvariant;
57 }
58
59 @Override
60 public Likelihood getLikelihood() {
61 throw new RuntimeException("Not yet implemented");
62 // return generator.getLikelihood();
63 }
64
65 @Override
66 public int getDimension() {
67 return generator.getDimension();
68 }
69
70 @Override
71 public double[][] getPrecisionMatrix() {
72 throw new RuntimeException("Not yet implemented");
73 // return generator.getPrecisionMatrix();
74 }
75
76 @Override
77 public Object nextRandom() {
78
79 double[] draw = (double[]) generator.nextRandom();
80 EllipticalSliceOperator.transformPoint(draw, translationInvariant, rotationInvariant,
81 2); // TODO Generalize for dim != 2
82 return draw;
83 }
84
85 @Override
86 public double logPdf(Object x) {
87 throw new RuntimeException("Not yet implemented");
88 // return generator.logPdf(x);
89
90 }
91
92 public boolean isTranslationInvariant() {
93 return translationInvariant;
94 }
95
96 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
97
98 public static final String CONSTAINED_GAUSSIAN_PROCESS = "constrainedGaussianProcess";
99 public static final String TRANSLATION_INVARIANT = EllipticalSliceOperatorParser.TRANSLATION_INVARIANT;
100 public static final String ROTATION_INVARIANT = EllipticalSliceOperatorParser.ROTATION_INVARIANT;
101
102 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
103 new ElementRule(GaussianProcessRandomGenerator.class),
104 AttributeRule.newBooleanRule(TRANSLATION_INVARIANT, true),
105 AttributeRule.newBooleanRule(ROTATION_INVARIANT, true),
106 };
107
108 @Override
109 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
110
111 boolean translationInvariant = xo.getAttribute(TRANSLATION_INVARIANT, false);
112 boolean rotationInvariant = xo.getAttribute(ROTATION_INVARIANT, false);
113
114 GaussianProcessRandomGenerator generator =
115 (GaussianProcessRandomGenerator) xo.getChild(GaussianProcessRandomGenerator.class);
116
117 return new ConstrainedGaussianProcessRandomGenerator(generator, translationInvariant, rotationInvariant);
118 }
119
120 @Override
121 public XMLSyntaxRule[] getSyntaxRules() {
122 return rules;
123 }
124
125 @Override
126 public String getParserDescription() {
127 return "Returns a random draw of traits given a trait model and a prior";
128 }
129
130 @Override
131 public Class getReturnType() {
132 return ConstrainedGaussianProcessRandomGenerator.class;
133 }
134
135 @Override
136 public String getParserName() {
137 return CONSTAINED_GAUSSIAN_PROCESS;
138 }
139 };
140 }