| 1 | /* |
| 2 | * ExposeRateCategoriesWrapper.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.substmodel; |
| 27 | |
| 28 | import dr.inference.model.Bounds; |
| 29 | import dr.inference.model.Model; |
| 30 | import dr.inference.model.ModelListener; |
| 31 | import dr.inference.model.Parameter; |
| 32 | |
| 33 | /** |
| 34 | * @author Marc A. Suchard |
| 35 | * @author Rory E. Wasiolek |
| 36 | */ |
| 37 | public class ExposeRateCategoriesWrapper extends Parameter.Abstract implements ModelListener { |
| 38 | |
| 39 | public ExposeRateCategoriesWrapper(MarkovModulatedSubstitutionModel mmSubstModel) { |
| 40 | super(); |
| 41 | this.mmSubstModel = mmSubstModel; |
| 42 | } |
| 43 | |
| 44 | public int getDimension() { |
| 45 | return mmSubstModel.getNumBaseModel(); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void storeValues() { |
| 50 | // Do nothing |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected void restoreValues() { |
| 55 | // Do nothing |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected void acceptValues() { |
| 60 | // Do nothing |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected void adoptValues(Parameter source) { |
| 65 | // Do nothing |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param dim the index of the parameter dimension of interest |
| 70 | * @return the parameter's scalar value in the given dimension |
| 71 | */ |
| 72 | @Override |
| 73 | public double getParameterValue(int dim) { |
| 74 | return mmSubstModel.getModelRateScalar(dim); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * sets the scalar value in the given dimension of this parameter |
| 79 | * |
| 80 | * @param dim the index of the dimension to set |
| 81 | * @param value the value to set |
| 82 | */ |
| 83 | @Override |
| 84 | public void setParameterValue(int dim, double value) { |
| 85 | throw new RuntimeException("Not implemented for wrapper."); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * sets the scalar value in the given dimensin of this parameter to val, without firing any events |
| 90 | * |
| 91 | * @param dim the index of the dimension to set |
| 92 | * @param value the value to set |
| 93 | */ |
| 94 | @Override |
| 95 | public void setParameterValueQuietly(int dim, double value) { |
| 96 | throw new RuntimeException("Not implemented for wrapper."); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * sets the scalar value in the given dimensin of this parameter to val, |
| 101 | * and notifies that values in all dimension have been changed |
| 102 | * |
| 103 | * @param dim the index of the dimension to set |
| 104 | * @param value the value to set |
| 105 | */ |
| 106 | @Override |
| 107 | public void setParameterValueNotifyChangedAll(int dim, double value) { |
| 108 | throw new RuntimeException("Not implemented for wrapper."); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @return the name of this parameter |
| 113 | */ |
| 114 | @Override |
| 115 | public String getParameterName() { |
| 116 | return "useful name"; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Adds new bounds to this parameter |
| 121 | * |
| 122 | * @param bounds to add |
| 123 | */ |
| 124 | @Override |
| 125 | public void addBounds(Bounds<Double> bounds) { |
| 126 | throw new RuntimeException("Not implemented for wrapper."); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @return the intersection of all bounds added to this parameter |
| 131 | */ |
| 132 | @Override |
| 133 | public Bounds<Double> getBounds() { |
| 134 | throw new RuntimeException("Not implemented for wrapper."); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Adds an extra dimension at the given index |
| 139 | * |
| 140 | * @param index Index of the dimension to add |
| 141 | * @param value value to save at end of new array |
| 142 | */ |
| 143 | @Override |
| 144 | public void addDimension(int index, double value) { |
| 145 | throw new RuntimeException("Not implemented for wrapper."); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Removes the specified dimension from parameter |
| 150 | * |
| 151 | * @param index Index of dimension to lose |
| 152 | * @return the value of the dimension removed |
| 153 | */ |
| 154 | @Override |
| 155 | public double removeDimension(int index) { |
| 156 | throw new RuntimeException("Not implemented for wrapper."); |
| 157 | } |
| 158 | |
| 159 | private final MarkovModulatedSubstitutionModel mmSubstModel; |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * The model has changed. The model firing the event can optionally |
| 164 | * supply a reference to an object and an index if appropriate. Use |
| 165 | * of this extra information will be contingent on recognising what |
| 166 | * model it was that fired the event. |
| 167 | */ |
| 168 | @Override |
| 169 | public void modelChangedEvent(Model model, Object object, int index) { |
| 170 | if (model == mmSubstModel) { // TODO limit to passing along only exposed value changes |
| 171 | fireParameterChangedEvent(); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * The model has been restored. |
| 177 | * Required only for notification of non-models (say pure likelihoods) which depend on |
| 178 | * models. |
| 179 | * |
| 180 | * @param model |
| 181 | */ |
| 182 | @Override |
| 183 | public void modelRestored(Model model) { |
| 184 | // Do nothing |
| 185 | } |
| 186 | } |