Debian Codegraph @

src/dr/inference/operators/CombinedOperatorSchedule.java

raw symbols SCIP
1 /*
2 * CombinedOperatorSchedule.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 dr.math.MathUtils;
29
30 import java.util.List;
31 import java.util.Vector;
32
33 /**
34 * Package: CombinedOperatorSchedule
35 * Description:
36 * <p/>
37 * <p/>
38 * Created by
39 *
40 * @author Alexander V. Alekseyenko ([email protected])
41 * Date: Dec 23, 2009
42 * Time: 10:17:28 AM
43 */
44 public class CombinedOperatorSchedule implements OperatorSchedule {
45
46 List<OperatorSchedule> operatorSchedules = null;
47
48 public CombinedOperatorSchedule() {
49 operatorSchedules = new Vector<OperatorSchedule>();
50 }
51
52 public void addOperatorSchedule(OperatorSchedule os) {
53 operatorSchedules.add(os);
54 }
55
56 public int getScheduleCount() {
57 return operatorSchedules.size();
58 }
59
60 public int getNextOperatorIndex() {
61
62 final int v = MathUtils.nextInt(operatorSchedules.size());
63
64 int offset = 0;
65 for (int i = 0; i < v; ++i) {
66 offset += operatorSchedules.get(i).getOperatorCount();
67 }
68
69 return offset + operatorSchedules.get(v).getNextOperatorIndex();
70 }
71
72 public void reset() {
73 for (OperatorSchedule os : operatorSchedules) {
74 for (int i = 0; i < os.getOperatorCount(); ++i) {
75 os.getOperator(i).reset();
76 }
77 }
78 }
79
80 public int getOperatorCount() {
81 int operatorCount = 0;
82 for (OperatorSchedule os : operatorSchedules) {
83 operatorCount += os.getOperatorCount();
84 }
85 return operatorCount;
86 }
87
88 public MCMCOperator getOperator(int index) {
89 for (OperatorSchedule os : operatorSchedules) {
90 int opCount = os.getOperatorCount();
91 if (index < opCount) {
92 return os.getOperator(index);
93 } else {
94 index -= opCount;
95 }
96 }
97 // if we reach here the index must be out of bounds return null
98 return null;
99 }
100
101 public void addOperator(MCMCOperator op) {
102 System.err.println("ERROR: addOperator() should not be called on CombinedOperatorSchedule, " +
103 "use individual operator schedules to add operators. This call will have no affect!");
104 }
105
106 public void addOperators(List<MCMCOperator> v) {
107 System.err.println("ERROR: addOperators() should not be called on CombinedOperatorSchedule, " +
108 "use individual operator schedules to add operators. This call will have no affect!");
109 }
110
111 public void operatorsHasBeenUpdated() {
112 for (OperatorSchedule os : operatorSchedules) {
113 os.operatorsHasBeenUpdated();
114 }
115 }
116
117 public double getOptimizationTransform(double d) {
118 if (operatorSchedules.size() > 0)
119 return operatorSchedules.get(0).getOptimizationTransform(d);
120 else
121 return 0;
122 }
123
124 public long getMinimumAcceptAndRejectCount() {
125 long minCount = Long.MAX_VALUE;
126 for (OperatorSchedule os : operatorSchedules) {
127 if (os.getMinimumAcceptAndRejectCount() < minCount) {
128 minCount = os.getMinimumAcceptAndRejectCount();
129 }
130 }
131 return minCount;
132 }
133
134
135 }