/* * CRPClusterRandomWalkOperator.java * * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard * * This file is part of BEAST. * See the NOTICE file distributed with this work for additional * information regarding copyright ownership and licensing. * * BEAST is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * BEAST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with BEAST; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ package dr.evomodel.antigenic; import dr.inference.model.*; import dr.inference.operators.*; import dr.math.MathUtils; import dr.xml.*; import java.util.logging.Logger; import dr.inference.model.Parameter; /** * Created with IntelliJ IDEA. * User: Gabi * Date: 2/2/15 * Time: 11:15 PM * To change this template use File | Settings | File Templates. */ public class CRPClusterRandomWalkOperator extends AbstractAdaptableOperator { public static final String WINDOW_SIZE = "windowSize"; public static final String VIRUS_LOCATIONS = "virusLocations"; public static final String CLUSTER_ASSIGNMENTS = "clusterAssignments"; public static final String CRP_CLUSTER_RW_OPERATOR= "CRPClusterRandomWalkOperator"; private final MatrixParameter virusLocations; private final Parameter assignments; private double windowSize; public CRPClusterRandomWalkOperator( Parameter assignments, MatrixParameter virusLocations,double windowSize, double weight){ super(AdaptationMode.ADAPTATION_ON); this.virusLocations=virusLocations; this.windowSize = windowSize; this.assignments=assignments; setWeight(weight); } public double doOperation() { int max = findMax(assignments); int group = MathUtils.nextInt(max+1); if (windowSize>50){ windowSize=50; } double draw0 = (2.0 * MathUtils.nextDouble() - 1.0) * windowSize; double draw1 = (2.0 * MathUtils.nextDouble() - 1.0) * windowSize; for (int i = 0; imax){ max = (int) assignments.getParameterValue(i); } } return max; } private void printInformation(double[] par, int length) { StringBuffer sb = new StringBuffer("\n \n double vector \n"); for(int j=0; j