numl.Supervised.NaiveBayes.Measure.GetStatisticFor C# (CSharp) Method

GetStatisticFor() private method

Gets statistic for.
Thrown when the index is outside the required /// range.
private GetStatisticFor ( double x ) : Statistic
x double The x coordinate.
return Statistic
        internal Statistic GetStatisticFor(double x)
        {
            if (Probabilities == null || Probabilities.Length == 0)
                throw new IndexOutOfRangeException("Invalid statistics");

            var p = Probabilities.Where(s => s.X.Test(x)).FirstOrDefault();

            return p;
        }

Usage Example

Beispiel #1
0
        /// <summary>Predicts the given o.</summary>
        /// <exception cref="InvalidOperationException">Thrown when the requested operation is invalid.</exception>
        /// <param name="y">The Vector to process.</param>
        /// <returns>An object.</returns>
        public override double Predict(Vector y)
        {
            this.Preprocess(y);

            if (Root == null || Descriptor == null)
            {
                throw new InvalidOperationException("Invalid Model - Missing information");
            }

            Vector lp = Vector.Zeros(Root.Probabilities.Length);

            for (int i = 0; i < Root.Probabilities.Length; i++)
            {
                Statistic stat = Root.Probabilities[i];
                lp[i] = System.Math.Log(stat.Probability);
                for (int j = 0; j < y.Length; j++)
                {
                    Measure conditional = stat.Conditionals[j];
                    var     p           = conditional.GetStatisticFor(y[j]);
                    // check for missing range, assign bad probability
                    lp[i] += System.Math.Log(p == null ? 10e-10 : p.Probability);
                }
            }
            var idx = lp.MaxIndex();

            return(Root.Probabilities[idx].X.Min);
        }
All Usage Examples Of numl.Supervised.NaiveBayes.Measure::GetStatisticFor