public double proposeDiscreteValue(
     QuietRealParameter proposal,
     double oldValue,
     ConditionalCategoricalDistribution distr,
     double upper,
     double lower) {
   int oldModel = (int) oldValue;
   double newValue =
       Randomizer.randomChoicePDF(distr.conditionalDensities(oldModel)) + distr.getOffset();
   proposal.setValueQuietly(0, newValue);
   proposal.setBounds(lower, upper);
   return distr.logConditionalDensity(oldModel, (int) newValue);
 }
  public double proposeNewValueInLogSpace(
      QuietRealParameter proposal,
      double oldValue,
      ParametricDistribution distr,
      double upper,
      double lower)
      throws Exception {
    double sampleVal = distr.sample(1)[0][0];
    double newValue = Math.exp(sampleVal + Math.log(oldValue));
    proposal.setValueQuietly(0, newValue);
    proposal.setBounds(lower, upper);

    return distr.calcLogP(new QuietRealParameter(new Double[] {sampleVal})) - Math.log(newValue);
  }
  public double proposalValueInLogSpace(
      QuietRealParameter proposal,
      double oldValue,
      ParametricDistribution distr,
      double upper,
      double lower)
      throws Exception {

    double sampleVal = distr.sample(1)[0][0];
    double newValue = Math.exp(sampleVal + Math.log(oldValue));
    proposal.setValueQuietly(0, newValue);
    proposal.setBounds(lower, upper);

    /*System.out.println("oldValue: "+oldValue+", newVal: "+newValue+", logpdf: "+(distr.calcLogP(new QuietRealParameter(new Double[]{sampleVal}))-Math.log(newValue)));
    System.out.println("sampleValue: "+sampleVal);
    System.out.println(distr.calcLogP(new QuietRealParameter(new Double[]{sampleVal})));*/

    // System.out.println(oldValue+" "+newValue);
    return distr.calcLogP(new QuietRealParameter(new Double[] {sampleVal})) - Math.log(newValue);
  }
Exemplo n.º 4
0
  protected double proposeNewFreqValues(
      QuietRealParameter proposal,
      Double[] oldValues,
      DirichletDistribution distr,
      double upper,
      double lower)
      throws Exception {

    // System.out.println(parameterList.getParameter(categoryIndex));

    Double[] newValues = DirichletDistribution.nextDirichletScale(oldValues, distr.getScaleValue());
    for (int i = 0; i < newValues.length; i++) {
      proposal.setValueQuietly(i, newValues[i]);
    }
    proposal.setBounds(lower, upper);

    int validCount = 0;
    // while(validCount < 4){
    validCount = 0;
    for (double newVal : newValues) {
      if (newVal == 0.0) {
        break;
      } else {
        validCount++;
      }
    }
    if (validCount < 4) {
      return Double.NEGATIVE_INFINITY;
    }

    // }

    if (Double.isNaN(DirichletDistribution.logPDF(newValues, oldValues, distr.getScaleValue()))
        || Double.NEGATIVE_INFINITY
            == (DirichletDistribution.logPDF(newValues, oldValues, distr.getScaleValue()))) {
      throw new RuntimeException("Crap");
    }

    return DirichletDistribution.logPDF(newValues, oldValues, distr.getScaleValue());
  }