public NaiveBayesClassifier(Pair <TClass, TFeatures[]>[] training) { ExpandingCollator <TFeatures> tfeats = new ExpandingCollator <TFeatures>(); ExpandingCollator <TClass> tclass = new ExpandingCollator <TClass>(); ClassFeatureList[] cfl = Array.ConvertAll(training, x => new ClassFeatureList() { cls = tclass[x.a], features = Array.ConvertAll(x.b, feat => tfeats[feat]) } ); ffeats = new FixedCollator <TFeatures>(tfeats); fclasses = new FixedCollator <TClass>(tclass); classifier = new NaiveBayesClassifier(cfl, fclasses.Count, ffeats.Count); }
public HiddenMarkovModel(Expectation <TInput, TOutput>[] training, HiddenMarkovModel.GenerationMethod generationMethod) { ExpandingCollator <TInput> tinputs = new ExpandingCollator <TInput>(); ExpandingCollator <TOutput> toutputs = new ExpandingCollator <TOutput>(); // collect the types Expectation <int, int>[] intExpectation = Array.ConvertAll(training, x => new Expectation <int, int>( Array.ConvertAll(x.expectation, y => new Pair <int, int>() { a = tinputs[y.a], b = toutputs[y.b] } ))); inputs = new FixedCollator <TInput>(tinputs); outputs = new FixedCollator <TOutput>(toutputs); hmm = new HiddenMarkovModel(intExpectation, tinputs.Count, toutputs.Count, generationMethod); }