Debian Codegraph @

src/dr/oldevomodel/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.oldevomodel.substmodel;
27
28 import dr.evolution.datatype.DataType;
29 import dr.inference.distribution.LogLinearModel;
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 LogLinearModel 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 }
64 else
65 super.handleModelChangedEvent(model,object,index);
66 }
67
68 public LogColumn[] getColumns() {
69 return glm.getColumns();
70 }
71
72 public double getLogLikelihood() {
73 double logL = super.getLogLikelihood();
74 if (logL == 0 &&
75 BayesianStochasticSearchVariableSelection.Utils.connectedAndWellConditioned(testProbabilities,this)) { // Also check that graph is connected
76 return 0;
77 }
78 return Double.NEGATIVE_INFINITY;
79 }
80
81 @Override
82 public String getDescription() {
83 return "Generalized linear (model, GLM) substitution model"; // TODO Horrible; fix
84 }
85
86 @Override
87 public List<Citation> getCitations() {
88
89 return Collections.singletonList(CommonCitations.LEMEY_2014_UNIFYING);
90 }
91
92 private LogLinearModel glm;
93 private double[] testProbabilities;
94 }