Ejemplo n.º 1
0
      /// <summary>
      /// Train the EM model using the specific training data
      /// </summary>
      /// <param name="samples">The training data. A 32-bit floating-point, single-channel matrix, one vector per row</param>
      /// <param name="sampleIdx">Can be null if not needed. When specified, identifies samples of interest. It is a Matrix&gt;int&lt; of nx1</param>
      /// <param name="parameters">The parameters for EM</param>
      /// <param name="labels">Can be null if not needed. Optionally computed output "class label" for each sample</param>
      /// <returns></returns>
      public bool Train(Matrix<float> samples, Matrix<float> sampleIdx, EMParams parameters, Matrix<Int32> labels)
      {
         MCvEMParams param = new MCvEMParams();
         param.nclusters = parameters.Nclusters;
         param.cov_mat_type = parameters.CovMatType;
         param.start_step = parameters.StartStep;
         param.probs = parameters.Probs == null ? IntPtr.Zero : parameters.Probs.Ptr;
         param.means = parameters.Means == null ? IntPtr.Zero : parameters.Means.Ptr;
         param.weights = parameters.Weights == null ? IntPtr.Zero : parameters.Weights.Ptr;

         GCHandle? covsPtrHandle = null;
         if (parameters.Covs == null)
            param.covs = IntPtr.Zero;
         else
         {
            IntPtr[] covsPtr = Array.ConvertAll<CvArray<double>, IntPtr>(parameters.Covs,
               delegate(CvArray<double> m) { return m.Ptr; });
            covsPtrHandle = GCHandle.Alloc(covsPtr, GCHandleType.Pinned);
            param.covs = covsPtrHandle.Value.AddrOfPinnedObject();
         }
         param.term_crit = parameters.TermCrit;
 
         bool res = MlInvoke.CvEMTrain(
            _ptr, 
            samples.Ptr, 
            sampleIdx == null? IntPtr.Zero : sampleIdx.Ptr, 
            param,
            labels == null? IntPtr.Zero : labels.Ptr);

         if (covsPtrHandle.HasValue)
            covsPtrHandle.Value.Free();

         return res;
      }
Ejemplo n.º 2
0
        /// <summary>
        /// Train the EM model using the specific training data
        /// </summary>
        /// <param name="samples">The training data. A 32-bit floating-point, single-channel matrix, one vector per row</param>
        /// <param name="parameters">The parameters for EM</param>
        /// <param name="labels">Can be null if not needed. Optionally computed output "class label" for each sample</param>
        /// <returns></returns>
        public bool Train(Matrix <float> samples, EMParams parameters, Matrix <Int32> labels)
        {
            MCvEMParams param = new MCvEMParams();

            param.nclusters    = parameters.Nclusters;
            param.cov_mat_type = parameters.CovMatType;
            param.start_step   = parameters.StartStep;
            param.probs        = parameters.Probs == null ? IntPtr.Zero : parameters.Probs.Ptr;
            param.means        = parameters.Means == null ? IntPtr.Zero : parameters.Means.Ptr;
            param.weights      = parameters.Weights == null ? IntPtr.Zero : parameters.Weights.Ptr;

            GCHandle?covsPtrHandle = null;

            if (parameters.Covs == null)
            {
                param.covs = IntPtr.Zero;
            }
            else
            {
                IntPtr[] covsPtr =
#if NETFX_CORE
                    Extensions.
#else
                    Array.
#endif
                    ConvertAll <Matrix <double>, IntPtr>(parameters.Covs, delegate(Matrix <double> m) { return(m.Ptr); });
                covsPtrHandle = GCHandle.Alloc(covsPtr, GCHandleType.Pinned);
                param.covs    = covsPtrHandle.Value.AddrOfPinnedObject();
            }
            param.term_crit = parameters.TermCrit;

            bool res = MlInvoke.CvEMLegacyTrain(
                _ptr,
                samples.Ptr,
                IntPtr.Zero,
                param,
                labels == null ? IntPtr.Zero : labels.Ptr);

            if (covsPtrHandle.HasValue)
            {
                covsPtrHandle.Value.Free();
            }

            return(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creaet an Expectation Maximization model using the specific training parameters
 /// </summary>
 /// <param name="samples">The training data. A 32-bit floating-point, single-channel matrix, one vector per row</param>
 /// <param name="parameters">The parameters for EM</param>
 /// <param name="labels">Can be null if not needed. Optionally computed output "class label" for each sample</param>
 public EMLegacy(Matrix <float> samples, EMParams parameters, Matrix <Int32> labels)
     : this()
 {
     Train(samples, parameters, labels);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creaet an Expectation Maximization model using the specific training parameters
 /// </summary>
 /// <param name="samples">The samples to be trained</param>
 /// <param name="sampleIdx"></param>
 /// <param name="parameters"></param>
 /// <param name="labels"></param>
 public EM(Matrix<float> samples, Matrix<float> sampleIdx, EMParams parameters, Matrix<Int32> labels)
     : this()
 {
     Train(samples, sampleIdx, parameters, labels);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creaet an Expectation Maximization model using the specific training parameters
 /// </summary>
 /// <param name="samples">The samples to be trained</param>
 /// <param name="sampleIdx"></param>
 /// <param name="parameters"></param>
 /// <param name="labels"></param>
 public EM(Matrix <float> samples, Matrix <float> sampleIdx, EMParams parameters, Matrix <Int32> labels)
     : this()
 {
     Train(samples, sampleIdx, parameters, labels);
 }