Exemplo n.º 1
0
 private static double[] LognormalLpdf(double x, double[] weights, double[] mus, double[] sigmas)
 {
     double[] ret = new double[weights.Length];
     for (int i = 0; i < ret.Length; i++)
     {
         double sigma = Math.Max(sigmas[i], eps);
         double z     = sigma * x * Math.Sqrt(2 * Math.PI);
         double e     = 0.5 * ArrayMath.Square((Math.Log(x) - mus[i]) / sigma);
         ret[i] = -e - Math.Log(z) + Math.Log(weights[i]);
     }
     return(ret);
 }
Exemplo n.º 2
0
 private static double[] NormalLpdf(double x, double[] weights, double[] mus, double[] sigmas, double pAccept)
 {
     double[] ret = new double[weights.Length];
     for (int i = 0; i < ret.Length; i++)
     {
         double sigma = Math.Max(sigmas[i], eps);
         double dist  = x - mus[i];
         double mahal = ArrayMath.Square(dist / sigma);
         double z     = Math.Sqrt(2 * Math.PI) * sigmas[i];
         double coef  = weights[i] / z / pAccept;
         ret[i] = -0.5 * mahal + Math.Log(coef);
     }
     return(ret);
 }