Projects >> blog >>113d96efef755fd5527c8364daa52ae46dfebd4f

Chunk
Conflicting content
import java.util.LinkedList;
import java.util.List;
<<<<<<< HEAD
=======

import blog.model.Type;
>>>>>>> 57f377a222eed2c448fa03daa5f51050e18fb984

/**
 * A Beta distribution with shape parameters a and b, defined by f(x) =(x^(a-1)
Solution content
import java.util.LinkedList;
import java.util.List;

import blog.model.Type;

/**
 * A Beta distribution with shape parameters a and b, defined by f(x) =(x^(a-1)
File
Beta.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
<<<<<<< HEAD

    gammaA = new Gamma(a, 1);
    gammaB = new Gamma(b, 1);
  }
  /**
   * Returns the probability of value under this distribution.
   */
  public double getProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      return ((Math.pow(x, (a - 1)) * Math.pow((1 - x), (b - 1))) / beta(a, b));
    }
  }

  /**
   * Returns the log of the probability of value under this distribution.
   */
  public double getLogProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      return (((a - 1) * Math.log(x)) + ((b - 1) * Math.log(1 - x)) - Math
          .log(beta(a, b)));
    }
  }

  /**
   * Returns a double sampled according to this distribution. Takes time
   * equivalent to the distrib.Gamma sampling function. (Reference: A Guide To
   * Simulation, 2nd Ed. Bratley, Paul, Bennett L. Fox and Linus E. Schrage.)
   */
  public Object sampleVal(List args) {
    LinkedList l = new LinkedList();
    double y = ((Double) gammaA.sampleVal(l)).doubleValue();
    double z = ((Double) gammaB.sampleVal(l)).doubleValue();
    return new Double(y / (y + z));
  }

  /**
   * Returns the Beta function of reals a and b B(a,b) = Gamma(a)Gamma(b) /
   * Gamma(a+b) Reference: Numerical Recipes in C
   * http://www.library.cornell.edu/nr/cbookcpdf.html
   */
  public static double beta(double a, double b) {
    return ((Gamma.gamma(a) * Gamma.gamma(b)) / Gamma.gamma(a + b));
  }

  public String toString() {
    return getClass().getName();
  }

  private double a;
  private double b;
  private Gamma gammaA;
  private Gamma gammaB;

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#setParams(java.util.List)
   */
  @Override
  public void setParams(List params) {
    // TODO Auto-generated method stub

  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getProb(java.lang.Object)
   */
  @Override
  public double getProb(Object value) {
    // TODO Auto-generated method stub
    return 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getLogProb(java.lang.Object)
   */
  @Override
  public double getLogProb(Object value) {
    // TODO Auto-generated method stub
    return 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#sampleVal()
   */
  @Override
  public Object sampleVal() {
    // TODO Auto-generated method stub
    return null;
  }
=======

  /**
   * Returns the probability of value under this distribution.
   */
  public double getProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      return ((Math.pow(x, (a - 1)) * Math.pow((1 - x), (b - 1))) / beta(a, b));
    }
  }

  /**
   * Returns the log of the probability of value under this distribution.
   */
  public double getLogProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      double t1 = 0;
      double t2 = 0;
      if (a != 1) {
        t1 = (a - 1) * Math.log(x);
      }
      if (b != 1) {
        t2 = (b - 1) * Math.log(1 - x);
      }
      return t1 + t2 - Math.log(beta(a, b));
    }
  }

  /**
   * Returns a double sampled according to this distribution. Takes time
   * equivalent to the distrib.Gamma sampling function. (Reference: A Guide To
   * Simulation, 2nd Ed. Bratley, Paul, Bennett L. Fox and Linus E. Schrage.)
   */
  public Object sampleVal(List args, Type childType) {
    LinkedList l = new LinkedList();
    double y = ((Double) gammaA.sampleVal(l, childType)).doubleValue();
    double z = ((Double) gammaB.sampleVal(l, childType)).doubleValue();
    return new Double(y / (y + z));
  }

  /**
   * Returns the Beta function of reals a and b B(a,b) = Gamma(a)Gamma(b) /
   * Gamma(a+b) Reference: Numerical Recipes in C
   * http://www.library.cornell.edu/nr/cbookcpdf.html
   */
  public static double beta(double a, double b) {
    return ((Gamma.gamma(a) * Gamma.gamma(b)) / Gamma.gamma(a + b));
  }

  public String toString() {
    return getClass().getName();
  }

  private double a;
  private double b;
  private Gamma gammaA;
  private Gamma gammaB;
