/// <summary> /// Sets the parameters to represent the weighted sum of two discrete distributions. /// </summary> /// <param name="dist1">The first discrete distribution. Can be the same object as <c>this</c></param> /// <param name="weight1">The first weight</param> /// <param name="dist2">The second discrete distribution. Cannot be the same object as <c>this</c></param> /// <param name="weight2">The second weight</param> public void SetToSum(double weight1, Discrete dist1, double weight2, Discrete dist2) { if (weight1 + weight2 == 0) { SetToUniform(); } else if (weight1 + weight2 < 0) { throw new ArgumentException("weight1 (" + weight1 + ") + weight2 (" + weight2 + ") < 0"); } else if (weight1 == 0) { SetTo(dist2); } else if (weight2 == 0) { SetTo(dist1); } // if dist1 == dist2 then we must return dist1, with no roundoff error else if (dist1.Equals(dist2)) { SetTo(dist1); } else if (double.IsPositiveInfinity(weight1)) { if (double.IsPositiveInfinity(weight2)) { throw new ArgumentException("both weights are infinity"); } else { SetTo(dist1); } } else if (double.IsPositiveInfinity(weight2)) { SetTo(dist2); } else { dist1.GetProbs(prob); if (dist2.IsPointMass) { prob.Scale(weight1); prob[dist2.Point] += weight2; } else if (dist2.Dimension < this.Dimension) { Vector prob2 = Vector.Zero(prob.Count, prob.Sparsity); dist2.GetProbs(prob2); prob.SetToSum(weight1, prob, weight2, prob2); } else { prob.SetToSum(weight1, prob, weight2, dist2.prob); } Normalize(); } }
/// <summary> /// Gets the probability at each index. /// </summary> /// <returns>The vector of probabilities</returns> public Vector GetProbs() { return(disc.GetProbs()); }