Debian Codegraph @

src/dr/inference/model/CorrelationStatistic.java

raw symbols SCIP
1 /*
2 * CorrelationStatistic.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.inference.model;
27
28 import dr.math.matrixAlgebra.SymmetricMatrix;
29 import dr.xml.*;
30
31 /**
32 * Created by IntelliJ IDEA.
33 * User: msuchard
34 * Date: Jul 7, 2007
35 * Time: 8:15:31 AM
36 * To change this template use File | Settings | File Templates.
37 */
38 public class CorrelationStatistic extends Statistic.Abstract {
39
40 // public class CorrelationStatistic extends Statistic.Abstract {
41
42 public static final String CORRELATION_STATISTIC = "correlation";
43 public static final String DIMENSION1 = "dimension1";
44 public static final String DIMENSION2 = "dimension2";
45
46 private MatrixParameter precision = null;
47 private int dim1;
48 private int dim2;
49
50 public CorrelationStatistic(String name, MatrixParameter precision,
51 int dim1, int dim2) {
52 super(name);
53 this.precision = precision;
54 this.dim1 = dim1 - 1;
55 this.dim2 = dim2 - 1;
56 // System.err.println("MAKE!");
57 // System.exit(0);
58 }
59
60 public int getDimension() {
61 return 1;
62 }
63
64 public double getStatisticValue(int dim) {
65
66 double[][] variance = new SymmetricMatrix(
67 precision.getParameterAsMatrix()).inverse().toComponents();
68 return variance[dim1][dim2] /
69 Math.sqrt(variance[dim1][dim1] * variance[dim2][dim2]);
70
71 }
72
73 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
74
75 public String getParserName() {
76 return CORRELATION_STATISTIC;
77 }
78
79 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
80
81 // ReciprocalStatistic recipStatistic = null;
82 MatrixParameter matrix = (MatrixParameter) xo.getChild(MatrixParameter.class);
83 int dim1 = xo.getIntegerAttribute(DIMENSION1);
84 int dim2 = xo.getIntegerAttribute(DIMENSION2);
85
86 if (dim1 < 1 || dim1 > matrix.getRowDimension() || dim2 < 1 || dim2 > matrix.getColumnDimension())
87 throw new XMLParseException("Invalid dimensions in " + getParserName() + " element");
88
89 return new CorrelationStatistic(CORRELATION_STATISTIC, matrix, dim1, dim2);
90 }
91
92 //************************************************************************
93 // AbstractXMLObjectParser implementation
94 //************************************************************************
95
96 public String getParserDescription() {
97 return "This element returns a precision that is the element-wise reciprocal of the child precision.";
98 }
99
100 public Class getReturnType() {
101 return ReciprocalStatistic.class;
102 }
103
104 public XMLSyntaxRule[] getSyntaxRules() {
105 return rules;
106 }
107
108 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
109 new ElementRule(MatrixParameter.class, 1, 1),
110 AttributeRule.newIntegerRule(DIMENSION1),
111 AttributeRule.newIntegerRule(DIMENSION2)
112
113 };
114 };
115 // }
116
117 }