| 1 | /* |
| 2 | * CoulombPrior.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.inference.model; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | |
| 30 | /** |
| 31 | * A prior with a density given by Coulombs Law of electrical force |
| 32 | * between charged particles. |
| 33 | * |
| 34 | * @author Andrew Rambaut |
| 35 | * @author Trevor Bedford |
| 36 | */ |
| 37 | |
| 38 | public class CoulombPrior extends Likelihood.Abstract { |
| 39 | |
| 40 | public CoulombPrior(double beta) { |
| 41 | |
| 42 | super(null); |
| 43 | |
| 44 | this.beta = beta; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Adds a statistic, this is the data for which the prior is calculated. |
| 49 | * |
| 50 | * @param data the statistic to compute density of |
| 51 | */ |
| 52 | public void addData(Statistic data) { |
| 53 | dataList.add(data); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | protected ArrayList<Statistic> dataList = new ArrayList<Statistic>(); |
| 58 | |
| 59 | /** |
| 60 | * Overridden to always return false. |
| 61 | */ |
| 62 | protected boolean getLikelihoodKnown() { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Calculate the log likelihood of the current state. |
| 68 | * |
| 69 | * @return the log likelihood. |
| 70 | */ |
| 71 | public double calculateLogLikelihood() { |
| 72 | |
| 73 | double logL = 0.0; |
| 74 | |
| 75 | for (Statistic statistic : dataList) { |
| 76 | for (int j = 0; j < statistic.getDimension(); j++) { |
| 77 | logL += -beta / statistic.getStatisticValue(j); |
| 78 | } |
| 79 | } |
| 80 | return logL; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | public String prettyName() { |
| 85 | String s = "Coulomb" + "("; |
| 86 | for (Statistic statistic : dataList) { |
| 87 | s = s + statistic.getStatisticName() + ","; |
| 88 | } |
| 89 | return s.substring(0, s.length() - 1) + ")"; |
| 90 | } |
| 91 | |
| 92 | private final double beta; |
| 93 | } |
| 94 |