train_class_gmmT_train_class_gmmTrainClassGmmTrainClassGmmtrain_class_gmm (算子)

名称

train_class_gmmT_train_class_gmmTrainClassGmmTrainClassGmmtrain_class_gmm — 训练高斯混合模型。

签名

train_class_gmm( : : GMMHandle, MaxIter, Threshold, ClassPriors, Regularize : Centers, Iter)

Herror T_train_class_gmm(const Htuple GMMHandle, const Htuple MaxIter, const Htuple Threshold, const Htuple ClassPriors, const Htuple Regularize, Htuple* Centers, Htuple* Iter)

void TrainClassGmm(const HTuple& GMMHandle, const HTuple& MaxIter, const HTuple& Threshold, const HTuple& ClassPriors, const HTuple& Regularize, HTuple* Centers, HTuple* Iter)

HTuple HClassGmm::TrainClassGmm(Hlong MaxIter, double Threshold, const HString& ClassPriors, double Regularize, HTuple* Iter) const

HTuple HClassGmm::TrainClassGmm(Hlong MaxIter, double Threshold, const char* ClassPriors, double Regularize, HTuple* Iter) const

HTuple HClassGmm::TrainClassGmm(Hlong MaxIter, double Threshold, const wchar_t* ClassPriors, double Regularize, HTuple* Iter) const   ( Windows only)

static void HOperatorSet.TrainClassGmm(HTuple GMMHandle, HTuple maxIter, HTuple threshold, HTuple classPriors, HTuple regularize, out HTuple centers, out HTuple iter)

HTuple HClassGmm.TrainClassGmm(int maxIter, double threshold, string classPriors, double regularize, out HTuple iter)

def train_class_gmm(gmmhandle: HHandle, max_iter: int, threshold: float, class_priors: str, regularize: float) -> Tuple[Sequence[int], Sequence[int]]

描述

train_class_gmmtrain_class_gmmTrainClassGmmTrainClassGmmTrainClassGmmtrain_class_gmm trains the Gaussian Mixture Model (GMM) referenced by GMMHandleGMMHandleGMMHandleGMMHandleGMMHandlegmmhandle. Before the GMM can be trained, all training samples to be used for the training must be stored in the GMM using add_sample_class_gmmadd_sample_class_gmmAddSampleClassGmmAddSampleClassGmmAddSampleClassGmmadd_sample_class_gmm, add_samples_image_class_gmmadd_samples_image_class_gmmAddSamplesImageClassGmmAddSamplesImageClassGmmAddSamplesImageClassGmmadd_samples_image_class_gmm, or read_samples_class_gmmread_samples_class_gmmReadSamplesClassGmmReadSamplesClassGmmReadSamplesClassGmmread_samples_class_gmm。After the training, new training samples can be added to the GMM and the GMM can be trained again.

During the training, the error that results from the GMM applied to the training vectors will be minimized with the expectation maximization (EM) algorithm.

MaxIterMaxIterMaxIterMaxItermaxItermax_iter specifies the maximum number of iterations per class for the EM algorithm. In practice, values between 20 and 200 should be sufficient for most problems. ThresholdThresholdThresholdThresholdthresholdthreshold specifies a threshold for the relative changes of the error. If the relative change in error exceeds the threshold after MaxIterMaxIterMaxIterMaxItermaxItermax_iter iterations, the algorithm will be canceled for this class. Because the algorithm starts with the maximum specified number of centers (parameter NumCentersNumCentersNumCentersNumCentersnumCentersnum_centers in create_class_gmmcreate_class_gmmCreateClassGmmCreateClassGmmCreateClassGmmcreate_class_gmm), in case of a premature termination the number of centers and the error for this class will not be optimal. In this case, a new training with different parameters (e.g., another value for RandSeedRandSeedRandSeedRandSeedrandSeedrand_seed in create_class_gmmcreate_class_gmmCreateClassGmmCreateClassGmmCreateClassGmmcreate_class_gmm) can be tried.

ClassPriorsClassPriorsClassPriorsClassPriorsclassPriorsclass_priors specifies the method of calculation of the class priors in GMM. If 'training'"training""training""training""training""training" is specified, the priors of the classes are taken from the proportion of the corresponding sample data during training. If 'uniform'"uniform""uniform""uniform""uniform""uniform" is specified, the priors are set equal to 1/NumClassesNumClassesNumClassesNumClassesnumClassesnum_classes for all classes.

RegularizeRegularizeRegularizeRegularizeregularizeregularize is used to regularize (nearly) singular covariance matrices during the training. A covariance matrix might collapse to singularity if it is trained with linearly dependent data. To avoid this, a small value specified by RegularizeRegularizeRegularizeRegularizeregularizeregularize is added to each main diagonal element of the covariance matrix, which prevents this element from becoming smaller than RegularizeRegularizeRegularizeRegularizeregularizeregularize. A recommended value for RegularizeRegularizeRegularizeRegularizeregularizeregularize is 0.0001. If RegularizeRegularizeRegularizeRegularizeregularizeregularize is set to 0.0, no regularization is performed.

