예제 #1
0
        /// <summary>
        /// Creates a uniform unnormalized discrete distribution over the values from 0 to numValues-1
        /// </summary>
        /// <returns></returns>
        public static UnnormalizedDiscrete Uniform(int numValues)
        {
            UnnormalizedDiscrete d = new UnnormalizedDiscrete();

            d.logProb = DenseVector.Zero(numValues);
            return(d);
        }
예제 #2
0
        /// <summary>
        /// Creates an unnormalized discrete distribution from a vector of log probabilities.
        /// </summary>
        /// <param name="logProb"></param>
        /// <returns></returns>
        public static UnnormalizedDiscrete FromLogProbs(DenseVector logProb)
        {
            UnnormalizedDiscrete ud = new UnnormalizedDiscrete();

            ud.logProb = logProb;
            return(ud);
        }
예제 #3
0
        /// <summary>
        /// Creates an unnormalized discrete distribution from a normal discrete distribution.
        /// </summary>
        /// <param name="d">The discrete distribution</param>
        /// <returns></returns>
        public static UnnormalizedDiscrete FromDiscrete(Discrete d)
        {
            UnnormalizedDiscrete ud = new UnnormalizedDiscrete();

            ud.logProb = (DenseVector)d.GetLogProbs();
            return(ud);
        }
예제 #4
0
        public void SetToSum(double weight1, UnnormalizedDiscrete value1, double weight2, UnnormalizedDiscrete value2)
        {
            Discrete result = Discrete.Uniform(Dimension);

            result.SetToSum(weight1, value1.ToDiscrete(), weight2, value2.ToDiscrete());
            SetLogProbs((DenseVector)result.GetLogProbs());
        }
예제 #5
0
        /// <summary>
        /// Creates an unnormalized discrete distribution which is the ratio of two unnormalized discrete distributions
        /// </summary>
        /// <param name="a">The first distribution</param>
        /// <param name="b">The second distribution</param>
        /// <returns>The resulting unnormalized discrete distribution</returns>
        public static UnnormalizedDiscrete operator /(UnnormalizedDiscrete a, UnnormalizedDiscrete b)
        {
            UnnormalizedDiscrete result = UnnormalizedDiscrete.Uniform(a.Dimension);

            result.SetToRatio(a, b);
            return(result);
        }
예제 #6
0
        public static UnnormalizedDiscrete operator ^(UnnormalizedDiscrete dist, double exponent)
        {
            UnnormalizedDiscrete result = UnnormalizedDiscrete.Uniform(dist.Dimension);

            result.SetToPower(dist, exponent);
            return(result);
        }
예제 #7
0
 /// <summary>
 /// Sets the parameters to represent the ratio of two unnormalized discrete distributions.
 /// </summary>
 /// <param name="numerator">The first unnormalized discrete distribution</param>
 /// <param name="denominator">The second unnormalized discrete distribution</param>
 /// <param name="forceProper">Ignored</param>
 public void SetToRatio(UnnormalizedDiscrete numerator, UnnormalizedDiscrete denominator, bool forceProper = false)
 {
     if (numerator.IsPointMass)
     {
         if (denominator.IsPointMass)
         {
             if (numerator.Point == denominator.Point)
             {
                 SetToUniform();
             }
             else
             {
                 throw new DivideByZeroException();
             }
         }
         else
         {
             SetTo(numerator);
         }
     }
     else if (denominator.IsPointMass)
     {
         throw new DivideByZeroException();
     }
     else
     {
         logProb.SetToDifference(numerator.logProb, denominator.logProb);
     }
 }
예제 #8
0
        /// <summary>
        /// The maximum difference between the parameters of this discrete and that discrete
        /// </summary>
        /// <param name="that">That discrete</param>
        /// <returns>The maximum difference</returns>
        public double MaxDiff(object that)
        {
            UnnormalizedDiscrete thatd = that as UnnormalizedDiscrete;

            if (thatd == null)
            {
                return(Double.PositiveInfinity);
            }
            return(logProb.MaxDiff(thatd.logProb));
        }
예제 #9
0
 /// <summary>
 /// Sets the parameters of this instance to the parameters of that instance
 /// </summary>
 /// <param name="value">That instance</param>
 public void SetTo(UnnormalizedDiscrete value)
 {
     if (object.ReferenceEquals(value, null))
     {
         SetToUniform();
     }
     else
     {
         logProb.SetTo(value.logProb);
     }
 }
예제 #10
0
 /// <summary>
 /// Sets the parameters to represent the product of two unnormalized discrete distributions.
 /// </summary>
 /// <param name="a">The first unnormalized discrete distribution</param>
 /// <param name="b">The second unnormalized discrete distribution</param>
 public void SetToProduct(UnnormalizedDiscrete a, UnnormalizedDiscrete b)
 {
     if (a.IsPointMass)
     {
         if (b.IsPointMass && (a.Point != b.Point))
         {
             throw new AllZeroException();
         }
         SetTo(a);
     }
     else if (b.IsPointMass)
     {
         SetTo(b);
     }
     else
     {
         logProb.SetToSum(a.logProb, b.logProb);
     }
 }
예제 #11
0
 public void SetToPower(UnnormalizedDiscrete dist, double exponent)
 {
     if (dist.IsPointMass)
     {
         if (exponent == 0)
         {
             SetToUniform();
         }
         else if (exponent < 0)
         {
             throw new DivideByZeroException("The exponent is negative and the distribution is a point mass");
         }
         else
         {
             Point = dist.Point;
         }
         return;
     }
     logProb.Scale(exponent);
 }
예제 #12
0
 public double GetAverageLog(UnnormalizedDiscrete that)
 {
     throw new NotImplementedException();
 }