/// <summary>
        ///   Gets the probability density function (pdf) for
        ///   this distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">A single point in the distribution range.</param>
        ///
        /// <returns>
        ///   The probability of <c>x</c> occurring
        ///   in the current distribution.
        /// </returns>
        ///
        /// <remarks>
        ///   The Probability Density Function (PDF) describes the
        ///   probability that a given value <c>x</c> will occur.
        /// </remarks>
        ///
        public override double ProbabilityDensityFunction(params double[] x)
        {
            // http://www.buch-kromann.dk/tine/nonpar/Nonparametric_Density_Estimation_multidim.pdf
            // http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/ebooks/html/spm/spmhtmlnode18.html

            double sum = 0;

            double[] delta = new double[Dimension];

            if (type == WeightType.None)
            {
                for (int i = 0; i < samples.Length; i++)
                {
                    for (int j = 0; j < x.Length; j++)
                    {
                        delta[j] = (x[j] - samples[i][j]);
                    }

                    sum += kernel.Function(chol.Solve(delta));
                }

                return(sum / (samples.Length * determinant));
            }

            if (type == WeightType.Repetition)
            {
                for (int i = 0; i < samples.Length; i++)
                {
                    for (int j = 0; j < x.Length; j++)
                    {
                        delta[j] = (x[j] - samples[i][j]);
                    }

                    sum += kernel.Function(chol.Solve(delta)) * repeats[i];
                }

                return(sum / (numberOfSamples * determinant));
            }

            if (type == WeightType.Fraction)
            {
                for (int i = 0; i < samples.Length; i++)
                {
                    for (int j = 0; j < x.Length; j++)
                    {
                        delta[j] = (x[j] - samples[i][j]);
                    }

                    sum += kernel.Function(chol.Solve(delta)) * weights[i];
                }

                return(sum / (sumOfWeights * determinant));
            }

            throw new InvalidOperationException();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Gets the probability density function (pdf) for
        ///   this distribution evaluated at point <c>x</c>.
        /// </summary>
        ///
        /// <param name="x">A single point in the distribution range.</param>
        ///
        /// <returns>
        ///   The probability of <c>x</c> occurring
        ///   in the current distribution.
        /// </returns>
        ///
        /// <remarks>
        ///   The Probability Density Function (PDF) describes the
        ///   probability that a given value <c>x</c> will occur.
        /// </remarks>
        ///
        public override double ProbabilityDensityFunction(double[] x)
        {
            // http://www.buch-kromann.dk/tine/nonpar/Nonparametric_Density_Estimation_multidim.pdf
            // http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/ebooks/html/spm/spmhtmlnode18.html

            double sum = 0;

            CholeskyDecomposition chol = new CholeskyDecomposition(smoothing);

            double[] delta = new double[Dimension];
            for (int i = 0; i < samples.Length; i++)
            {
                for (int j = 0; j < x.Length; j++)
                {
                    delta[j] = (x[j] - samples[i][j]);
                }

                sum += kernel.Function(chol.Solve(delta));
            }

            return(sum / (samples.Length * determinant));
        }