The centers are initially randomly distributed. In individual cases, relatively high errors will result from the algorithm because the initial random values determined by RandSeedRandSeedRandSeedRandSeedrandSeedrand_seed in create_class_gmmcreate_class_gmmCreateClassGmmCreateClassGmmCreateClassGmmcreate_class_gmm lead to local minima. In this case, a new GMM with a different value for RandSeedRandSeedRandSeedRandSeedrandSeedrand_seed should be generated to test whether a significantly smaller error can be obtained.

It should be noted that, depending on the number of centers, the type of covariance matrix, and the number of training samples, the training can take from a few seconds to several hours.

On output, train_class_gmmtrain_class_gmmTrainClassGmmTrainClassGmmTrainClassGmmtrain_class_gmm returns in CentersCentersCentersCenterscenterscenters the number of centers per class that have been found to be optimal by the EM algorithm. These values can be used as a reference in NumCentersNumCentersNumCentersNumCentersnumCentersnum_centers (in create_class_gmmcreate_class_gmmCreateClassGmmCreateClassGmmCreateClassGmmcreate_class_gmm) for future GMMs. If the number of centers found by training a new GMM on integer training data is unexpectedly high, this might be corrected by adding a RandomizeRandomizeRandomizeRandomizerandomizerandomize noise to the training data in add_sample_class_gmmadd_sample_class_gmmAddSampleClassGmmAddSampleClassGmmAddSampleClassGmmadd_sample_class_gmmIterIterIterIteriteriter contains the number of performed iterations per class. If a value in IterIterIterIteriteriter equals MaxIterMaxIterMaxIterMaxItermaxItermax_iter, the training algorithm has been terminated prematurely (see above).

执行信息

此算子修改后续输入参数的状态:

在执行此算子时,若该参数值需在多个线程间使用,则必须对其访问进行同步。

参数

GMMHandleGMMHandleGMMHandleGMMHandleGMMHandlegmmhandle (输入控制,状态被修改)  class_gmm HClassGmm, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

GMM 句柄。

MaxIterMaxIterMaxIterMaxItermaxItermax_iter (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Maximum number of iterations of the expectation maximization algorithm

默认值: 100

建议值: 10, 20, 30, 50, 100, 200

ThresholdThresholdThresholdThresholdthresholdthreshold (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Threshold for relative change of the error for the expectation maximization algorithm to terminate.

默认值: 0.001

建议值: 0.001, 0.0001

限制: Threshold >= 0.0 && Threshold <= 1.0

ClassPriorsClassPriorsClassPriorsClassPriorsclassPriorsclass_priors (输入控制)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Mode to determine the a-priori probabilities of the classes

默认值: 'training' "training" "training" "training" "training" "training"

值列表: 'training'"training""training""training""training""training", 'uniform'"uniform""uniform""uniform""uniform""uniform"

RegularizeRegularizeRegularizeRegularizeregularizeregularize (输入控制)  real HTuplefloatHTupleHtuple (real) (double) (double) (double)

Regularization value for preventing covariance matrix singularity.

默认值: 0.0001

限制: Regularize >= 0.0 && Regularize < 1.0

CentersCentersCentersCenterscenterscenters (输出控制)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of found centers per class

IterIterIterIteriteriter (输出控制)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

Number of executed iterations per class

示例(HDevelop)

create_class_gmm (NumDim, NumClasses, [1,5], 'full', 'none', 0, 42,\
                  GMMHandle)
* Add the training data
read_samples_class_gmm (GMMHandle, 'samples.gsf')
* Train the GMM
train_class_gmm (GMMHandle, 100, 1e-4, 'training', 1e-4, Centers, Iter)
* Write the Gaussian Mixture Model to file
write_class_gmm (GMMHandle, 'gmmclassifier.gmm')

结果

如果参数有效,算子 train_class_gmmtrain_class_gmmTrainClassGmmTrainClassGmmTrainClassGmmtrain_class_gmm 返回值 2 ( H_MSG_TRUE )。如有必要,则抛出异常。

可能的前趋

add_sample_class_gmmadd_sample_class_gmmAddSampleClassGmmAddSampleClassGmmAddSampleClassGmmadd_sample_class_gmm, read_samples_class_gmmread_samples_class_gmmReadSamplesClassGmmReadSamplesClassGmmReadSamplesClassGmmread_samples_class_gmm

可能的后继

evaluate_class_gmmevaluate_class_gmmEvaluateClassGmmEvaluateClassGmmEvaluateClassGmmevaluate_class_gmm, classify_class_gmmclassify_class_gmmClassifyClassGmmClassifyClassGmmClassifyClassGmmclassify_class_gmm, write_class_gmmwrite_class_gmmWriteClassGmmWriteClassGmmWriteClassGmmwrite_class_gmm, create_class_lut_gmmcreate_class_lut_gmmCreateClassLutGmmCreateClassLutGmmCreateClassLutGmmcreate_class_lut_gmm

替代

read_class_gmmread_class_gmmReadClassGmmReadClassGmmReadClassGmmread_class_gmm

另见

create_class_gmmcreate_class_gmmCreateClassGmmCreateClassGmmCreateClassGmmcreate_class_gmm

参考文献

Christopher M. Bishop: “Neural Networks for Pattern Recognition”; Oxford University Press, Oxford; 1995.
Mario A.T. Figueiredo: “Unsupervised Learning of Finite Mixture Models”; IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 24, No. 3; March 2002.

模块

基础