Debian Codegraph @

src/dr/inference/operators/MCMCOperator.java

raw symbols SCIP
1 /*
2 * MCMCOperator.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.operators;
27
28 import java.io.Serializable;
29
30 /**
31 * An MCMC operator.
32 *
33 * @author Alexei Drummond
34 * @author Andrew Rambaut
35 * @version $Id: MCMCOperator.java,v 1.6 2005/06/14 10:40:34 rambaut Exp $
36 */
37 public interface MCMCOperator extends Serializable {
38
39 public static final String WEIGHT = "weight";
40
41 /**
42 * operates on the model.
43 *
44 * @return the hastings ratio of this operator.
45 */
46 double operate();
47
48 /**
49 * Called to tell operator that operation was accepted
50 *
51 * @param deviation the log ratio accepted on
52 */
53 void accept(double deviation);
54
55 /**
56 * Called to tell operator that operation was rejected
57 */
58 void reject();
59
60 /**
61 * Reset operator acceptance records.
62 */
63 void reset();
64
65 /**
66 * @return the total number of operations since last call to reset().
67 */
68 long getCount();
69
70 /**
71 * @return the number of acceptances since last call to reset().
72 */
73 long getAcceptCount();
74
75 /**
76 * Set the number of acceptances since last call to reset(). This is used
77 * to restore the state of the operator
78 *
79 * @param acceptCount number of acceptances
80 */
81 void setAcceptCount(long acceptCount);
82
83 /**
84 * @return the number of rejections since last call to reset().
85 */
86 long getRejectCount();
87
88 /**
89 * Set the number of rejections since last call to reset(). This is used
90 * to restore the state of the operator
91 *
92 * @param rejectCount number of rejections
93 */
94 void setRejectCount(long rejectCount);
95
96 /**
97 * @return the mean deviation in log posterior per accepted operations.
98 */
99 double getMeanDeviation();
100
101 double getSumDeviation();
102
103 //double getSpan(boolean reset);
104
105 void setSumDeviation(double sumDeviation);
106
107 /**
108 * @return the relative weight of this operator.
109 */
110 double getWeight();
111
112 /**
113 * sets the weight of this operator. The weight
114 * determines the proportion of time spent using
115 * this operator. This is relative to a 'standard'
116 * operator weight of 1.
117 *
118 * @param weight the relative weight of this parameter - should be positive.
119 */
120 void setWeight(double weight);
121
122 /**
123 * @return the name of this operator
124 */
125 String getOperatorName();
126
127 double getMeanEvaluationTime();
128
129 void addEvaluationTime(long time);
130
131 long getTotalEvaluationTime();
132
133 class Utils {
134
135 public static double getAcceptanceProbability(MCMCOperator op) {
136 final long accepted = op.getAcceptCount();
137 final long rejected = op.getRejectCount();
138 return (double) accepted / (double) (accepted + rejected);
139 }
140
141 public static long getOperationCount(MCMCOperator op) {
142 return op.getAcceptCount() + op.getRejectCount();
143 }
144 }
145 }