package dr.evomodel.antigenic.phyloclustering.misc.obsolete; import dr.evomodel.antigenic.NPAntigenicLikelihood; import dr.inference.model.Likelihood; import dr.inference.model.MatrixParameter; import dr.inference.model.Parameter; import dr.inference.operators.MCMCOperator; import dr.inference.operators.SimpleMCMCOperator; import dr.math.MathUtils; import dr.xml.*; public class ClusterOperator extends SimpleMCMCOperator { public final static String CLUSTER_OPERATOR = "clusterOperator"; public static final String WINDOW_SIZE = "windowSize"; public NPAntigenicLikelihood modelLikelihood; private Parameter assignments = null; private Parameter links = null; private MatrixParameter virusLocations = null; private double windowSize = 1; public ClusterOperator(Parameter assignments, MatrixParameter virusLocations, double weight, double windowSize, NPAntigenicLikelihood Likelihood, Parameter links) { //System.out.println("Constructor"); this.links = links; this.assignments = assignments; this.virusLocations = virusLocations; this.windowSize = windowSize; this.modelLikelihood = Likelihood; setWeight(weight); //load in the virusLocations System.out.println((int)assignments.getParameterValue(0)); Parameter vLoc = virusLocations.getParameter(0); //double d0= vLoc.getParameterValue(0); //double d1= vLoc.getParameterValue(1); //System.out.println( d0 + "," + d1); //System.exit(0); } //assume no boundary /** * change the parameter and return the hastings ratio. */ public final double doOperation() { double moveWholeClusterOrChangeOnePoint = MathUtils.nextDouble(); //double moveWholeClusterProb = 0.2; double moveWholeClusterProb = 0.5; int numSamples = assignments.getDimension(); // if(moveWholeClusterOrChangeOnePoint getMaximumAcceptanceLevel()) { return ""; } else { return ""; } } public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { public final static String ASSIGNMENTS = "assignments"; public final static String VIRUS_LOCATIONS = "virusLocations"; public final static String LIKELIHOOD = "likelihood"; public final static String LINKS = "links"; public String getParserName() { return CLUSTER_OPERATOR; } /* (non-Javadoc) * @see dr.xml.AbstractXMLObjectParser#parseXMLObject(dr.xml.XMLObject) */ public Object parseXMLObject(XMLObject xo) throws XMLParseException { double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); // double windowSize = xo.getDoubleAttribute(WINDOW_SIZE); XMLObject cxo = xo.getChild(ASSIGNMENTS); Parameter assignments = (Parameter) cxo.getChild(Parameter.class); MatrixParameter virusLocationsParameter = null; if (xo.hasChildNamed(VIRUS_LOCATIONS)) { virusLocationsParameter = (MatrixParameter) xo.getElementFirstChild(VIRUS_LOCATIONS); } cxo = xo.getChild(LINKS); Parameter links = (Parameter) cxo.getChild(Parameter.class); cxo = xo.getChild(LIKELIHOOD); NPAntigenicLikelihood likelihood = (NPAntigenicLikelihood)cxo.getChild(NPAntigenicLikelihood.class); //set window size to be 1 return new ClusterOperator(assignments, virusLocationsParameter, weight, 1.0, likelihood, links); // public ClusterOperator(Parameter assignments, MatrixParameter virusLocations, double weight, double windowSize, NPAntigenicLikelihood Likelihood, Parameter links) { } //************************************************************************ // AbstractXMLObjectParser implementation //************************************************************************ public String getParserDescription() { return "An operator that picks a new allocation of an item to a cluster under the Dirichlet process."; } public Class getReturnType() { return ClusterOperator.class; } public XMLSyntaxRule[] getSyntaxRules() { return rules; } private final XMLSyntaxRule[] rules = { AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), // AttributeRule.newDoubleRule(WINDOW_SIZE), new ElementRule(ASSIGNMENTS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), new ElementRule(VIRUS_LOCATIONS, MatrixParameter.class, "Parameter of locations of all virus"), new ElementRule(LINKS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), new ElementRule(LIKELIHOOD, new XMLSyntaxRule[] { new ElementRule(Likelihood.class),}, true), }; }; public int getStepCount() { return 1; } }