using System;
namespace Legalsoft.Truffer
{
public class Betadist : Beta
{
private double alph { get; set; }
private double bet { get; set; }
private double fac { get; set; }
public Betadist(double aalph, double bbet)
{
this.alph = aalph;
this.bet = bbet;
if (alph <= 0.0 || bet <= 0.0)
{
throw new Exception("bad alph,bet in Betadist");
}
fac = Globals.gammln(alph + bet) - Globals.gammln(alph) - Globals.gammln(bet);
}
public double p(double x)
{
if (x <= 0.0 || x >= 1.0)
{
throw new Exception("bad x in Betadist");
}
return Math.Exp((alph - 1.0) * Math.Log(x) + (bet - 1.0) * Math.Log(1.0 - x) + fac);
}
public double cdf(double x)
{
if (x < 0.0 || x > 1.0)
{
throw new Exception("bad x in Betadist");
}
return betai(alph, bet, x);
}
public double invcdf(double p)
{
if (p < 0.0 || p > 1.0)
{
throw new Exception("bad p in Betadist");
}
return invbetai(p, alph, bet);
}
}
}