/// <summary>
 /// Creates a list of Betas using the supplied vectors of true and false counts.
 /// </summary>
 /// <param name="trueCounts">The vector of true counts</param>
 /// <param name="falseCounts">The vector of false counts</param>
 public SparseBetaList(Vector trueCounts, Vector falseCounts)
 {
     if (trueCounts.Count != falseCounts.Count)
     {
         throw new ArgumentException("True and false count vectors must be the same size " +
                                     trueCounts.Count + "!=" + falseCounts.Count);
     }
     TrueCounts  = ApproximateSparseVector.Copy(trueCounts);
     FalseCounts = ApproximateSparseVector.Copy(falseCounts);
 }
Пример #2
0
        public void VectorSerializeTests()
        {
            Sparsity approxSparsity = Sparsity.ApproximateWithTolerance(0.001);

            double[]        fromArray  = new double[] { 1.2, 2.3, 3.4, 1.2, 1.2, 2.3 };
            Vector          vdense     = Vector.FromArray(fromArray);
            Vector          vsparse    = Vector.FromArray(fromArray, Sparsity.Sparse);
            Vector          vapprox    = Vector.FromArray(fromArray, approxSparsity);
            MemoryStream    stream     = new MemoryStream();
            BinaryFormatter serializer = new BinaryFormatter();

            serializer.Serialize(stream, vdense);
            serializer.Serialize(stream, vsparse);
            serializer.Serialize(stream, vapprox);

            stream.Position = 0;
            Vector                  vdense2  = (Vector)serializer.Deserialize(stream);
            SparseVector            vsparse2 = (SparseVector)serializer.Deserialize(stream);
            ApproximateSparseVector vapprox2 = (ApproximateSparseVector)serializer.Deserialize(stream);

            Assert.Equal(6, vdense2.Count);
            for (int i = 0; i < fromArray.Length; i++)
            {
                Assert.Equal(fromArray[i], vdense2[i]);
            }
            Assert.Equal(vdense2.Sparsity, Sparsity.Dense);

            Assert.Equal(6, vsparse2.Count);
            for (int i = 0; i < fromArray.Length; i++)
            {
                Assert.Equal(vsparse2[i], fromArray[i]);
            }
            Assert.Equal(vsparse2.Sparsity, Sparsity.Sparse);
            Assert.Equal(1.2, vsparse2.CommonValue);
            Assert.Equal(3, vsparse2.SparseValues.Count);
            Assert.True(vsparse2.HasCommonElements);

            Assert.Equal(6, vapprox2.Count);
            for (int i = 0; i < fromArray.Length; i++)
            {
                Assert.Equal(vapprox2[i], fromArray[i]);
            }
            Assert.Equal(vapprox2.Sparsity, approxSparsity);
            Assert.Equal(1.2, vapprox2.CommonValue);
            Assert.Equal(3, vapprox2.SparseValues.Count);
            Assert.True(vapprox2.HasCommonElements);
        }
 /// <summary>
 /// Creates a list of Betas of the specified size, each set to have the specified true and false counts.
 /// </summary>
 /// <param name="size">The size of the list</param>
 /// <param name="trueCount">The true count for each Beta distribution</param>
 /// <param name="falseCount">The false count for each Beta distribution</param>
 public SparseBetaList(int size, double trueCount, double falseCount)
 {
     TrueCounts  = ApproximateSparseVector.Constant(size, trueCount, DefaultSparsity);
     FalseCounts = ApproximateSparseVector.Constant(size, falseCount, DefaultSparsity);
 }
 /// <summary>
 /// Creates a list of Bernoullis of the specified size, each set to have the specified probability of being true.
 /// </summary>
 /// <param name="size">The size of the list</param>
 /// <param name="probTrue">The probability of each Bernoulli being true</param>
 public SparseBernoulliList(int size, double probTrue)
 {
     LogOddsVector = ApproximateSparseVector.Constant(size, MMath.Logit(probTrue), DefaultSparsity);
 }
 /// <summary>
 /// Creates a list of Bernoullis of the specified size, each set to uniform.
 /// </summary>
 /// <param name="size">The size of the list</param>
 public SparseBernoulliList(int size)
 {
     LogOddsVector = ApproximateSparseVector.Zero(size, DefaultSparsity);
 }
 /// <summary>
 /// Creates a list of Bernoullis of the specified size, each set to uniform.
 /// </summary>
 /// <param name="size">The size of the list</param>
 public BernoulliIntegerSubset(int size)
 {
     LogOddsVector = ApproximateSparseVector.Zero(size, SparseBernoulliList.DefaultSparsity);
 }