Пример #1
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data, GaussianMixtureModelOptions options)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (model == null)
            {
                // TODO: Perform K-Means multiple times to avoid
                //  a poor Gaussian Mixture model initialization.
                Initialize(data, options.Threshold);
            }

            // Create the mixture options
            var mixtureOptions = new MixtureOptions()
            {
                Threshold    = options.Threshold,
                InnerOptions = options.NormalOptions,
                Iterations   = options.Iterations,
                Logarithm    = options.Logarithm
            };

            // Check if we have weighted samples
            double[] weights = options.Weights;

            // Fit a multivariate Gaussian distribution
            model.Fit(data, weights, mixtureOptions);


            // Return the log-likelihood as a measure of goodness-of-fit
            return(model.LogLikelihood(data));
        }
Пример #2
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data, GaussianMixtureModelOptions options)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            int components = this.clusters.Count;


            if (model == null)
            {
                // TODO: Perform K-Means multiple times to avoid
                //  a poor Gaussian Mixture model initialization.
                double error = Initialize(data, options.Threshold);
            }

            // Fit a multivariate Gaussian distribution
            var mixtureOptions = new MixtureOptions()
            {
                Threshold    = options.Threshold,
                InnerOptions = options.NormalOptions,
            };

            model.Fit(data, mixtureOptions);


            // Return the log-likelihood as a measure of goodness-of-fit
            return(model.LogLikelihood(data));
        }
Пример #3
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data, double threshold)
        {
            var options = new GaussianMixtureModelOptions
            {
                Threshold = threshold
            };

            return(Compute(data, options));
        }
Пример #4
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data, double threshold, double regularization)
        {
            var options = new GaussianMixtureModelOptions()
            {
                Threshold     = threshold,
                NormalOptions = new NormalOptions()
                {
                    Regularization = regularization
                }
            };

            return(Compute(data, options));
        }
Пример #5
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data, GaussianMixtureModelOptions options)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            int components = this.clusters.Count;


            if (model == null)
            {
                // TODO: Perform K-Means multiple times to avoid
                //  a poor Gaussian Mixture model initialization.
                double error = Initialize(data, options.Threshold);
            }

            // Create the mixture options
            var mixtureOptions = new MixtureOptions()
            {
                Threshold    = options.Threshold,
                InnerOptions = options.NormalOptions,
            };

            // Check if we have weighted samples
            double[] weights = options.Weights;
            if (weights != null)
            {
                // Normalize if necessary
                double sum = weights.Sum();
                if (sum != 1)
                {
                    weights.Divide(sum, inPlace: true);
                }

                System.Diagnostics.Debug.Assert(weights.Sum() - 1 < 1e-5);
            }

            // Fit a multivariate Gaussian distribution
            model.Fit(data, weights, mixtureOptions);


            // Return the log-likelihood as a measure of goodness-of-fit
            return(model.LogLikelihood(data));
        }
Пример #6
0
        /// <summary>
        ///   Divides the input data into K clusters modeling each
        ///   cluster as a multivariate Gaussian distribution.
        /// </summary>
        ///
        public double Compute(double[][] data)
        {
            var options = new GaussianMixtureModelOptions();

            return(Compute(data, options));
        }