/* * DirichletSiteModel.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.sitemodel; import dr.oldevomodel.substmodel.FrequencyModel; import dr.oldevomodel.substmodel.SubstitutionModel; import dr.inference.model.AbstractModel; import dr.inference.model.Model; import dr.inference.model.Parameter; import dr.inference.model.Variable; import dr.xml.*; import java.util.logging.Logger; /** * DirichletSiteModel - A SiteModel that has a free rate parameter for each category. * These rate parameters are constrained to sum to 1. * * @author Benjamin Redelings */ public class DirichletSiteModel extends AbstractModel implements SiteModel { public static final String SUBSTITUTION_MODEL = "substitutionModel"; public static final String DIRICHLET_SITE_MODEL = "DirichletSiteModel"; public static final String CATEGORIES = "categories"; public static final String RATES = "rates"; /** * Constructor for gamma+invar distributed sites. Either shapeParameter or * invarParameter (or both) can be null to turn off that feature. */ public DirichletSiteModel(SubstitutionModel substitutionModel, int n_categories) { this(substitutionModel, new Parameter.Default(new double[n_categories])); } public DirichletSiteModel(SubstitutionModel substitutionModel, Parameter ratesParameter) { super(DIRICHLET_SITE_MODEL); // Set substitution model this.substitutionModel = substitutionModel; addModel(substitutionModel); // Allocate array for categories and proportions int n_categories = ratesParameter.getDimension(); categoryRates = new double[n_categories]; categoryProportions = new double[n_categories]; // We haven't calculated any rates yet. ratesKnown = false; // Initialize the rate parameter value for(int i=0;i 0) { Logger.getLogger("dr.evomodel").info("Creating site model: " + msg); } else { Logger.getLogger("dr.evomodel").info("Creating site model."); } return new DirichletSiteModel(substitutionModel, ratesParameter); } //************************************************************************ // AbstractXMLObjectParser implementation //************************************************************************ public String getParserDescription() { return "A SiteModel that has Dirichlet distributed rates across sites"; } public Class getReturnType() { return DirichletSiteModel.class; } public XMLSyntaxRule[] getSyntaxRules() { return rules; } private final XMLSyntaxRule[] rules = { new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{ new ElementRule(SubstitutionModel.class) }), new ElementRule(RATES, new XMLSyntaxRule[]{ new ElementRule(Parameter.class) }) }; }; /** * the substitution model for these sites */ private SubstitutionModel substitutionModel = null; /** * the substitution rates: these sum to 1 */ private Parameter ratesParameter; private boolean ratesKnown; private double[] categoryRates; private double[] categoryProportions; }