static void Main(string[] args) { StreamWriter file1 = new StreamWriter("d:\\" + "Result_MOBISIG_Scores_" + DateTime.Now.Ticks.ToString() + ".csv"); DTWConfiguration lDTWConfig = new DTWConfiguration(); List <double> lAllOriginalScoresGlobal = new List <double>(); List <double> lAllOriginalScoresGlobal2 = new List <double>(); List <double> lAllOriginalScoresLocal = new List <double>(); List <double> lAllImpostorScoresGlobal = new List <double>(); List <double> lAllImpostorScoresGlobal2 = new List <double>(); List <double> lAllImpostorScoresLocal = new List <double>(); Console.Write("Path to directory: "); string lPath = Console.ReadLine(); string[] lSubdirectoryEntries = Directory.GetDirectories(lPath); lDTWConfig = new DTWConfiguration() .UseXY() .UseX1Y1() .UseX2Y2(); int aNrOfTrainingSamples = 10; foreach (var directory in lSubdirectoryEntries) { Console.WriteLine("Processing " + directory + " directory"); List <Signature> lSignatures = SignatureFileUtils.GetAllSignaturesFromFolder(directory); //MCYT //List<Signature> lTemplate = lSignatures.Skip(25).Take(aNrOfTrainingSamples).ToList(); //List<Signature> lOriginalSignatures = lSignatures.Skip(25 + aNrOfTrainingSamples).Take(25 - aNrOfTrainingSamples).ToList(); //List<Signature> lImpostorSignatures = lSignatures.Take(15).ToList(); //MOBISIG List <Signature> lTemplate = lSignatures.Skip(20).Take(aNrOfTrainingSamples).ToList(); List <Signature> lOriginalSignatures = lSignatures.Skip(20 + aNrOfTrainingSamples).Take(25 - aNrOfTrainingSamples).ToList(); List <Signature> lImpostorSignatures = lSignatures.Take(15).ToList(); //retrieve feature set List <SignatureFeatures> lFeaturesTemplate = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesOriginal = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesImpostor = new List <SignatureFeatures>(); for (int i = 0; i < lTemplate.Count; ++i) { var lElement = lTemplate.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lTemplate.RemoveAt(i); lTemplate.Insert(i, lNewElement); lFeaturesTemplate.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lOriginalSignatures.Count; ++i) { var lElement = lOriginalSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lOriginalSignatures.RemoveAt(i); lOriginalSignatures.Insert(i, lNewElement); lFeaturesOriginal.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lImpostorSignatures.Count; ++i) { var lElement = lImpostorSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lImpostorSignatures.RemoveAt(i); lImpostorSignatures.Insert(i, lNewElement); lFeaturesImpostor.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } ManhattanDetector lManhattanDetector = new ManhattanDetector(lFeaturesTemplate); EuclideanDetector lEuclideanDetector = new EuclideanDetector(lFeaturesTemplate); List <double> lListOfScores = new List <double>(); //aDetector.CalculateScores() List <double> lOriginalScoresGlobal = lManhattanDetector.CompareToTemplate(lFeaturesOriginal); List <double> lImpostorScoresGlobal = lManhattanDetector.CompareToTemplate(lFeaturesImpostor); List <double> lOriginalScoresGlobal2 = lEuclideanDetector.CompareToTemplate(lFeaturesOriginal); List <double> lImpostorScoresGlobal2 = lEuclideanDetector.CompareToTemplate(lFeaturesImpostor); List <double> lOriginalScoresLocal = SignatureUtils.SignatureUtils.CompareSignaturesDTW(lTemplate, lOriginalSignatures, lDTWConfig); List <double> lImpostorScoresLocal = SignatureUtils.SignatureUtils.CompareSignaturesDTW(lTemplate, lImpostorSignatures, lDTWConfig); lAllOriginalScoresGlobal.AddRange(lOriginalScoresGlobal); lAllOriginalScoresGlobal2.AddRange(lOriginalScoresGlobal2); lAllOriginalScoresLocal.AddRange(lOriginalScoresLocal); lAllImpostorScoresGlobal.AddRange(lImpostorScoresGlobal); lAllImpostorScoresGlobal2.AddRange(lImpostorScoresGlobal2); lAllImpostorScoresLocal.AddRange(lImpostorScoresLocal); } file1.WriteLine("Original Scores Local" + "," + "Original Scores Manhattan" + "," + "Original Scores Euclidean"); for (int i = 0; i < lAllOriginalScoresLocal.Count; ++i) { file1.WriteLine(lAllOriginalScoresLocal.ElementAt(i) + "," + lAllOriginalScoresGlobal.ElementAt(i) + "," + lAllOriginalScoresGlobal2.ElementAt(i)); } file1.WriteLine("Impostor Scores Local" + "," + "Impostor Scores Manhattan" + "," + "Impostor Scores Euclidean"); for (int i = 0; i < lAllImpostorScoresLocal.Count; ++i) { file1.WriteLine(lAllImpostorScoresLocal.ElementAt(i) + "," + lAllImpostorScoresGlobal.ElementAt(i) + "," + lAllImpostorScoresGlobal2.ElementAt(i)); } file1.Close(); }
public static double CompareMCYTFusion(string aFolder, int aNrOfTrainingSamples, DTWConfiguration aDTWConfig, ref StreamWriter aSWriter) { List <Signature> lSignatures = SignatureFileUtils.GetAllSignaturesFromFolder(aFolder); List <Signature> lTemplate = lSignatures.Skip(25).Take(aNrOfTrainingSamples).ToList(); List <Signature> lOriginalSignatures = lSignatures.Skip(25 + aNrOfTrainingSamples).Take(25 - aNrOfTrainingSamples).ToList(); List <Signature> lImpostorSignatures = lSignatures.Take(15).ToList(); //retrieve feature set List <SignatureFeatures> lFeaturesTemplate = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesOriginal = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesImpostor = new List <SignatureFeatures>(); for (int i = 0; i < lTemplate.Count; ++i) { var lElement = lTemplate.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lTemplate.RemoveAt(i); lTemplate.Insert(i, lNewElement); lFeaturesTemplate.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lOriginalSignatures.Count; ++i) { var lElement = lOriginalSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lOriginalSignatures.RemoveAt(i); lOriginalSignatures.Insert(i, lNewElement); lFeaturesOriginal.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lImpostorSignatures.Count; ++i) { var lElement = lImpostorSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lImpostorSignatures.RemoveAt(i); lImpostorSignatures.Insert(i, lNewElement); lFeaturesImpostor.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } ManhattanDetector lEuclideanDetector = new ManhattanDetector(lFeaturesTemplate); List <double> lListOfScores = new List <double>(); //aDetector.CalculateScores() List <double> lOriginalScoresGlobal = lEuclideanDetector.CompareToTemplate(lFeaturesOriginal); List <double> lImpostorScoresGlobal = lEuclideanDetector.CompareToTemplate(lFeaturesImpostor); //int lNumberOfOriginalScores; //int lNumberOfImpostorScores; //lListOfScores.AddRange(lOriginalScoresGlobal); //lListOfScores.AddRange(lImpostorScoresGlobal); //lListOfScores = SignatureUtils.SignatureUtils.MinMaxNormalization(lListOfScores); //lNumberOfOriginalScores = lOriginalScoresGlobal.Count; //lNumberOfImpostorScores = lImpostorScoresGlobal.Count; //lOriginalScoresGlobal = new List<double>(); //lOriginalScoresGlobal.AddRange(lListOfScores.Take(lNumberOfOriginalScores)); //lImpostorScoresGlobal = new List<double>(); //lImpostorScoresGlobal.AddRange(lListOfScores.Skip(lNumberOfOriginalScores).Take(lNumberOfImpostorScores)); List <double> lOriginalScoresLocal = SignatureUtils.SignatureUtils.CompareSignaturesDTW(lTemplate, lOriginalSignatures, aDTWConfig); List <double> lImpostorScoresLocal = SignatureUtils.SignatureUtils.CompareSignaturesDTW(lTemplate, lImpostorSignatures, aDTWConfig); aSWriter.WriteLine("Original Scores Local" + "," + "Original Scores Global"); for (int i = 0; i < lOriginalScoresLocal.Count; ++i) { aSWriter.WriteLine(lOriginalScoresLocal.ElementAt(i) + "," + lOriginalScoresGlobal.ElementAt(i)); } //lListOfScores = new List<double>(); //lListOfScores.AddRange(lOriginalScoresLocal); //lListOfScores.AddRange(lImpostorScoresLocal); //lListOfScores = SignatureUtils.SignatureUtils.MinMaxNormalization(lListOfScores); //lNumberOfOriginalScores = lOriginalScoresLocal.Count; //lNumberOfImpostorScores = lImpostorScoresLocal.Count; //lOriginalScoresLocal = new List<double>(); //lOriginalScoresLocal.AddRange(lListOfScores.Take(lNumberOfOriginalScores)); //lImpostorScoresLocal = new List<double>(); //lImpostorScoresLocal.AddRange(lListOfScores.Skip(lNumberOfOriginalScores).Take(lNumberOfImpostorScores)); aSWriter.WriteLine("Impostor Scores Local" + "," + "Impostor Scores Global"); for (int i = 0; i < lImpostorScoresLocal.Count; ++i) { aSWriter.WriteLine(lImpostorScoresLocal.ElementAt(i) + "," + lImpostorScoresGlobal.ElementAt(i)); } //List<double> lOriginalScores = SignatureUtils.SignatureUtils.ScoreFusion(lOriginalScoresLocal, lOriginalScoresGlobal); //List<double> lImpostorScores = SignatureUtils.SignatureUtils.ScoreFusion(lImpostorScoresLocal, lImpostorScoresGlobal); //aSWriter.WriteLine("Impostor Scores"); //for (int i = 0; i < lImpostorScores.Count; ++i) //{ // aSWriter.WriteLine(lImpostorScores.ElementAt(i)); //} //aSWriter.WriteLine("Original Scores"); //for (int i = 0; i < lOriginalScores.Count; ++i) //{ // aSWriter.WriteLine(lOriginalScores.ElementAt(i)); //} //ErrorCalculation lError = ErrorCalculationFactory.GetDScoreErrorCalculator(); //lError.CalculateErrors(lOriginalScores, lImpostorScores, 100); //var lFARList = lError.GetFARList(); //var lFRRList = lError.GetFRRList(); //var lTresholdList = lError.GetThresholdList(); //for(int i = 0; i < lFARList.Count; ++i) //{ // aSWriter.WriteLine(lFARList.ElementAt(i) + "," + lFRRList.ElementAt(i) + ", " + lTresholdList.ElementAt(i)); //} //for (int i = 0; i < lOriginalScoresLocal.Count; ++i) //{ // aSWriter.WriteLine(lOriginalScoresLocal.ElementAt(i) + "," + lOriginalScoresGlobal.ElementAt(i)); //} //aSWriter.WriteLine(lError.GetERR()); return(1); }
public static double CompareMCYTFeatureBased(string aFolder, int aNrOfTrainingSamples, ref StreamWriter aSWriter) { List <Signature> lSignatures = SignatureFileUtils.GetAllSignaturesFromFolder(aFolder); List <Signature> lTemplate = lSignatures.Skip(25).Take(aNrOfTrainingSamples).ToList(); List <Signature> lOriginalSignatures = lSignatures.Skip(25 + aNrOfTrainingSamples).Take(25 - aNrOfTrainingSamples).ToList(); List <Signature> lImpostorSignatures = lSignatures.Take(15).ToList(); //retrieve feature set List <SignatureFeatures> lFeaturesTemplate = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesOriginal = new List <SignatureFeatures>(); List <SignatureFeatures> lFeaturesImpostor = new List <SignatureFeatures>(); for (int i = 0; i < lTemplate.Count; ++i) { var lElement = lTemplate.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lTemplate.RemoveAt(i); lTemplate.Insert(i, lNewElement); lFeaturesTemplate.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lOriginalSignatures.Count; ++i) { var lElement = lOriginalSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lOriginalSignatures.RemoveAt(i); lOriginalSignatures.Insert(i, lNewElement); lFeaturesOriginal.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } for (int i = 0; i < lImpostorSignatures.Count; ++i) { var lElement = lImpostorSignatures.ElementAt(i); var lNewElement = SignatureUtils.SignatureUtils.CalculateCharacteristics(lElement); lNewElement = SignatureUtils.SignatureUtils.StandardizeSignature(lNewElement); lImpostorSignatures.RemoveAt(i); lImpostorSignatures.Insert(i, lNewElement); lFeaturesImpostor.Add(FeatureCalculator.CalculateFeatures(lNewElement)); } ManhattanDetector lEuclideanDetector = new ManhattanDetector(lFeaturesTemplate); //aDetector.CalculateScores() List <double> lOriginalScores = lEuclideanDetector.CompareToTemplate(lFeaturesOriginal); List <double> lImpostorScores = lEuclideanDetector.CompareToTemplate(lFeaturesImpostor); ErrorCalculation lError = ErrorCalculationFactory.GetDScoreErrorCalculator(); lError.CalculateErrors(lOriginalScores, lImpostorScores, 100); //var lFARList = lError.GetFARList(); //var lFRRList = lError.GetFRRList(); //var lTresholdList = lError.GetThresholdList(); //for(int i = 0; i < lFARList.Count; ++i) //{ // aSWriter.WriteLine(lFARList.ElementAt(i) + "," + lFRRList.ElementAt(i) + ", " + lTresholdList.ElementAt(i)); //} aSWriter.WriteLine(lError.GetERR()); return(lError.GetERR()); }