/// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given length
 /// and assigns all elements the given value,
 /// except for the specified list of sparse values. This list is stored internally as is,
 /// so MUST be sorted by index and must not be modified externally after being passed in.
 /// </summary>
 /// <param name="size">The size of the list.</param>
 /// <param name="commonValue">The common value.</param>
 /// <param name="sortedSparseValues">The sorted list of non-common values.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromSparseValues(
     int size,
     Bernoulli commonValue,
     List <ValueAtIndex <Bernoulli> > sortedSparseValues)
 {
     return(BernoulliIntegerSubset.FromSparseValues(size, commonValue, sortedSparseValues, SparseBernoulliList.DefaultTolerance));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="BernoulliIntegerSubset"/> class
        /// with the specified number of elements all of which are set to uniform.
        /// </summary>
        /// <param name="size">The size of the list.</param>
        /// <param name="tolerance">The tolerance for the approximation.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromSize(int size, double tolerance)
        {
            var result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.FromSize(size, tolerance);
            return(result);
        }
        /// <summary>
        /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class from a sparse list of Bernoulli distributions.
        /// </summary>
        /// <param name="bernoullis">The sparse list of Bernoulli distributions.</param>
        /// <param name="tolerance">The tolerance.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromSparseList(ISparseList <Bernoulli> bernoullis, double tolerance)
        {
            var result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.FromSparseList(bernoullis, tolerance);
            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BernoulliIntegerSubset"/> class
        /// with the specified number of elements all of which are set to the specified <see cref="Bernoulli"/> instance.
        /// </summary>
        /// <param name="size">The size of the list.</param>
        /// <param name="commonValue">The common value.</param>
        /// <param name="tolerance">The tolerance for the approximation.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromBernoulli(int size, Bernoulli commonValue, double tolerance)
        {
            var result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.Constant(size, commonValue, tolerance);
            return(result);
        }
        /// <summary>
        /// Creates a <see cref="BernoulliIntegerSubset"/> distribution which is the ratio of two others.
        /// </summary>
        /// <param name="numerator">The numerator.</param>
        /// <param name="denominator">The denominator.</param>
        /// <returns>The resulting <see cref="BernoulliIntegerSubset"/> distribution.</returns>
        public static BernoulliIntegerSubset operator /(BernoulliIntegerSubset numerator, BernoulliIntegerSubset denominator)
        {
            var result = BernoulliIntegerSubset.FromSize(numerator.Dimension);

            result.SetToRatio(numerator, denominator);
            return(result);
        }
        /// <summary>
        /// Creates a <see cref="BernoulliIntegerSubset"/> distribution which is the power of another.
        /// </summary>
        /// <param name="dist">The other distribution.</param>
        /// <param name="exponent">The exponent.</param>
        /// <returns>The resulting <see cref="BernoulliIntegerSubset"/> distribution.</returns>
        public static BernoulliIntegerSubset operator ^(BernoulliIntegerSubset dist, double exponent)
        {
            var result = BernoulliIntegerSubset.FromSize(dist.Dimension);

            result.SetToPower(dist, exponent);
            return(result);
        }
        /// <summary>
        /// Creates a <see cref="BernoulliIntegerSubset"/> distribution which is the product of two others.
        /// </summary>
        /// <param name="a">The first distribution.</param>
        /// <param name="b">The second distribution.</param>
        /// <returns>The resulting <see cref="BernoulliIntegerSubset"/> distribution.</returns>
        public static BernoulliIntegerSubset operator *(BernoulliIntegerSubset a, BernoulliIntegerSubset b)
        {
            var result = BernoulliIntegerSubset.FromSize(a.Dimension);

            result.SetToProduct(a, b);
            return(result);
        }
        public static BernoulliIntegerSubset FromSparseBernoulliList(SparseBernoulliList list)
        {
            var result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = list;
            return(result);
        }
        /// <summary>
        /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
        /// from a sparse list of probability true.
        /// </summary>
        /// <param name="probTrue">The sparse list of probability of true.</param>
        /// <param name="tolerance">The tolerance for the approximation.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromProbTrue(
            ISparseList <double> probTrue, double tolerance)
        {
            BernoulliIntegerSubset result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.FromProbTrue(probTrue, tolerance);
            return(result);
        }
        /// <summary>
        /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
        /// from a sparse list of log odds.
        /// </summary>
        /// <param name="logOdds">The sparse list of log odds.</param>
        /// <param name="tolerance">The tolerance for the approximation.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromLogOdds(
            ISparseList <double> logOdds, double tolerance)
        {
            BernoulliIntegerSubset result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.FromLogOdds(logOdds, tolerance);
            return(result);
        }
        /// <summary>
        /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given length and assigns all elements the given value,
        /// except for the specified list of sparse values. This list is stored internally as is
        /// so MUST be sorted by index and must not be modified externally after being passed in.
        /// </summary>
        /// <param name="size">The size of the list.</param>
        /// <param name="commonValue">The common value.</param>
        /// <param name="sortedSparseValues">The sorted list of non-common values.</param>
        /// <param name="tolerance">The tolerance for the approximation.</param>
        /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
        public static BernoulliIntegerSubset FromSparseValues(
            int size,
            Bernoulli commonValue,
            List <ValueAtIndex <Bernoulli> > sortedSparseValues,
            double tolerance)
        {
            var result = new BernoulliIntegerSubset();

            result.SparseBernoulliList = SparseBernoulliList.FromSparseValues(size, commonValue, sortedSparseValues, tolerance);
            return(result);
        }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
 /// from a sparse list of probability true.
 /// </summary>
 /// <param name="probTrue">The sparse list of probability of true.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromProbTrue(
     ISparseList <double> probTrue)
 {
     return(BernoulliIntegerSubset.FromProbTrue(probTrue, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
 /// with each element having a given probability of true.
 /// </summary>
 /// <param name="size">The size of the list.</param>
 /// <param name="probTrue">The desired probability of true.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromProbTrue(
     int size, double probTrue)
 {
     return(BernoulliIntegerSubset.FromProbTrue(size, probTrue, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Returns the log of the integral of the product of BernoulliIntegerSubset distribution and another
 /// BernoulliIntegerSubset distribution raised to a power.
 /// </summary>
 /// <param name="that">The other distribution.</param>
 /// <param name="power">The exponent.</param>
 /// <returns>The average of the power of the other distribution under this distribution.</returns>
 public double GetLogAverageOfPower(BernoulliIntegerSubset that, double power)
 {
     return(this.SparseBernoulliList.GetLogAverageOfPower(that.SparseBernoulliList, power));
 }
 /// <summary>
 /// The expected logarithm of that distribution under this distribution.
 /// </summary>
 /// <param name="that">The distribution to take the logarithm of.</param>
 /// <returns><c>sum_x this.Evaluate(x)*Math.Log(that.Evaluate(x))</c>.</returns>
 /// <remarks>This is also known as the cross entropy.</remarks>
 public double GetAverageLog(BernoulliIntegerSubset that)
 {
     return(this.SparseBernoulliList.GetAverageLog(that.SparseBernoulliList));
 }
 /// <summary>
 /// Sets this BernoulliIntegerSubset distribution to the ratio of two other such distributions.
 /// </summary>
 /// <param name="numerator">The numerator.</param>
 /// <param name="denominator">The denominator.</param>
 /// <param name="forceProper">Whether to force the result to be proper.</param>
 public void SetToRatio(BernoulliIntegerSubset numerator, BernoulliIntegerSubset denominator, bool forceProper = false)
 {
     this.SparseBernoulliList.SetToRatio(numerator.SparseBernoulliList, denominator.SparseBernoulliList, forceProper);
 }
 /// <summary>
 /// Sets this BernoulliIntegerSubset distribution to the weighted sum of two other such distributions.
 /// </summary>
 /// <param name="weight1">The first weight.</param>
 /// <param name="value1">The first distribution.</param>
 /// <param name="weight2">The second weight.</param>
 /// <param name="value2">The second distribution.</param>
 /// <remarks>Not yet implemented</remarks>
 public void SetToSum(double weight1, BernoulliIntegerSubset value1, double weight2, BernoulliIntegerSubset value2)
 {
     this.SparseBernoulliList.SetToSum(weight1, value1.SparseBernoulliList, weight2, value2.SparseBernoulliList);
 }
 /// <summary>
 /// Sets this BernoulliIntegerSubset distribution to another such distribution.
 /// </summary>
 /// <param name="value">The distribution to set.</param>
 public void SetTo(BernoulliIntegerSubset value)
 {
     this.SparseBernoulliList.SetTo(value.SparseBernoulliList);
 }
 /// <summary>
 /// Sets this BernoulliIntegerSubset distribution to the power another such distribution.
 /// </summary>
 /// <param name="value">The distribution to be raised to a power.</param>
 /// <param name="exponent">The exponent.</param>
 public void SetToPower(BernoulliIntegerSubset value, double exponent)
 {
     this.SparseBernoulliList.SetToPower(value.SparseBernoulliList, exponent);
 }
 /// <summary>
 /// Sets this BernoulliIntegerSubset distribution to a product of two other such distributions.
 /// </summary>
 /// <param name="a">The left hand side.</param>
 /// <param name="b">The right hand side.</param>
 public void SetToProduct(BernoulliIntegerSubset a, BernoulliIntegerSubset b)
 {
     this.SparseBernoulliList.SetToProduct(a.SparseBernoulliList, b.SparseBernoulliList);
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
 /// with each element having a given log odds.
 /// </summary>
 /// <param name="size">The size of the list.</param>
 /// <param name="logOdds">The desired log odds.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromLogOdds(
     int size, double logOdds)
 {
     return(BernoulliIntegerSubset.FromLogOdds(size, logOdds, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class of a given size
 /// from a sparse list of log odds
 /// </summary>
 /// <param name="logOdds">The sparse list of log odds.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromLogOdds(
     ISparseList <double> logOdds)
 {
     return(BernoulliIntegerSubset.FromLogOdds(logOdds, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class with the specified number of elements
 /// all of which are set to the specified <see cref="Bernoulli"/> instance.
 /// </summary>
 /// <param name="size">The size of the list.</param>
 /// <param name="commonValue">The common value.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromBernoulli(int size, Bernoulli commonValue)
 {
     return(BernoulliIntegerSubset.FromBernoulli(size, commonValue, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class
 /// with the specified number of elements all of which are set to uniform.
 /// </summary>
 /// <param name="size">The size of the list.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromSize(int size)
 {
     return(BernoulliIntegerSubset.FromSize(size, SparseBernoulliList.DefaultTolerance));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BernoulliIntegerSubset"/> class from an instance of the same type.
 /// </summary>
 /// <param name="that">The instance to copy.</param>
 protected BernoulliIntegerSubset(BernoulliIntegerSubset that)
 {
     SparseBernoulliList = (SparseBernoulliList)that.SparseBernoulliList.Clone();
 }
 /// <summary>
 /// Returns a new instance of the <see cref="BernoulliIntegerSubset"/> class from a sparse list of Bernoulli distributions.
 /// </summary>
 /// <param name="bernoullis">The sparse list of Bernoulli distributions.</param>
 /// <returns>The new <see cref="BernoulliIntegerSubset"/> instance.</returns>
 public static BernoulliIntegerSubset FromSparseList(ISparseList <Bernoulli> bernoullis)
 {
     return(BernoulliIntegerSubset.FromSparseList(bernoullis, SparseBernoulliList.DefaultTolerance));
 }