>>>>>>> 57f377a222eed2c448fa03daa5f51050e18fb984
}
Solution content
  /**
    gammaA = new Gamma(a, 1);
    gammaB = new Gamma(b, 1);
  }

   * Returns the probability of value under this distribution.
   */
  public double getProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      return ((Math.pow(x, (a - 1)) * Math.pow((1 - x), (b - 1))) / beta(a, b));
    }
  }

  /**
   * Returns the log of the probability of value under this distribution.
   */
  public double getLogProb(List args, Object value) {
    if (!(value instanceof Number)) {
      throw new IllegalArgumentException(
          "Beta CPD defines a distribution over objects"
              + " of class Number, not " + value.getClass() + ".");
    } else {
      double x = ((Number) value).doubleValue();
      double t1 = 0;
      double t2 = 0;
      if (a != 1) {
        t1 = (a - 1) * Math.log(x);
      }
      if (b != 1) {
        t2 = (b - 1) * Math.log(1 - x);
      }
      return t1 + t2 - Math.log(beta(a, b));
    }
  }

  /**
   * Returns a double sampled according to this distribution. Takes time
   * equivalent to the distrib.Gamma sampling function. (Reference: A Guide To
   * Simulation, 2nd Ed. Bratley, Paul, Bennett L. Fox and Linus E. Schrage.)
   */
  public Object sampleVal(List args, Type childType) {
    LinkedList l = new LinkedList();
    double y = ((Double) gammaA.sampleVal(l, childType)).doubleValue();
    double z = ((Double) gammaB.sampleVal(l, childType)).doubleValue();
    return new Double(y / (y + z));
  }

  /**
   * Returns the Beta function of reals a and b B(a,b) = Gamma(a)Gamma(b) /
   * Gamma(a+b) Reference: Numerical Recipes in C
   * http://www.library.cornell.edu/nr/cbookcpdf.html
   */
  public static double beta(double a, double b) {
    return ((Gamma.gamma(a) * Gamma.gamma(b)) / Gamma.gamma(a + b));
  }

  public String toString() {
    return getClass().getName();
  }

  private double a;
  private double b;
  private Gamma gammaA;
  private Gamma gammaB;

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#setParams(java.util.List)
   */
  @Override
  public void setParams(List params) {
    // TODO Auto-generated method stub

  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getProb(java.lang.Object)
   */
  @Override
  public double getProb(Object value) {
    // TODO Auto-generated method stub
    return 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getLogProb(java.lang.Object)
   */
  @Override
  public double getLogProb(Object value) {
    // TODO Auto-generated method stub
    return 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#sampleVal()
   */
  @Override
  public Object sampleVal() {
    // TODO Auto-generated method stub
    return null;
  }
}
File
Beta.java
Developer's decision
Combination
Kind of conflict
Annotation
Attribute
Comment
Method declaration
Chunk
Conflicting content
package blog.distrib;

import java.util.List;
<<<<<<< HEAD

import blog.common.Util;

=======

import blog.common.Util;
import blog.model.Type;

>>>>>>> 57f377a222eed2c448fa03daa5f51050e18fb984
/**
 * A geometric distribution over the natural numbers 0, 1, 2,... It has a single
 * parameter alpha, which equals the probability of a success trial. Thus an
Solution content
package blog.distrib;

import java.util.List;

import blog.common.Util;
import blog.model.Type;

/**
 * A geometric distribution over the natural numbers 0, 1, 2,... It has a single
 * parameter alpha, which equals the probability of a success trial. Thus an
File
Geometric.java
Developer's decision
Version 2
Kind of conflict
Import