static void ClassifyAndDump(short[] signal, SignalClassifier classifier, string folder, string fileName)
 {
     var result = classifier.Classify(signal).Select(ConvertClassMark).ToArray();
     var dump = new WavFileInfo(DefaultSampleRate, result);
     var filePath = string.Concat(folder, fileName, "_result", ".wav");
     dump.Write(filePath);
 }
        private static void ClassifyAll(string folder, string[] fileNames, SignalClassifier classifier)
        {
            foreach (var fileName in fileNames)
            {
                var wavFile = WavFileInfo.Read(string.Concat(folder, fileName, ".wav"));
                if (wavFile.SampleRate != DefaultSampleRate)
                {
                    throw new Exception(string.Format("File {0} has non-default sample rate", fileName));
                }
                ClassifyAndDump(wavFile.Data, classifier, folder, fileName);

                var markerFile = MarkerFileInfo.Read(string.Concat(folder, fileName, ".mrk"));
                var expectedWavFile = new WavFileInfo(wavFile.SampleRate,
                                                      markerFile.Decompress(wavFile.Data.Length)
                                                                .Select(ConvertClassMark)
                                                                .ToArray());
                expectedWavFile.Write(string.Concat(folder, fileName, "_expected", ".wav"));
            }
        }
        private static SignalClassifier TrainClassifier(string folder, string[] trainingSet, IFeatureExtractor[] featureExtractors, out double learningError)
        {
            var classifier = new SignalClassifier(featureExtractors);
            foreach (var fileName in trainingSet)
            {
                var wavFile = WavFileInfo.Read(string.Concat(folder, fileName, ".wav"));
                var markerFile = MarkerFileInfo.Read(string.Concat(folder, fileName, ".mrk"));

                classifier.AddTrainingSignal(wavFile.Data, markerFile.Decompress(wavFile.Data.Length));
            }
            classifier.Learn(out learningError);
            return classifier;
        }
        private static double EvaluateClassifier(string folder, string[] testSet, SignalClassifier classifier)
        {
            var errors = 0;
            var total = 0;
            foreach (var fileName in testSet)
            {
                var wavFile = WavFileInfo.Read(string.Concat(folder, fileName, ".wav"));
                var markerFile = MarkerFileInfo.Read(string.Concat(folder, fileName, ".mrk"));

                var actual = classifier.Classify(wavFile.Data);
                var expected = markerFile.Decompress(wavFile.Data.Length);
                total += wavFile.Data.Length;
                errors += GetErrorsCount(actual, expected);
            }
            return errors * 1.0 / total;
        }