Debian Codegraph @

src/dr/evomodel/operators/MicrosatelliteUpDownOperator.java

raw symbols SCIP
1 /*
2 * MicrosatUpDownOperator.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.evomodel.operators;
27
28 import dr.inference.operators.*;
29 import dr.math.MathUtils;
30
31 /**
32 *
33 * @author Chieh-Hsi
34 *
35 * Implements MicrosatUpDownOperator
36 *
37 * This is almost the same as UpDownOperator, except it uses scaleAllAndNotify method instead of scale.
38 *
39 */
40 public class MicrosatelliteUpDownOperator extends AbstractAdaptableOperator {
41
42 private Scalable.Default[] upParameter = null;
43 private Scalable.Default[] downParameter = null;
44 private double scaleFactor;
45
46 public MicrosatelliteUpDownOperator(Scalable.Default[] upParameter,
47 Scalable.Default[] downParameter,
48 double scale,
49 double weight,
50 AdaptationMode mode) {
51
52 super(mode);
53 setWeight(weight);
54
55 this.upParameter = upParameter;
56 this.downParameter = downParameter;
57 this.scaleFactor = scale;
58 }
59
60 public final double getScaleFactor() {
61 return scaleFactor;
62 }
63
64 public final void setScaleFactor(double sf) {
65 if( (sf > 0.0) && (sf < 1.0) ) {
66 scaleFactor = sf;
67 } else {
68 throw new IllegalArgumentException("scale must be between 0 and 1");
69 }
70 }
71
72 /**
73 * change the parameter and return the hastings ratio.
74 */
75 public final double doOperation() {
76
77
78 final double scale = (scaleFactor + (MathUtils.nextDouble() * ((1.0 / scaleFactor) - scaleFactor)));
79 int goingUp = 0, goingDown = 0;
80
81 if( upParameter != null ) {
82 for( Scalable.Default up : upParameter ) {
83 goingUp += up.scaleAllAndNotify(scale, -1, false);
84 }
85 }
86
87 if( downParameter != null ) {
88 for(Scalable.Default dn : downParameter ) {
89 goingDown += dn.scaleAllAndNotify(1.0 / scale, -1, false);
90 }
91 }
92
93 return (goingUp - goingDown - 2) * Math.log(scale);
94 }
95
96 public String getAdaptableParameterName() {
97 return "scaleFactor";
98 }
99
100 public final String getOperatorName() {
101 String name = "";
102 if( upParameter != null ) {
103 name = "up:";
104 for( Scalable up : upParameter ) {
105 name = name + up.getName() + " ";
106 }
107 }
108
109 if( downParameter != null ) {
110 name += "down:";
111 for( Scalable dn : downParameter ) {
112 name = name + dn.getName() + " ";
113 }
114 }
115 return name;
116 }
117
118 public double getAdaptableParameter() {
119 return Math.log(1.0 / scaleFactor - 1.0) / Math.log(10);
120 }
121
122 public void setAdaptableParameter(double value) {
123 scaleFactor = 1.0 / (Math.pow(10.0, value) + 1.0);
124 }
125
126 public double getRawParameter() {
127 return scaleFactor;
128 }
129
130 // Since this operator invariably modifies at least 2 parameters it
131 // should allow lower acceptance probabilities
132 // as it is known that optimal acceptance levels are inversely
133 // proportional to the number of dimensions operated on
134 // AD 16/3/2004
135 public double getMinimumAcceptanceLevel() {
136 return 0.05;
137 }
138
139 public double getMaximumAcceptanceLevel() {
140 return 0.3;
141 }
142
143 public double getMinimumGoodAcceptanceLevel() {
144 return 0.10;
145 }
146
147 public double getMaximumGoodAcceptanceLevel() {
148 return 0.20;
149 }
150
151 }