/* * MultivariatePolyaDistributionLikelihood.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.math.distributions; import dr.inference.loggers.LogColumn; import dr.inference.loggers.NumberColumn; import dr.inference.model.*; import dr.math.GammaFunction; import dr.xml.*; import java.util.Arrays; import java.util.HashSet; import java.util.Set; /** * Package: MultivariatePolyaDistributionLikelihood * Description: * this class provides a model for over-dispersed multinomial counts. The model follows Dirichlet-Multinomial distribution with * multinomial parameters integrated out analytically. This model is also known as Multivariate Polya distribution. * Standard parametrization involves k intensities a_i's. This implementation uses the standard parametrization internally, but allows * for re-parametrization as frequencies (k-1 df) and dispersion parameters, where a = sum_i=1^k a_i is dispersion and f_i = a_i/a *
* Created by * * @author Alexander V. Alekseyenko (alexander.alekseyenko@gmail.com) * Date: Sep 23, 2010 * Time: 12:25:14 PM */ public class MultivariatePolyaDistributionLikelihood extends AbstractModel implements Likelihood { protected Parameter frequencies; protected Parameter dispersion; protected Parameter alphas; protected boolean usingAlphas; protected boolean isAlphasKnown; protected MatrixParameter data; protected double fixedNorm; protected double variableNorm; protected double storedFixedNorm; protected double storedVariableNorm; protected double logLikelihood; protected double storedLogLikelihood; protected boolean isLogLikelihoodKnown; protected boolean isFixedNormKnown; protected boolean isVariableNormKnown; protected double rowSums[]; public MultivariatePolyaDistributionLikelihood(String modelID, MatrixParameter data, Parameter frequencies, Parameter dispersion) { super(modelID); this.frequencies = frequencies; this.dispersion = dispersion; this.alphas = new Parameter.Default(frequencies.getDimension()); computeAlphas(); this.data = data; isFixedNormKnown = false; isVariableNormKnown = false; addVariable(this.frequencies); addVariable(this.dispersion); addVariable(this.data); if (this.alphas.getDimension() != data.getColumnDimension()) { System.err.println("Dimensions of the frequency vector and number of columns do not match!"); } } public MultivariatePolyaDistributionLikelihood(String modelID, MatrixParameter data, Parameter alphas) { super(modelID); this.alphas = alphas; isAlphasKnown = true; usingAlphas = true; this.frequencies = new Parameter.Default(alphas.getDimension()); this.dispersion = new Parameter.Default(1); this.data = data; isFixedNormKnown = false; isVariableNormKnown = false; addVariable(this.alphas); addVariable(this.data); if (this.alphas.getDimension() != data.getColumnDimension()) { System.err.println("Dimensions of the frequency vector and number of columns do not match!"); } } /* Compute alphas from frequencies and dispersion */ protected void computeAlphas(){ double disp=dispersion.getParameterValue(0); double[] freqs = frequencies.getParameterValues(); for(int i=0; i