Calculates the probability from 0 to X under Beta Distribution

@param x
@param a
@param b
@return
166764
public static double betaCdf(double x, double a, double b) {
        if(x<0 || a<=0 || b<=0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        
        double Bcdf = 0.0;
        
        if(x==0) {
            return Bcdf;
        }
        else if (x>=1) {
            Bcdf=1.0;
            return Bcdf;
        }
        
        double S= a + b;

        double BT = Math.exp(logGamma(S)-logGamma(b)-logGamma(a)+a*Math.log(x)+b*Math.log(1-x));
        if (x<(a+1.0)/(S+2.0)) {
            Bcdf=BT*betinc(x,a,b);
        } 
        else {
            Bcdf=1.0-BT*betinc(1.0-x,b,a);
        }

        return Bcdf;
    }
1028944
public static final DoubleMatrix1D zMult(final DoubleMatrix2D A, final DoubleMatrix1D b, final double beta){
		if(A.columns() != b.size()){
			throw new IllegalArgumentException("wrong matrices dimensions");
		}
		final DoubleMatrix1D ret = DoubleFactory1D.dense.make(A.rows());

		if(A instanceof SparseDoubleMatrix2D){
			//sparse matrix
			A.forEachNonZero(new IntIntDoubleFunction() {
				@Override
				public double apply(int i, int j, double Aij) {
					double vi = 0;
					vi += Aij * b.getQuick(j);
					ret.setQuick(i, ret.getQuick(i) + beta * vi);
					return Aij;
				}
			});
		}else{
			//dense matrix
			for(int i=0; i<A.rows(); i++){
				double vi = 0;
				for(int j=0; j<A.columns(); j++){
					vi += A.getQuick(i, j) * b.getQuick(j);
				}
				ret.setQuick(i, beta * vi);
			}
		}

		return ret;
	}
622485
static
	public double probability(ContinuousDistribution distribution, Number x){

		if(distribution instanceof GaussianDistribution){
			return probability((GaussianDistribution)distribution, x);
		} else

		if(distribution instanceof PoissonDistribution){
			return probability((PoissonDistribution)distribution, x);
		}

		throw new UnsupportedElementException(distribution);
	}
46633
public static double inverseRegularizedIncompleteBetaFunction(double alpha, double beta, double p) {
        final double EPS = 1.0E-8;

        double pp, t, u, err, x, al, h, w, afac;
        double a1 = alpha - 1.;
        double b1 = beta - 1.;

        if (p <= 0.0) {
            return 0.0;
        }

        if (p >= 1.0) {
            return 1.0;
        }

        if (alpha >= 1. && beta >= 1.) {
            pp = (p < 0.5) ? p : 1. - p;
            t = Math.sqrt(-2. * Math.log(pp));
            x = (2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t;
            if (p < 0.5) {
                x = -x;
            }
            al = (x * x - 3.) / 6.;
            h = 2. / (1. / (2. * alpha - 1.) + 1. / (2. * beta - 1.));
            w = (x * Math.sqrt(al + h) / h) - (1. / (2. * beta - 1) - 1. / (2. * alpha - 1.)) * (al + 5. / 6. - 2. / (3. * h));
            x = alpha / (alpha + beta * Math.exp(2. * w));
        } else {
            double lna = Math.log(alpha / (alpha + beta));
            double lnb = Math.log(beta / (alpha + beta));
            t = Math.exp(alpha * lna) / alpha;
            u = Math.exp(beta * lnb) / beta;
            w = t + u;
            if (p < t / w) {
                x = Math.pow(alpha * w * p, 1. / alpha);
            } else {
                x = 1. - Math.pow(beta * w * (1. - p), 1. / beta);
            }
        }
        afac = -Gamma.lgamma(alpha) - Gamma.lgamma(beta) + Gamma.lgamma(alpha + beta);
        for (int j = 0; j < 10; j++) {
            if (x == 0. || x == 1.) {
                return x;
            }
            err = regularizedIncompleteBetaFunction(alpha, beta, x) - p;
            t = Math.exp(a1 * Math.log(x) + b1 * Math.log(1. - x) + afac);
            u = err / t;
            x -= (t = u / (1. - 0.5 * Math.min(1., u * (a1 / x - b1 / (1. - x)))));
            if (x <= 0.) {
                x = 0.5 * (x + t);
            }
            if (x >= 1.) {
                x = 0.5 * (x + t + 1.);
            }
            if (Math.abs(t) < EPS * x && j > 0) {
                break;
            }
        }
        return x;
    }
111795
public double fBeta(double beta, int outputNum) {
        assertIndex(outputNum);
        double precision = precision(outputNum);
        double recall = recall(outputNum);
        return EvaluationUtils.fBeta(beta, precision, recall);
    }
635035
public static double pdf(double x, double k, double theta, double shift) {
    x = (x - shift);
    return x <= 0. ? 0. : FastMath.pow(theta, k) / GammaDistribution.gamma(k) * FastMath.pow(1 + x, -(theta + 1.)) * FastMath.pow(FastMath.log1p(x), k - 1.);
  }
1059091
public double computeOverlap( ImageRectangle a , ImageRectangle b ) {
		if( !a.intersection(b,work) )
			return 0;

		int areaI = work.area();

		int bottom = a.area() + b.area() - areaI;

		return areaI/ (double)bottom;
	}
1051817
private static double approxBinomialCdf(int k, double p, int n) {
        //use an approximation as described at http://www.math.ucla.edu/~tom/distributions/binomial.html
        double Z = p;
        double A=k+1;
        double B=n-k;
        double S=A+B;
        double BT=Math.exp(ContinuousDistributions.logGamma(S)-ContinuousDistributions.logGamma(B)-ContinuousDistributions.logGamma(A)+A*Math.log(Z)+B*Math.log(1-Z));
        
        double probabilitySum;
        if (Z<(A+1)/(S+2)) {
            probabilitySum=BT*ContinuousDistributions.betinc(Z,A,B);
        } 
        else {
            probabilitySum=1.0-BT*ContinuousDistributions.betinc(1.0-Z,B,A);
        }
        probabilitySum=1.0-probabilitySum;

        return probabilitySum;
    }
613068
private void doMutation(double probability, DoubleSolution solution) {
    double rnd, delta1, delta2, mutPow, deltaq;
    double y, yl, yu, val, xy;

    for (int i = 0; i < solution.getNumberOfVariables(); i++) {
      if (randomGenerator.getRandomValue() <= probability) {
        y = solution.getVariableValue(i);
        yl = solution.getLowerBound(i) ;
        yu = solution.getUpperBound(i) ;
        if (yl == yu) {
          y = yl ;
        } else {
          delta1 = (y - yl) / (yu - yl);
          delta2 = (yu - y) / (yu - yl);
          rnd = randomGenerator.getRandomValue();
          mutPow = 1.0 / (distributionIndex + 1.0);
          if (rnd <= 0.5) {
            xy = 1.0 - delta1;
            val = 2.0 * rnd + (1.0 - 2.0 * rnd) * (Math.pow(xy, distributionIndex + 1.0));
            deltaq = Math.pow(val, mutPow) - 1.0;
          } else {
            xy = 1.0 - delta2;
            val = 2.0 * (1.0 - rnd) + 2.0 * (rnd - 0.5) * (Math.pow(xy, distributionIndex + 1.0));
            deltaq = 1.0 - Math.pow(val, mutPow);
          }
          y = y + deltaq * (yu - yl);
          y = solutionRepair.repairSolutionVariableValue(y, yl, yu);
        }
        solution.setVariableValue(i, y);
      }
    }
  }
353075
@Override
  public GallicWeight times(GallicWeight a, GallicWeight b) {
    if (isZero(a) || isZero(b)) {
      return zero;
    }
    IntArrayList newOutputLabels = new IntArrayList();
    newOutputLabels.addAll(a.getLabels());
    newOutputLabels.addAll(b.getLabels());
    double newWeight = this.weightSemiring.times(a.getWeight(), b.getWeight());
    return GallicWeight.create(newOutputLabels, newWeight);
  }
360673
def betacf(a, b, x):
    
    ITMAX = 200
    EPS = 3.0e-7

    bm = az = am = 1.0
    qab = a + b
    qap = a + 1.0
    qam = a - 1.0
    bz = 1.0 - qab * x / qap
    for i in range(ITMAX + 1):
        em = float(i + 1)
        tem = em + em
        d = em * (b - em) * x / ((qam + tem) * (a + tem))
        ap = az + d * am
        bp = bz + d * bm
        d = -(a + em) * (qab + em) * x / ((qap + tem) * (a + tem))
        app = ap + d * az
        bpp = bp + d * bz
        aold = az
        am = ap / bpp
        bm = bp / bpp
        az = app / bpp
        bz = 1.0
        if (abs(az - aold) < (EPS * abs(az))):
            return az
    print('a or b too big, or ITMAX too small in Betacf.')
330620
public static double Hypotenuse(double a, double b) {
        double r = 0.0;
        double absA = Math.abs(a);
        double absB = Math.abs(b);

        if (absA > absB) {
            r = b / a;
            r = absA * Math.sqrt(1 + r * r);
        } else if (b != 0) {
            r = a / b;
            r = absB * Math.sqrt(1 + r * r);
        }

        return r;
    }
27103
public double compare(String v1, String v2) {
    // FIXME: it should be possible here to say that, actually, we
    // didn't learn anything from comparing these two values, so that
    // probability is set to 0.5.

    if (comparator == null)
      return 0.5; // we ignore properties with no comparator

    // first, we call the comparator, to get a measure of how similar
    // these two values are. note that this is not the same as what we
    // are going to return, which is a probability.
    double sim = comparator.compare(v1, v2);

    // we have been configured with a high probability (for equal
    // values) and a low probability (for different values). given
    // sim, which is a measure of the similarity somewhere in between
    // equal and different, we now compute our estimate of the
    // probability.

    // if sim = 1.0, we return high. if sim = 0.0, we return low. for
    // values in between we need to compute a little.  the obvious
    // formula to use would be (sim * (high - low)) + low, which
    // spreads the values out equally spaced between high and low.

    // however, if the similarity is higher than 0.5 we don't want to
    // consider this negative evidence, and so there's a threshold
    // there.  also, users felt Duke was too eager to merge records,
    // and wanted probabilities to fall off faster with lower
    // probabilities, and so we square sim in order to achieve this.

    if (sim >= 0.5)
      return ((high - 0.5) * (sim * sim)) + 0.5;
    else
      return low;
  }
790101
function bpser(a, b, x) {
      var c, ser;

      c = 1;
      ser = a * series(function(i) {
         if (i === 0) { return 0; }
         c = c * (1 - b / i) * x;
         return c / (a + i);
      });
      ser = ser > -1 ? log1p(ser) : -Infinity;
      return -lbeta(a, b) + a * Math.log(x) - Math.log(a) + ser;
   }
1150709
public static double pdf(double x, double k, double theta, double shift) {
    if(x == Double.POSITIVE_INFINITY || x == Double.NEGATIVE_INFINITY) {
      return 0.;
    }
    if(x != x) {
      return Double.NaN;
    }
    x = (x - shift) * theta;
    final double ex = FastMath.exp(x);
    return ex < Double.POSITIVE_INFINITY ? FastMath.exp(k * x - ex - GammaDistribution.logGamma(k)) * theta : 0.;
  }
850764
public static double Incomplete(double a, double b, double x) {
        double aa, bb, t, xx, xc, w, y;
        boolean flag;

        if (a <= 0.0) {
            try {
                throw new IllegalArgumentException(" 'a' Lower limit must be greater than zero.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (b <= 0.0) {
            try {
                throw new IllegalArgumentException(" 'b' Upper limit must be greater than zero.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if ((x <= 0.0) || (x >= 1.0)) {
            if (x == 0.0) return 0.0;
            if (x == 1.0) return 1.0;
            try {
                throw new IllegalArgumentException(" 'x' Value must be between 0 and 1.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        flag = false;
        if ((b * x) <= 1.0 && x <= 0.95) {
            t = PowerSeries(a, b, x);
            return t;
        }

        w = 1.0 - x;

        if (x > (a / (a + b))) {
            flag = true;
            aa = b;
            bb = a;
            xc = x;
            xx = w;
        } else {
            aa = a;
            bb = b;
            xc = w;
            xx = x;
        }

        if (flag && (bb * xx) <= 1.0 && xx <= 0.95) {
            t = PowerSeries(aa, bb, xx);
            if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
            else t = 1.0 - t;
            return t;
        }

        y = xx * (aa + bb - 2.0) - (aa - 1.0);
        if (y < 0.0)
            w = Incbcf(aa, bb, xx);
        else
            w = Incbd(aa, bb, xx) / xc;


        y = aa * Math.log(xx);
        t = bb * Math.log(xc);
        if ((aa + bb) < Gamma.GammaMax && Math.abs(y) < Constants.LogMax && Math.abs(t) < Constants.LogMax) {
            t = Math.pow(xc, bb);
            t *= Math.pow(xx, aa);
            t /= aa;
            t *= w;
            t *= Gamma.Function(aa + bb) / (Gamma.Function(aa) * Gamma.Function(bb));
            if (flag) {
                if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
                else t = 1.0 - t;
            }
            return t;
        }

        y += t + Gamma.Log(aa + bb) - Gamma.Log(aa) - Gamma.Log(bb);
        y += Math.log(w / aa);
        if (y < Constants.LogMin)
            t = 0.0;
        else
            t = Math.exp(y);

        if (flag) {
            if (t <= Constants.DoubleEpsilon) t = 1.0 - Constants.DoubleEpsilon;
            else t = 1.0 - t;
        }
        return t;
    }
1333119
public static double Log(double a, double b) {
        return Gamma.Log(a) + Gamma.Log(b) - Gamma.Log(a + b);
    }