Debian Codegraph @

src/dr/inference/model/BooleanLikelihood.java

raw symbols SCIP
1 /*
2 * BooleanLikelihood.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 class that returns a log likelihood of a set of boolean statistics.
32 * If all the statistics are true then it returns 0.0 otherwise -INF.
33 *
34 * @author Andrew Rambaut
35 *
36 * @version $Id: BooleanLikelihood.java,v 1.8 2005/05/24 20:25:59 rambaut Exp $
37 */
38 public class BooleanLikelihood extends Likelihood.Abstract {
39
40 public BooleanLikelihood() {
41 super(null);
42 }
43
44 /**
45 * Adds a statistic, this is the data for which the likelihood is calculated.
46 */
47 public void addData(BooleanStatistic data) { dataList.add(data); }
48
49 protected ArrayList<BooleanStatistic> dataList = new ArrayList<BooleanStatistic>();
50
51 // **************************************************************
52 // Likelihood IMPLEMENTATION
53 // **************************************************************
54
55 /**
56 * Overridden to always return false.
57 */
58 protected boolean getLikelihoodKnown() {
59 return false;
60 }
61
62 /**
63 * Calculate the log likelihood of the current state.
64 * If all the statistics are true then it returns 0.0 otherwise -INF.
65 * @return the log likelihood.
66 */
67 public double calculateLogLikelihood() {
68
69 if (getBooleanState()) {
70 return Double.NEGATIVE_INFINITY;
71 } else {
72 return 0.0;
73 }
74 }
75
76 public boolean getBooleanState() {
77
78 for (BooleanStatistic statistic : dataList) {
79 for (int j = 0; j < statistic.getDimension(); j++) {
80 if (!statistic.getBoolean(j)) {
81 return true;
82 }
83 }
84 }
85 return false;
86 }
87
88 /**
89 * Boolean likelihoods would generally want to be evaluated early to allow for a quick
90 * termination of the evaluation in the case of a zero likelihood.
91 * @return
92 */
93 public boolean evaluateEarly() {
94 return true;
95 }
96
97 }
98