問題は、教育アルゴリズムがトレーニング シーケンスがdouble[12][32][18]
ではなくの形式であると想定していることdouble[12][32,18]
でした。トレーニング データは、多変量点のシーケンスのコレクションである必要があります。int[12]
また、ジェスチャの可能なクラスが 11 ある場合、配列で指定された整数ラベルは 0 から 10 の間の値のみで構成される必要があることに注意する必要があります。
したがって、それぞれが 32 フレームを含む 12 個のジェスチャ サンプルがあり、各フレームが 18 ポイントのベクトルである場合double[12][32][18]
、観察を含むint[12]
配列と予想されるクラス ラベルを含む配列を教師に与える必要があります。
HiddenMarkovClassifierLearning ドキュメンテーション ページから抜粋した以下の例は、ベクトルをどのように編成する必要があるかを理解するのに役立ちます。
// Create a Continuous density Hidden Markov Model Sequence Classifier
// to detect a multivariate sequence and the same sequence backwards.
double[][][] sequences = new double[][][]
{
new double[][]
{
// This is the first sequence with label = 0
new double[] { 0, 1 },
new double[] { 1, 2 },
new double[] { 2, 3 },
new double[] { 3, 4 },
new double[] { 4, 5 },
},
new double[][]
{
// This is the second sequence with label = 1
new double[] { 4, 3 },
new double[] { 3, 2 },
new double[] { 2, 1 },
new double[] { 1, 0 },
new double[] { 0, -1 },
}
};
// Labels for the sequences
int[] labels = { 0, 1 };
上記のコードでは、観測の 2 つのシーケンスの問題を設定しました。各シーケンスには 5 つの観測が含まれ、各観測は 2 つの値で構成されています。ご覧のとおり、これは double[2][5][2] 配列です。クラス ラベルの配列は int[2] で指定され、0 から 1 の範囲の値のみが含まれます。
ここで、例をより完全なものにするために、次のコードを使用してモデルの作成とトレーニングを続けることができます。
var initialDensity = new MultivariateNormalDistribution(2);
// Creates a sequence classifier containing 2 hidden Markov Models with 2 states
// and an underlying multivariate mixture of Normal distributions as density.
var classifier = new HiddenMarkovClassifier<MultivariateNormalDistribution>(
classes: 2, topology: new Forward(2), initial: initialDensity);
// Configure the learning algorithms to train the sequence classifier
var teacher = new HiddenMarkovClassifierLearning<MultivariateNormalDistribution>(
classifier,
// Train each model until the log-likelihood changes less than 0.0001
modelIndex => new BaumWelchLearning<MultivariateNormalDistribution>(
classifier.Models[modelIndex])
{
Tolerance = 0.0001,
Iterations = 0,
FittingOptions = new NormalOptions()
{
Diagonal = true, // only diagonal covariance matrices
Regularization = 1e-5 // avoid non-positive definite errors
}
}
);
// Train the sequence classifier using the algorithm
double logLikelihood = teacher.Run(sequences, labels);
これで、モデルをテストして、出力クラス ラベルが実際に期待したものと一致することを確認できます。
// Calculate the probability that the given
// sequences originated from the model
double likelihood, likelihood2;
// Try to classify the 1st sequence (output should be 0)
int c1 = classifier.Compute(sequences[0], out likelihood);
// Try to classify the 2nd sequence (output should be 1)
int c2 = classifier.Compute(sequences[1], out likelihood2);