public ClassifierBuildResult Build(TextDocument[] trainingSet, EnsembleParams ensembleParams)
        {
            var classifiers = ensembleParams.ClassifiersParams.Select(x => Build(trainingSet, ensembleParams.BaggingParams, x)).ToArray();
            var result = new ClassifiersEnsemble(classifiers);

            return ClassifierBuildResult.Create(result, trainingSet, ensembleParams.TargetTag);
        }
        public ClassifierBuildResult Build(TextDocument[] trainingSet, EnsembleParams ensembleParams)
        {
            var weightedDocuments = trainingSet.Select((x, i) => new WeightedDocument { Document = x, Weight = 1.0 / trainingSet.Length }).ToArray();

            var classifiers = new List<WeightedClassifier>();
            var classifierParamses = ensembleParams.ClassifiersParams;
            var targetTag = ensembleParams.TargetTag;

            for (int iteration = 0; iteration < classifierParamses.Length; iteration++)
            {
                Console.WriteLine("Running {0}/{1} boosting iteration", iteration + 1, classifierParamses.Length);
                var sampledTrainingSet = DoSampling(weightedDocuments);
                var binaryClassifierBuildResult = classifierBuilder.Build(sampledTrainingSet, classifierParamses[iteration]);
                var classifier = binaryClassifierBuildResult.Classifier;

                var error = weightedDocuments.Sum(x => classifier.IsClassifierWrong(x.Document, targetTag) ? x.Weight : 0);
                var alpha = 0.5 * Math.Log((1.0 - error) / error);
                foreach (var weightedDocument in weightedDocuments)
                {
                    if (classifier.IsClassifierWrong(weightedDocument.Document, targetTag))
                        weightedDocument.Weight *= Math.Exp(alpha);
                    else
                        weightedDocument.Weight *= Math.Exp(-alpha);
                }
                var z = weightedDocuments.Sum(x => x.Weight);
                foreach (var weightedDocument in weightedDocuments)
                {
                    weightedDocument.Weight /= z;
                }

                classifiers.Add(new WeightedClassifier { Classifier = classifier, Weight = alpha });

                Console.WriteLine("Error (weighted) = {0}", error);
                Console.WriteLine("Alpha = {0}", alpha);
                var evaluationResult = classifierEvaluator.Evaluate(classifier, trainingSet, targetTag);
                Console.WriteLine("FScore = {0}", evaluationResult.FScore);
            }

            var result = new ClassifiersEnsemble(classifiers);

            return ClassifierBuildResult.Create(result, trainingSet, targetTag);
        }
 public ClassifierBuildResult Build(TextDocument[] trainingSet, EnsembleParams ensembleParams)
 {
     var builder = builders.First(x => x.Type == ensembleParams.Type);
     return builder.Build(trainingSet, ensembleParams);
 }