/**
   * Returns the empirical Bayes estimate of a single value.
   *
   * @param x the value
   * @return the empirical Bayes estimate
   */
  public double empiricalBayesEstimate(double x) {
    if (Math.abs(x) > 10) return x; // pratical consideration; modify later
    DoubleVector d = Maths.dnormLog(x, mixingDistribution.getPointValues(), 1);

    d.minusEquals(d.max());
    d = d.map("java.lang.Math", "exp");
    d.timesEquals(mixingDistribution.getFunctionValues());
    return mixingDistribution.getPointValues().innerProduct(d) / d.sum();
  }
Exemple #2
0
  /**
   * Computes the value of h(x) / f(x) given the mixture. The implementation avoided overflow.
   *
   * @param AHat the value
   * @return the value of h(x) / f(x)
   */
  public double hf(double AHat) {

    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();

    double x = Math.sqrt(AHat);
    DoubleVector mean = points.sqrt();
    DoubleVector d1 = Maths.dnormLog(x, mean, 1);
    double d1max = d1.max();
    d1.minusEquals(d1max);
    DoubleVector d2 = Maths.dnormLog(-x, mean, 1);
    d2.minusEquals(d1max);

    d1 = d1.map("java.lang.Math", "exp");
    d1.timesEquals(values);
    d2 = d2.map("java.lang.Math", "exp");
    d2.timesEquals(values);

    return ((points.minus(x / 2)).innerProduct(d1) - (points.plus(x / 2)).innerProduct(d2))
        / (d1.sum() + d2.sum());
  }
  /**
   * Computes the value of h(x) / f(x) given the mixture. The implementation avoided overflow.
   *
   * @param x the value
   * @return the value of h(x) / f(x)
   */
  public double hf(double x) {
    DoubleVector points = mixingDistribution.getPointValues();
    DoubleVector values = mixingDistribution.getFunctionValues();

    DoubleVector d = Maths.dnormLog(x, points, 1);
    d.minusEquals(d.max());

    d = (DoubleVector) d.map("java.lang.Math", "exp");
    d.timesEquals(values);

    return ((DoubleVector) points.times(2 * x).minusEquals(x * x)).innerProduct(d) / d.sum();
  }