本文整理汇总了C#中HiddenConditionalRandomField.Save方法的典型用法代码示例。如果您正苦于以下问题:C# HiddenConditionalRandomField.Save方法的具体用法?C# HiddenConditionalRandomField.Save怎么用?C# HiddenConditionalRandomField.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HiddenConditionalRandomField
的用法示例。
在下文中一共展示了HiddenConditionalRandomField.Save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveLoadTest
public void SaveLoadTest()
{
double[][] hello =
{
new double[] { 1.0, 0.1, 0.0, 0.0 }, // let's say the word
new double[] { 0.0, 1.0, 0.1, 0.1 }, // hello took 6 frames
new double[] { 0.0, 1.0, 0.1, 0.1 }, // to be recorded.
new double[] { 0.0, 0.0, 1.0, 0.0 },
new double[] { 0.0, 0.0, 1.0, 0.0 },
new double[] { 0.0, 0.0, 0.1, 1.1 },
};
double[][] car =
{
new double[] { 0.0, 0.0, 0.0, 1.0 }, // the car word
new double[] { 0.1, 0.0, 1.0, 0.1 }, // took only 4.
new double[] { 0.0, 0.0, 0.1, 0.0 },
new double[] { 1.0, 0.0, 0.0, 0.0 },
};
double[][] wardrobe =
{
new double[] { 0.0, 0.0, 1.0, 0.0 }, // same for the
new double[] { 0.1, 0.0, 1.0, 0.1 }, // wardrobe word.
new double[] { 0.0, 0.1, 1.0, 0.0 },
new double[] { 0.1, 0.0, 1.0, 0.1 },
};
double[][][] words = { hello, car, wardrobe };
int[] labels = { 0, 1, 2 };
var initial = new Independent
(
new NormalDistribution(0, 1),
new NormalDistribution(0, 1),
new NormalDistribution(0, 1),
new NormalDistribution(0, 1)
);
int numberOfWords = 3;
int numberOfStates = 5;
var classifier = new HiddenMarkovClassifier<Independent>
(
classes: numberOfWords,
topology: new Forward(numberOfStates),
initial: initial
);
var teacher = new HiddenMarkovClassifierLearning<Independent>(classifier,
modelIndex => new BaumWelchLearning<Independent>(classifier.Models[modelIndex])
{
Tolerance = 0.001,
Iterations = 100,
FittingOptions = new IndependentOptions()
{
InnerOption = new NormalOptions() { Regularization = 1e-5 }
}
}
);
double logLikelihood = teacher.Run(words, labels);
var function = new MarkovMultivariateFunction(classifier);
var hcrf = new HiddenConditionalRandomField<double[]>(function);
MemoryStream stream = new MemoryStream();
hcrf.Save(stream);
stream.Seek(0, SeekOrigin.Begin);
var target = HiddenConditionalRandomField<double[]>.Load(stream);
Assert.AreEqual(hcrf.Function.Factors.Length, target.Function.Factors.Length);
for (int i = 0; i < hcrf.Function.Factors.Length; i++)
{
var e = hcrf.Function.Factors[i];
var a = target.Function.Factors[i];
Assert.AreEqual(e.Index, target.Function.Factors[i].Index);
Assert.AreEqual(e.States, target.Function.Factors[i].States);
Assert.AreEqual(e.EdgeParameters.Count, a.EdgeParameters.Count);
Assert.AreEqual(e.EdgeParameters.Offset, a.EdgeParameters.Offset);
Assert.AreEqual(e.FactorParameters.Count, a.FactorParameters.Count);
Assert.AreEqual(e.FactorParameters.Offset, a.FactorParameters.Offset);
Assert.AreEqual(e.OutputParameters.Count, a.OutputParameters.Count);
Assert.AreEqual(e.OutputParameters.Offset, a.OutputParameters.Offset);
Assert.AreEqual(e.StateParameters.Count, a.StateParameters.Count);
Assert.AreEqual(e.StateParameters.Offset, a.StateParameters.Offset);
Assert.AreEqual(target.Function, a.Owner);
Assert.AreEqual(hcrf.Function, e.Owner);
}
Assert.AreEqual(hcrf.Function.Features.Length, target.Function.Features.Length);
for (int i = 0; i < hcrf.Function.Factors.Length; i++)
//.........这里部分代码省略.........