Search in sources :

Example 51 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class MultipleRandomWalkIntegerOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double w = xo.getDoubleAttribute(RandomWalkIntegerOperatorParser.WINDOW_SIZE);
    if (w != Math.floor(w)) {
        throw new XMLParseException("The window size of a randomWalkIntegerOperator should be an integer");
    }
    double s = xo.getDoubleAttribute(SAMPLE_SIZE);
    if (s != Math.floor(s)) {
        throw new XMLParseException("The window size of a randomWalkIntegerOperator should be an integer");
    }
    int windowSize = (int) w;
    int sampleSize = (int) s;
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    return new MultipleRandomWalkIntegerOperator(parameter, windowSize, sampleSize, weight);
}
Also used : MultipleRandomWalkIntegerOperator(dr.inference.operators.MultipleRandomWalkIntegerOperator) Parameter(dr.inference.model.Parameter)

Example 52 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class SelectorOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final SelectorOperator op = new SelectorOperator(parameter);
    op.setWeight(weight);
    return op;
}
Also used : Parameter(dr.inference.model.Parameter) SelectorOperator(dr.inference.operators.SelectorOperator)

Example 53 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class SetOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double[] values = xo.getDoubleArrayAttribute(SET);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    System.out.println("Creating set operator for parameter " + parameter.getParameterName());
    System.out.print("  set = {" + values[0]);
    for (int i = 1; i < values.length; i++) {
        System.out.print(", " + values[i]);
    }
    System.out.println("}");
    SetOperator operator = new SetOperator(parameter, values);
    operator.setWeight(weight);
    return operator;
}
Also used : SetOperator(dr.inference.operators.SetOperator) Parameter(dr.inference.model.Parameter)

Example 54 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class ClusterWalkOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double windowSize = xo.getDoubleAttribute(WINDOW_SIZE);
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    Double lower = null;
    Double upper = null;
    if (xo.hasAttribute(LOWER)) {
        lower = xo.getDoubleAttribute(LOWER);
    }
    if (xo.hasAttribute(UPPER)) {
        upper = xo.getDoubleAttribute(UPPER);
    }
    ClusterWalkOperator.BoundaryCondition condition = ClusterWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, ClusterWalkOperator.BoundaryCondition.reflecting.name()));
    if (xo.hasChildNamed(UPDATE_INDEX)) {
        XMLObject cxo = xo.getChild(UPDATE_INDEX);
        Parameter updateIndex = (Parameter) cxo.getChild(Parameter.class);
        if (updateIndex.getDimension() != parameter.getDimension())
            throw new RuntimeException("Parameter to update and missing indices must have the same dimension");
        return new ClusterWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode, lower, upper);
    }
    return new ClusterWalkOperator(parameter, null, windowSize, condition, weight, mode, lower, upper);
}
Also used : Parameter(dr.inference.model.Parameter) CoercionMode(dr.inference.operators.CoercionMode)

Example 55 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class TreeClusterAlgorithmOperator method test2.

