/**
         * <summary> The predict method takes an Instance as an input. First it gets the size of prior distribution and loops this size times.
         * Then it gets the possible class labels and and calculates metric value. At the end, it returns the class which has the
         * maximum value of metric.</summary>
         *
         * <param name="instance">{@link Instance} to predict.</param>
         * <returns>The class which has the maximum value of metric.</returns>
         */
        public override string Predict(Instance.Instance instance)
        {
            string predictedClass;
            var    maxMetric = double.MinValue;
            int    size;

            if (instance is CompositeInstance compositeInstance)
            {
                predictedClass = compositeInstance.GetPossibleClassLabels()[0];
                size           = compositeInstance.GetPossibleClassLabels().Count;
            }
            else
            {
                predictedClass = priorDistribution.GetMaxItem();
                size           = priorDistribution.Count;
            }
            for (var i = 0; i < size; i++)
            {
                string ci;
                if (instance is CompositeInstance compositeInstance1)
                {
                    ci = compositeInstance1.GetPossibleClassLabels()[i];
                }
                else
                {
                    ci = priorDistribution.GetItem(i);
                }
                if (priorDistribution.ContainsItem(ci))
                {
                    var metric = CalculateMetric(instance, ci);
                    if (metric > maxMetric)
                    {
                        maxMetric      = metric;
                        predictedClass = ci;
                    }
                }
            }

            return(predictedClass);
        }
        public void TestAddItem2()
        {
            Random random = new Random();
            DiscreteDistribution discreteDistribution = new DiscreteDistribution();

            for (int i = 0; i < 1000; i++)
            {
                discreteDistribution.AddItem("" + random.Next(1000));
            }

            int count = 0;

            for (int i = 0; i < 1000; i++)
            {
                if (discreteDistribution.ContainsItem("" + i))
                {
                    count += discreteDistribution.GetCount("" + i);
                }
            }

            Assert.AreEqual(1000, count);
        }
 public void TestContainsItem()
 {
     Assert.True(smallDistribution.ContainsItem("item1"));
     Assert.False(smallDistribution.ContainsItem("item4"));
 }