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
Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override Tuple <double, double> Predict(Vector y, bool t)
        {
            if (this.Root == null || this.Descriptor == null)
            {
                throw new InvalidOperationException("Invalid Model - Missing information");
            }

            Vector lp   = Vector.Zeros(this.Root.Probabilities.Length);
            Vector test = Vector.Zeros(this.Root.Probabilities.Length);
            Vector log  = Vector.Zeros(this.Root.Probabilities.Length);

            for (int i = 0; i < this.Root.Probabilities.Length; i++)
            {
                Statistic stat = this.Root.Probabilities[i];
                lp[i]   = (stat.Probability);
                test[i] = (stat.Probability);
                log[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]   *= (p == null ? 10e-10 : p.Probability);
                    test[i] += (p == null ? 10e-10 : p.Probability);
                    log[i]  += System.Math.Log(p == null ? 10e-10 : p.Probability);
                }
            }
            //for (int i = 0; i < lp.Length; i++)
            //    Console.WriteLine("Prob " +i+ "*: " + lp[i] + "\t +:" + test[i] + "\t Log +:" + log[i]);

            var idx       = lp.MaxIndex();
            var precision = lp[idx] / lp.Sum();

            return(new Tuple <double, double>([email protected][idx].X.Min, precision));
        }