/* * BetaKDEDistribution.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.math.GammaFunction; import dr.stats.DiscreteStatistics; //import java.io.BufferedReader; //import java.io.FileReader; //import java.io.FileNotFoundException; //import java.io.IOException; //import java.util.StringTokenizer; /** * @author Marc Suchard */ public class BetaKDEDistribution extends KernelDensityEstimatorDistribution { public BetaKDEDistribution(Double[] sample, Double lowerBound, Double upperBound, Double bandWidth) { super(sample, lowerBound, upperBound, bandWidth); } @Override public double getFromPoint() { throw new RuntimeException("Not yet implemented"); } @Override public double getToPoint() { throw new RuntimeException("Not yet implemented"); } protected void processBounds(Double lowerBound, Double upperBound) { if (lowerBound == null || upperBound == null || upperBound - lowerBound <= 0) { throw new RuntimeException("BetaKDEDistribution must be bounded"); } if (lowerBound > DiscreteStatistics.min(sample) || upperBound < DiscreteStatistics.max(sample)) throw new RuntimeException("Sample range outside bounds: "+DiscreteStatistics.min(sample)+" -> "+DiscreteStatistics.max(sample)); this.lowerBound = lowerBound; this.upperBound = upperBound; // Make a copy because we are translating values into [0,1) double[] oldSample = sample; sample = new double[sample.length]; range = upperBound - lowerBound; for(int i=0; i 1 - 2*bandWidth) betaMinus1 = getRho(1.0-xPrime,bandWidth) - 1.0; double logK = GammaFunction.lnGamma(alphaMinus1+betaMinus1+2.0) - GammaFunction.lnGamma(alphaMinus1+1.0) - GammaFunction.lnGamma(betaMinus1+1.0); double pdf = 0; for(int i=0; i