private void test2() {
    System.out.print("  [");
    for (int i = 0; i < numNodes; i++) {
        if ((int) indicators.getParameterValue(i) == 1) {
            System.out.print(i + " ");
        }
    }
    System.out.println("]");
    //indicators.setParameterValue( 436, 0);
    //indicators.setParameterValue( 549, 0);
    //   	indicators.setParameterValue( 615, 0);   
    //indicators.setParameterValue(648,0);
    //indicators.setParameterValue(673,0);
    //indicators.setParameterValue(794,0);
    //indicators.setParameterValue(785,0);
    //indicators.setParameterValue(690,0);
    //Note: if 615 is not turned on, 604 would be much superior to 605.
    //since I changed indicators.. should do this before calculating the original likelihood
    //1. Update the cluster labels, after the breakpoints and status parameters may have changed.
    //  		setClusterLabelsUsingIndicators();
    //setClusterLabelsArray(newClusterLabelArray);	
    //relabelClusterLabelsArray(newClusterLabelArray, oldClusterLabelArray);
    //convertClusterLabelsArrayToParameter( newClusterLabelArray);
    //oldClusterLabelArray = newClusterLabelArray; //the oldClusterLabelArray gets the current labels, so next time this is updated.
    //2. Update the virus locations (and offsets), given ...
    Tree_Clustering_Shared_Routines.updateUndriftedVirusLocations(numNodes, numdata, treeModel, virusLocationsTreeNode, indicators, mu, virusLocations, correspondingTreeIndexForVirus);
    //setVirusLocationAutoCorrelatedModel(); //set virus locations, given the breakpoints,status, and mu parameters
    double originalLikelihood = clusterLikelihood.getLogLikelihood();
    System.out.println("originalLikelihood = " + originalLikelihood);
    int originalNode1 = 605;
    int[] distance = determineTreeNeighborhood(originalNode1, 5);
    for (int g = 0; g < distance.length; g++) {
        if (distance[g] < 5 && distance[g] > 0) {
            int newNode = g;
            System.out.print(g + " distance=" + distance[g] + "\t");
            if ((int) indicators.getParameterValue(newNode) == 1) {
                System.out.print("Node already on!!!\n");
            } else {
                indicators.setParameterValue(originalNode1, 0);
                indicators.setParameterValue(newNode, 1);
                //Flip mu - so the neighbor that replaces the original node now also inherits the existing node's mu
                //Parameter originalNodeMu = mu.getParameter(originalNode1+1); //offset of 1
                Parameter originalNodeMu = mu.getParameter(originalNode1);
                double[] tmp = originalNodeMu.getParameterValues();
                //Parameter newMu = mu.getParameter(newNode+1); //offset of 1
                Parameter newMu = mu.getParameter(newNode);
                double[] tmpNew = newMu.getParameterValues();
                originalNodeMu.setParameterValue(0, tmpNew[0]);
                originalNodeMu.setParameterValue(1, tmpNew[1]);
                newMu.setParameterValue(0, tmp[0]);
                newMu.setParameterValue(1, tmp[1]);
                //1. Update the cluster labels, after the breakpoints and status parameters may have changed.
                //		setClusterLabelsUsingIndicators();
                //setClusterLabelsArray(newClusterLabelArray);	
                //relabelClusterLabelsArray(newClusterLabelArray, oldClusterLabelArray);
                //convertClusterLabelsArrayToParameter( newClusterLabelArray);
                //oldClusterLabelArray = newClusterLabelArray; //the oldClusterLabelArray gets the current labels, so next time this is updated.
                //2. Update the virus locations (and offsets), given ...
                Tree_Clustering_Shared_Routines.updateUndriftedVirusLocations(numNodes, numdata, treeModel, virusLocationsTreeNode, indicators, mu, virusLocations, correspondingTreeIndexForVirus);
                //setVirusLocationAutoCorrelatedModel(); //set virus locations, given the breakpoints,status, and mu parameters
                double testLikelihood = clusterLikelihood.getLogLikelihood();
                double diff = testLikelihood - originalLikelihood;
                if (diff > -10) {
                    System.out.print("***");
                }
                System.out.println("logL= " + testLikelihood + " and diff = " + diff);
                // 	System.out.print("  [");
                //	for(int i=0; i < numNodes; i++){
                //		if( (int)indicators.getParameterValue(i) == 1){
                //			System.out.print(i + " ");
                //		}
                //}
                //System.out.println("]");
                //revert back
                indicators.setParameterValue(originalNode1, 1);
                indicators.setParameterValue(newNode, 0);
                originalNodeMu.setParameterValue(0, tmp[0]);
                originalNodeMu.setParameterValue(1, tmp[1]);
                newMu.setParameterValue(0, tmpNew[0]);
                newMu.setParameterValue(1, tmpNew[1]);
            }
        }
    }
    System.exit(0);
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) Parameter(dr.inference.model.Parameter)

Aggregations

Parameter (dr.inference.model.Parameter)397 TreeModel (dr.evomodel.tree.TreeModel)62 MatrixParameter (dr.inference.model.MatrixParameter)46 ArrayList (java.util.ArrayList)44 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)43 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)41 Units (dr.evolution.util.Units)36 XMLUnits (dr.evoxml.util.XMLUnits)36 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)30 Tree (dr.evolution.tree.Tree)25 DataType (dr.evolution.datatype.DataType)24 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)23 CompoundParameter (dr.inference.model.CompoundParameter)23 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)21 SitePatterns (dr.evolution.alignment.SitePatterns)20 HKY (dr.evomodel.substmodel.nucleotide.HKY)17 Likelihood (dr.inference.model.Likelihood)17 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)16 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)16 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)16