public void JointDistributionConstructorTest2()
        {
            int[] symbols = { 3, 5, 2 };
            JointDistribution target = new JointDistribution(symbols);

            double[] p = target.Frequencies;

            Assert.AreEqual(3 * 5 * 2, p.Length);

            for (int i = 0; i < p.Length; i++)
                p[i] = i;

            double actual;

            actual = target.ProbabilityMassFunction(new int[] { 0, 0, 0 });
            Assert.AreEqual(0, actual);

            actual = target.ProbabilityMassFunction(new int[] { 0, 0, 1 });
            Assert.AreEqual(1, actual);

            actual = target.ProbabilityMassFunction(new int[] { 0, 1, 0 });
            Assert.AreEqual(2, actual);

            actual = target.ProbabilityMassFunction(new int[] { 0, 1, 1 });
            Assert.AreEqual(3, actual);

            actual = target.ProbabilityMassFunction(new int[] { 0, 2, 0 });
            Assert.AreEqual(4, actual);

            actual = target.ProbabilityMassFunction(new int[] { 0, 2, 1 });
            Assert.AreEqual(5, actual);

            actual = target.ProbabilityMassFunction(new int[] { 2, 4, 1 });
            Assert.AreEqual(29, actual);
        }
示例#2
0
        /// <summary>
        ///   Estimates a new <see cref="JointDistribution"/> from a given set of observations.
        /// </summary>
        ///
        /// <example>
        ///   Please see <see cref="JointDistribution"/>.
        /// </example>
        ///
        public static JointDistribution Estimate(int[][] values)
        {
            var joint = new JointDistribution(values.DistinctCount());

            joint.Fit(values);
            return(joint);
        }
示例#3
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            JointDistribution d = new JointDistribution(base.Dimension);

            d.positions     = this.positions.Copy();
            d.probabilities = this.probabilities.Copy();
            d.symbols       = this.symbols.Copy();
            d.start         = this.start.Copy();
            return(d);
        }
示例#4
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            JointDistribution d = new JointDistribution(base.Dimension);

            d.positions     = (int[])this.positions.Clone();
            d.probabilities = (double[])this.probabilities.Clone();
            d.symbols       = (int[])this.symbols.Clone();

            return(d);
        }
示例#5
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            JointDistribution d = new JointDistribution(base.Dimension);
            d.positions = (int[])this.positions.Clone();
            d.probabilities = (double[])this.probabilities.Clone();
            d.symbols = (int[])this.symbols.Clone();

            return d;
        }
        public void MeanTest3()
        {
            var target = new JointDistribution(new[] { 2 }, new [] { 0.5, 0.5 });
            double expected = (2.0 + 3.0) / 2.0;
            double actual = target.Mean[0];

            Assert.AreEqual(expected, actual);
        }
 public void MeanTest2()
 {
     var target = new JointDistribution(new [] { 42 }, new[] { 0.1, 0.4, 0.5 });
     double expected = 42 * 0.1 + 43 * 0.4 + 44 * 0.5;
     double actual = target.Mean[0];
      
     Assert.AreEqual(expected, actual);
 }
        public void DistributionFunctionTest()
        {
            var target = new JointDistribution(new[] { 0.1, 0.4, 0.5 });

            double actual;

            actual = target.DistributionFunction(new[] { 0 });
            Assert.AreEqual(0.1, actual, 1e-6);

            actual = target.DistributionFunction(new[] { 1 });
            Assert.AreEqual(0.5, actual, 1e-6);

            actual = target.DistributionFunction(new[] { 2 });
            Assert.AreEqual(1.0, actual, 1e-6);

            actual = target.DistributionFunction(new[] { 3 });
            Assert.AreEqual(1.0, actual, 1e-6);
        }
        public void FitTest_vector_inputs()
        {
            double[] expected = { 0.50, 0.00, 0.25, 0.25 };

            JointDistribution target;

            double[] values = { 0.00, 2.00, 3.00 };
            double[] weights = { 0.50, 0.25, 0.25 };
            target = new JointDistribution(new[] { 4 });
            target.Fit(Jagged.ColumnVector(values), weights);
            double[] actual = target.Frequencies;

            Assert.IsTrue(Matrix.IsEqual(expected, actual));
        }
        public void FitTest4()
        {
            double[] expected = { 0.50, 0.00, 0.25, 0.25 };

            JointDistribution target;

            double[] values = { 0.00, 2.00, 3.00 };
            double[] weights = { 0.50, 0.25, 0.25 };
            target = new JointDistribution(new[] { -1 }, new[] { 4 });
            target.Fit(Jagged.ColumnVector(values).Subtract(1), weights);
            double[] actual = target.Frequencies;

            Assert.IsTrue(Matrix.IsEqual(expected, actual));

            // --

            double[] values2 = { 0.00, 0.00, 2.00, 3.00 };
            double[] weights2 = { 0.25, 0.25, 0.25, 0.25 };
            target = new JointDistribution(new[] { -1 }, new[] { 4 });
            target.Fit(Jagged.ColumnVector(values2).Subtract(1), weights2);
            double[] actual2 = target.Frequencies;
            Assert.IsTrue(Matrix.IsEqual(expected, actual2));
        }
        public void FitTest2()
        {
            int[] symbols = { 3, 5 };
            JointDistribution target = new JointDistribution(symbols);

            double[][] observations = 
            {
                new double[] { 0, 0 },
                new double[] { 1, 1 },
                new double[] { 2, 1 },
            };

            double[] weights = { 2, 1, 1 };

            target.Fit(observations, weights);

            double[] p = target.Frequencies;

            double actual;

            actual = target.ProbabilityMassFunction(new[] { 0, 0 });
            Assert.AreEqual(0.5, actual);

            actual = target.ProbabilityMassFunction(new[] { 1, 1 });
            Assert.AreEqual(0.25, actual);

            actual = target.ProbabilityMassFunction(new[] { 2, 1 });
            Assert.AreEqual(0.25, actual);

        }