/* * SVSComplexSubstitutionModel.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.oldevomodel.substmodel; import dr.evolution.datatype.DataType; import dr.inference.model.BayesianStochasticSearchVariableSelection; import dr.inference.model.Parameter; import dr.inference.model.Variable; import dr.math.matrixAlgebra.Vector; /** * @author Marc A. Suchard */ public class SVSComplexSubstitutionModel extends ComplexSubstitutionModel implements BayesianStochasticSearchVariableSelection { public SVSComplexSubstitutionModel(String name, DataType dataType, FrequencyModel rootFreqModel, Parameter rates, Parameter indicators) { super(name, dataType, rootFreqModel, rates); if (indicators != null) { this.indicators = indicators; addVariable(indicators); } else { this.indicators = new Parameter.Default(rates.getDimension(), 1.0); } } protected double[] getRates() { double[] rates = infinitesimalRates.getParameterValues(); double[] indies = indicators.getParameterValues(); final int dim = rates.length; for (int i = 0; i < dim; i++) rates[i] *= indies[i]; return rates; } protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { if (variable == infinitesimalRates && indicators.getParameterValue(index) == 0) return; // ignore, does not affect likelihood super.handleVariableChangedEvent(variable, index, type); } public Parameter getIndicators() { return indicators; } // public double getLogLikelihood() { // double logL = super.getLogLikelihood(); // if (logL == 0 && considerConnectedness && !isStronglyConnected()) { // Also check that graph is connected // logL = Double.NEGATIVE_INFINITY; // } // return logL; // } // private boolean hasEdge(int i, int j) { // return i != j && getIndicators().getParameterValue(getEntry(i,j,stateCount)) == 1; // } // // private static int getEntry(int i, int j, int dim) { // int entry = i * (dim - 1) + j; // if( j > i ) // entry--; // return entry; // } // // private void depthFirstSearch(int node, BitVector visited) { // visited.set(node); // for(int v=0; v