コード例 #1
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          Parameter weights = (Parameter) xo.getChild(Parameter.class);
          List<AbstractModelLikelihood> likelihoodList = new ArrayList<AbstractModelLikelihood>();

          for (int i = 0; i < xo.getChildCount(); i++) {
            if (xo.getChild(i) instanceof Likelihood)
              likelihoodList.add((AbstractModelLikelihood) xo.getChild(i));
          }

          if (weights.getDimension() != likelihoodList.size()) {
            throw new XMLParseException(
                "Dim of " + weights.getId() + " does not match the number of likelihoods");
          }

          if (xo.hasAttribute(NORMALIZE)) {
            if (xo.getBooleanAttribute(NORMALIZE)) {
              double sum = 0;
              for (int i = 0; i < weights.getDimension(); i++) sum += weights.getParameterValue(i);
              for (int i = 0; i < weights.getDimension(); i++)
                weights.setParameterValue(i, weights.getParameterValue(i) / sum);
            }
          }

          if (!normalized(weights))
            throw new XMLParseException(
                "Parameter +" + weights.getId() + " must lie on the simplex");

          return new WeightedMixtureModel(likelihoodList, weights);
        }
コード例 #2
0
  /**
   * construct an instance of a parameter type that has a name. the value of {@code params} should
   * not contain a <em>null</em> instance, which is not a valid input when creating a {@link
   * Parameter}.
   *
   * @param name name of the parameter.
   * @param params parameters that will compose the parameters.
   * @return a new {@code Parameter} instance.
   */
  public static Parameter makeNamedParameter(String name, Object... params) {
    final Parameter param = new SingleValueParameter(name);

    for (Object each : params) {
      param.setParameterValue(each, discoverClass(each));
    }
    return param;
  }
コード例 #3
0
  public static void main(String[] args) {

    final double l1 = -10;
    final double l2 = -2;

    AbstractModelLikelihood like1 =
        new AbstractModelLikelihood("dummy") {

          public Model getModel() {
            return null;
          }

          public double getLogLikelihood() {
            return l1;
          }

          public void makeDirty() {}

          public String prettyName() {
            return null;
          }

          public boolean isUsed() {
            return false;
          }

          @Override
          protected void handleModelChangedEvent(Model model, Object object, int index) {}

          @Override
          protected void handleVariableChangedEvent(
              Variable variable, int index, Variable.ChangeType type) {}

          @Override
          protected void storeState() {}

          @Override
          protected void restoreState() {}

          @Override
          protected void acceptState() {}

          public void setUsed() {}

          public LogColumn[] getColumns() {
            return new LogColumn[0];
          }

          public String getId() {
            return null;
          }

          public void setId(String id) {}
        };

    AbstractModelLikelihood like2 =
        new AbstractModelLikelihood("dummy") {

          public Model getModel() {
            return null;
          }

          public double getLogLikelihood() {
            return l2;
          }

          public void makeDirty() {}

          public String prettyName() {
            return null;
          }

          public boolean isUsed() {
            return false;
          }

          @Override
          protected void handleModelChangedEvent(Model model, Object object, int index) {}

          @Override
          protected void handleVariableChangedEvent(
              Variable variable, int index, Variable.ChangeType type) {}

          @Override
          protected void storeState() {}

          @Override
          protected void restoreState() {}

          @Override
          protected void acceptState() {}

          public void setUsed() {}

          public LogColumn[] getColumns() {
            return new LogColumn[0];
          }

          public String getId() {
            return null;
          }

          public void setId(String id) {}
        };

    List<AbstractModelLikelihood> likelihoodList = new ArrayList<AbstractModelLikelihood>();
    likelihoodList.add(like1);
    likelihoodList.add(like2);

    Parameter weights = new Parameter.Default(2);
    double p1 = 0.05;
    weights.setParameterValue(0, p1);
    weights.setParameterValue(1, 1.0 - p1);

    WeightedMixtureModel mixture = new WeightedMixtureModel(likelihoodList, weights);
    System.err.println("getLogLikelihood() = " + mixture.getLogLikelihood());

    double test = Math.log(p1 * Math.exp(l1) + (1.0 - p1) * Math.exp(l2));
    System.err.println("correct            = " + test);
  }
コード例 #4
0
  public MixtureModelBranchRates(
      TreeModel tree,
      Parameter rateCategoryQuantilesParameter,
      ParametricDistributionModel[] models,
      Parameter distributionIndexParameter,
      boolean useQuantilesForRates,
      boolean normalize,
      double normalizeBranchRateTo) {
    super(MixtureModelBranchRatesParser.MIXTURE_MODEL_BRANCH_RATES);

    this.useQuantilesForRates = useQuantilesForRates;

    this.rateCategoryQuantiles =
        new TreeParameterModel(tree, rateCategoryQuantilesParameter, false);

    rates = new double[tree.getNodeCount()];

    this.normalize = normalize;

    this.treeModel = tree;
    this.distributionModels = models;
    this.normalizeBranchRateTo = normalizeBranchRateTo;

    this.tree = new SimpleTree(tree);

    this.distributionIndexParameter = distributionIndexParameter;
    addVariable(this.distributionIndexParameter);

    // Force the boundaries of rateCategoryParameter to match the category count
    // d Parameter.DefaultBounds bound = new Parameter.DefaultBounds(categoryCount - 1, 0,
    // rateCategoryParameter.getDimension());
    // d rateCategoryParameter.addBounds(bound);
    // rateCategoryQuantilesParameter.;

    Parameter.DefaultBounds bound =
        new Parameter.DefaultBounds(1.0, 0.0, rateCategoryQuantilesParameter.getDimension());
    rateCategoryQuantilesParameter.addBounds(bound);

    Parameter.DefaultBounds bound2 = new Parameter.DefaultBounds(models.length, 0.0, 1);
    distributionIndexParameter.addBounds(bound2);
    distributionIndexParameter.setParameterValue(0, 0);

    // Parameter distributionIndexParameter;

    for (ParametricDistributionModel distributionModel : distributionModels) {
      addModel(distributionModel);
    }
    // AR - commented out: changes to the tree are handled by model changed events fired by
    // rateCategories
    //        addModel(tree);
    // d addModel(rateCategories);

    addModel(rateCategoryQuantiles);

    // addModel(treeModel); // Maybe
    // AR - commented out: changes to rateCategoryParameter are handled by model changed events
    // fired by rateCategories
    //        addVariable(rateCategoryParameter);

    if (normalize) {
      tree.addModelListener(
          new ModelListener() {

            public void modelChangedEvent(Model model, Object object, int index) {
              computeFactor();
            }

            public void modelRestored(Model model) {
              computeFactor();
            }
          });
    }

    setupRates();
  }