예제 #1
0
 /// <summary>
 /// The log of the integral of the product of this discrete and that discrete
 /// </summary>
 /// <param name="that">That discrete distribution</param>
 /// <returns>The log inner product</returns>
 public double GetLogAverageOf(Discrete that)
 {
     if (Dimension == 0)
     {
         return(0);
     }
     if (that.Dimension == Dimension)
     {
         if (IsUniform() || that.IsUniform())
         {
             return(-Math.Log(Dimension)); // the code below does not return this exactly
         }
         // equivalent to:
         // (this*that).GetLogNormalizer() - this.GetLogNormalizer() - that.GetLogNormalizer()
         // but that fails if prob[0] == 0
         return(Math.Log(prob.Inner(that.prob)));
     }
     else
     {
         double sum = 0.0;
         int    min = Math.Min(prob.Count, that.prob.Count);
         for (int i = 0; i < min; i++)
         {
             sum += prob[i] * that.prob[i];
         }
         return(Math.Log(sum));
     }
 }
예제 #2
0
 /// <summary>
 /// Returns true if the distribution is uniform.
 /// </summary>
 /// <returns>True if uniform</returns>
 public bool IsUniform()
 {
     return(disc.IsUniform());
 }