Exemple #1
0
        /// <summary>
        /// サンプル集合からガウス混合パラメータを推定する
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="means0"></param>
        /// <param name="covs0"></param>
        /// <param name="weights0"></param>
        /// <param name="logLikelihoods"></param>
        /// <param name="labels"></param>
        /// <param name="probs"></param>
#else
        /// <summary>
        /// Estimates Gaussian mixture parameters from the sample set
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="means0"></param>
        /// <param name="covs0"></param>
        /// <param name="weights0"></param>
        /// <param name="logLikelihoods"></param>
        /// <param name="labels"></param>
        /// <param name="probs"></param>
#endif
        public virtual bool TrainE(
            InputArray samples,
            InputArray means0,
            InputArray covs0           = null,
            InputArray weights0        = null,
            OutputArray logLikelihoods = null,
            OutputArray labels         = null,
            OutputArray probs          = null)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }
            if (means0 == null)
            {
                throw new ArgumentNullException("means0");
            }
            samples.ThrowIfDisposed();
            means0.ThrowIfDisposed();

            if (logLikelihoods != null)
            {
                logLikelihoods.ThrowIfNotReady();
            }
            if (covs0 != null)
            {
                covs0.ThrowIfDisposed();
            }
            if (weights0 != null)
            {
                weights0.ThrowIfDisposed();
            }
            if (labels != null)
            {
                labels.ThrowIfNotReady();
            }
            if (probs != null)
            {
                probs.ThrowIfNotReady();
            }

            int ret = NativeMethods.ml_EM_trainE(
                ptr,
                samples.CvPtr,
                means0.CvPtr,
                Cv2.ToPtr(covs0),
                Cv2.ToPtr(weights0),
                Cv2.ToPtr(logLikelihoods),
                Cv2.ToPtr(labels),
                Cv2.ToPtr(probs));

            if (logLikelihoods != null)
            {
                logLikelihoods.Fix();
            }
            if (labels != null)
            {
                labels.Fix();
            }
            if (probs != null)
            {
                probs.Fix();
            }
            GC.KeepAlive(samples);
            GC.KeepAlive(means0);
            GC.KeepAlive(covs0);
            GC.KeepAlive(weights0);

            return(ret != 0);
        }