Debian Codegraph @

src/dr/evomodel/substmodel/GLMSubstitutionModel.java

raw symbols SCIP
1 /*
2 * GLMSubstitutionModel.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.substmodel;
27
28 import dr.evolution.datatype.DataType;
29 import dr.inference.glm.GeneralizedLinearModel;
30 import dr.inference.loggers.LogColumn;
31 import dr.inference.model.BayesianStochasticSearchVariableSelection;
32 import dr.inference.model.Model;
33 import dr.util.Citation;
34 import dr.util.CommonCitations;
35
36 import java.util.Collections;
37 import java.util.List;
38
39 /**
40 * @author Marc A. Suchard
41 */
42 public class GLMSubstitutionModel extends ComplexSubstitutionModel {
43
44 public GLMSubstitutionModel(String name, DataType dataType, FrequencyModel rootFreqModel,
45 GeneralizedLinearModel glm) {
46
47 super(name, dataType, rootFreqModel, null);
48 this.glm = glm;
49 addModel(glm);
50 testProbabilities = new double[stateCount*stateCount];
51
52 }
53
54 public double[] getRates() {
55 return glm.getXBeta();
56 }
57
58
59 protected void handleModelChangedEvent(Model model, Object object, int index) {
60 if (model == glm) {
61 updateMatrix = true;
62 fireModelChanged();
63 } else
64 super.handleModelChangedEvent(model, object, index);
65 }
66
67 // This info can be gotten from the GLM
68 // public LogColumn[] getColumns() {
69 // return glm.getColumns();
70 // }
71
72 public LogColumn[] getColumns() {
73 //Aggregate columns from ComplexSubstitutionModel with glm.columns
74 LogColumn[] aggregated = new LogColumn[glm.getColumns().length + 2];
75 int index = 0;
76 for (LogColumn col : glm.getColumns()) {
77 aggregated[index] = col;
78 index++;
79 }
80 aggregated[index++] = new LikelihoodColumn(getId() + ".L");
81 aggregated[index++] = new NormalizationColumn(getId() + ".Norm");
82
83 return aggregated;
84 //return glm.getColumns();
85 }
86
87 public double getLogLikelihood() {
88 double logL = super.getLogLikelihood();
89 if (logL == 0 &&
90 BayesianStochasticSearchVariableSelection.Utils.connectedAndWellConditioned(testProbabilities, this)) {
91 // Also check that graph is connected
92 return 0;
93 }
94 return Double.NEGATIVE_INFINITY;
95 }
96
97 @Override
98 public String getDescription() {
99 return "Generalized linear (model, GLM) substitution model"; // TODO Horrible; fix
100 }
101
102 @Override
103 public List<Citation> getCitations() {
104
105 return Collections.singletonList(CommonCitations.LEMEY_2014_UNIFYING);
106 }
107
108 private GeneralizedLinearModel glm;
109 private double[] testProbabilities;
110 }