Esempio n. 1
0
        public void TestDeserialization()
        {
            var expectedVerifier = new VerifierBenchmark()
            {
                Loader   = new Svc2004Loader(@"Databases\Online\SVC2004\Task2.zip".GetPath(), true),
                Verifier = new Verifier()
                {
                    Pipeline = new SequentialTransformPipeline
                    {
                        new NormalizeRotation()
                        {
                            InputX = Features.X, InputY = Features.Y, InputT = Features.T, OutputX = Features.X, OutputY = Features.Y
                        },

                        new Scale()
                        {
                            InputFeature = Features.X, OutputFeature = Features.X
                        },
                        new Scale()
                        {
                            InputFeature = Features.Y, OutputFeature = Features.Y
                        },
                        new FillPenUpDurations()
                        {
                            InputFeatures = new List <FeatureDescriptor <List <double> > >()
                            {
                                Features.X, Features.Y, Features.Pressure
                            },
                            OutputFeatures = new List <FeatureDescriptor <List <double> > >()
                            {
                                Features.X, Features.Y, Features.Pressure
                            },
                            InterpolationType = typeof(CubicInterpolation),
                            TimeInputFeature  = Features.T,
                            TimeOutputFeature = Features.T
                        }
                    }
                    ,
                    Classifier = new OptimalDtwClassifier()
                    {
                        Sampler  = new FirstNSampler(10),
                        Features = new List <FeatureDescriptor>()
                        {
                            Features.X, Features.Y, Features.Pressure
                        }
                    }
                },
                Sampler = new FirstNSampler(10),
                Logger  = new SimpleConsoleLogger(),
            };
            var verifierJson         = SerializationHelper.JsonSerialize(expectedVerifier);
            var deserializedVerifier = SerializationHelper.Deserialize <VerifierBenchmark>(verifierJson);

            JsonAssert.AreEqual(expectedVerifier, deserializedVerifier);
        }
Esempio n. 2
0
        private void TestClassifier()
        {
            ProgressValue = 0;
            App.Current.Dispatcher.Invoke(delegate
            {
                StatisticsProgressBar.Visibility = Visibility.Visible;
            });

            var logger           = new Logger(LogLevel.Debug, null, Log);
            var benchmarkResults = new Dictionary <List <FeatureDescriptor>, BenchmarkResults>(Common.Configuration.TestInputFeatures.Length);


            string transformPipelineElementsNames = "";

            foreach (var featureFilter in Common.Configuration.TestInputFeatures)
            {
                IClassifier classifier = GetClassifier(featureFilter);

                transformPipelineElementsNames = "";
                var transformPipeline = new SequentialTransformPipeline()
                {
                    new DerivedSvc2004FeatureExtractor()
                };
                if (IsNormalizationSelected)
                {
                    transformPipeline.Add(new Svc2004Normalize()); transformPipelineElementsNames += "_Norm";
                }
                if (IsCentroidSelected)
                {
                    transformPipeline.Add(new CentroidTranslate()); transformPipelineElementsNames += "_Centroid";
                }
                if (IsCenteringSelected)
                {
                    transformPipeline.Add(new CenteringTransform()); transformPipelineElementsNames += "_Centering";
                }

                benchmark = new VerifierBenchmark()
                {
                    //Loader = new Svc2004Loader(@"..\..\..\SigStat.Sample\Databases\Online\SVC2004\Task2.zip", true, s => s.ID.CompareTo("05") < 0),
                    //Loader = new Svc2004Loader(@"..\..\..\SigStat.Sample\Databases\Online\SVC2004\Task2.zip", true, s => s.ID == "02"),
                    Loader   = new Svc2004Loader(@"..\..\..\SigStat.Sample\Databases\Online\SVC2004\Task2.zip", true),
                    Sampler  = IsOptiClass ? MySampler.AllReferences : MySampler.Basic,
                    Verifier = new MyVerifier(classifier)
                    {
                        TransformPipeline = transformPipeline
                    },
                    Logger = logger,
                };
                benchmark.ProgressChanged += Bm_ProgressChanged;
                benchmarkResults.Add(featureFilter, benchmark.Execute());

                string dumpFileName = DateTime.Now.ToString().Replace(':', '.') + "_" + classifier.Name + transformPipelineElementsNames + "_Dump.xlsx";
                DumpLog(dumpFileName, logger.ObjectEntries);
                Process.Start(dumpFileName);
            }



            //string classifierName = ((MyVerifier)benchmark.Verifier).Classifier.GetType().Name;


            string fileName = DateTime.Now.ToString().Replace(':', '.') + "_" + GetClassifier(Common.Configuration.DefaultInputFeatures).Name + transformPipelineElementsNames + ".xlsx";

            using (var package = new ExcelPackage(new FileInfo(fileName)))
            {
                foreach (var featureFilter in Common.Configuration.TestInputFeatures)
                {
                    string wsName = "";
                    foreach (var feature in featureFilter)
                    {
                        wsName += feature.Name;
                    }
                    ExcelWorksheet ws = ExcelHelper.GetWorkSheetFromPackage(package, wsName);
                    ExcelHelper.SetBenchmarkresultOfClassificationHeader(ws);

                    var results = benchmarkResults[featureFilter];
                    foreach (var result in results.SignerResults)
                    {
                        ExcelHelper.SetBenchmarkresultOfClassificationRow(ws, result);
                    }

                    ExcelHelper.SetBenchmarkresultOfClassificationSummaryRow(ws, results.FinalResult, results.SignerResults.Count + 2);
                    package.Save();
                }
            }

            Process.Start(fileName);
        }
Esempio n. 3
0
        internal static async Task RunAsync(string inputDir, string outputDir, int procId, int maxThreads)
        {
            //stop worker process after 3 days
            DateTime stopTime = DateTime.Now.AddHours(71);

            //delayed start
            await Task.Delay(100 *procId);

            OutputDirectory = Directory.CreateDirectory(outputDir);

            var initSuccess = await Init(inputDir);

            if (!initSuccess)
            {
                return;
            }

            Console.WriteLine($"{DateTime.Now}: Worker is running.");
            if (!Console.IsInputRedirected)
            {
                Console.WriteLine("Press 'A' to abort.");
            }

            while (DateTime.Now < stopTime)
            {
                StringBuilder debugInfo = new StringBuilder();
                debugInfo.AppendLine(DateTime.Now.ToString());

                if (!Console.IsInputRedirected)
                {
                    if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.A)
                    {
                        Console.WriteLine($"{DateTime.Now}: Aborting...");
                        return;
                    }
                }


                var logger = new SimpleConsoleLogger();//default log level: Information
                logger.Logged += (m, e, l) =>
                {
                    debugInfo.AppendLine(m);
                    if (e != null)
                    {
                        debugInfo.AppendLine(e.ToString());
                    }
                    if (l == LogLevel.Error || l == LogLevel.Critical)
                    {
                        CurrentResultType = "Error";
                    }
                };

                CurrentBenchmark = await GetNextBenchmark();

                if (CurrentBenchmark is null)
                {
                    return;
                }
                CurrentBenchmark.Logger = logger;

                Console.WriteLine($"{DateTime.Now}: Starting benchmark...");

                try
                {
                    if (maxThreads > 0)
                    {
                        CurrentResults = CurrentBenchmark.Execute(maxThreads);
                    }
                    else
                    {
                        CurrentResults = CurrentBenchmark.Execute(true);//default: no restriction
                    }
                    CurrentResultType = "Success";
                }
                catch (Exception exc)
                {
                    CurrentResultType = "Error";
                    Console.WriteLine(exc.ToString());
                    debugInfo.AppendLine(exc.ToString());
                    var debugFileName = $"Result_{CurrentBenchmarkId}_Log.txt";

                    debugFileName = Path.Combine(OutputDirectory.ToString(), debugFileName);
                    File.WriteAllText(debugFileName, debugInfo.ToString());

                    if (!Program.Offline)
                    {
                        var blob = Container.GetBlockBlobReference($"Results/{debugFileName}");
                        await blob.DeleteIfExistsAsync();

                        await blob.UploadFromFileAsync(debugFileName);
                    }
                    continue;
                }

                await ProcessResults();

                if (Program.Offline)
                {//delete input config and lock after processing
                    File.Delete(Path.Combine(InputDirectory.ToString(), CurrentBenchmarkId + ".json"));
                    File.Delete(Path.Combine(InputDirectory.ToString(), CurrentBenchmarkId + ".json.lock"));
                }
                else
                {
                    await Queue.DeleteMessageAsync(CurrentMessage);
                }

                //LogProcessor.Dump(logger);
                // MongoDB
                // TableStorage
                // Json => utólag, json-ben szűrni lehet
                // DynamoDB ==> MongoDB $$$$$$$
                // DateTime, MachineName, ....ExecutionTime,..., ResultType, Result json{40*60 táblázat}
                //benchmark.Dump(filename, config.ToKeyValuePairs());
            }
        }
Esempio n. 4
0
        //static LinearInterpolation linearInterpolation = new LinearInterpolation();
        //static CubicInterpolation cubicInterpolation = new CubicInterpolation();
        //TODO: legyen allapotmentes a maradek is?

        public static VerifierBenchmark Build(BenchmarkConfig config, string databasePath = null)
        {
            if (databasePath == null)
            {
                databasePath = Environment.GetEnvironmentVariable("SigStatDB");
            }

            svcLoader      = new Svc2004Loader(Path.Combine(databasePath, "SVC2004.zip"), true);
            mcytLoader     = new MCYTLoader(Path.Combine(databasePath, "MCYT100.zip"), true);
            dutchLoader    = new SigComp11DutchLoader(Path.Combine(databasePath, "SigComp11_Dutch.zip"), true);
            chineseLoader  = new SigComp11ChineseLoader(Path.Combine(databasePath, "SigComp11Chinese.zip"), true);
            germanLoader   = new SigComp15GermanLoader(Path.Combine(databasePath, "SigWiComp2015_German.zip"), true);
            japaneseLoader = new SigComp13JapaneseLoader(Path.Combine(databasePath, "SigWiComp2013_Japanese.zip"), true);

            //labor:
            //svcLoader = new Svc2004Loader(@"Task2.zip", true);
            //mcytLoader = new MCYTLoader(@"MCYT_Signature_100.zip", true);
            //dutchLoader = new SigComp11DutchLoader(@"dutch_renamed.zip", true);


            Sampler sampler1 = null;
            Sampler sampler2 = null;
            Sampler sampler3 = null;
            Sampler sampler4 = null;


            VerifierBenchmark b = new VerifierBenchmark();

            switch (config.Database)
            {
            case "SVC2004":
                b.Loader = svcLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            case "MCYT100":
                b.Loader = mcytLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            case "DUTCH":
                b.Loader = dutchLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            case "GERMAN":
                b.Loader = germanLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            case "CHINESE":
                b.Loader = chineseLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            case "JAPANESE":
                b.Loader = japaneseLoader;
                sampler1 = first10Sampler;
                sampler2 = last10Sampler;
                sampler3 = even10Sampler;
                sampler4 = odd10Sampler;
                break;

            default:
                throw new NotSupportedException();
            }

            switch (config.Sampling)
            {
            case "S1":
                b.Sampler = sampler1;
                break;

            case "S2":
                b.Sampler = sampler2;
                break;

            case "S3":
                b.Sampler = sampler3;
                break;

            case "S4":
                b.Sampler = sampler4;
                break;

            default:
                break;
            }


            var pipeline = new SequentialTransformPipeline();

            //Filter first
            switch (config.ResamplingType_Filter)
            {
            case "P":
            case "P_FillPenUp":
                pipeline.Add(filterPoints);
                break;

            case "None":
            default:
                break;
            }

            if (config.Rotation)
            {
                pipeline.Add(normalizeRotation);
            }

            switch (config.Translation_Scaling.Translation)
            {
            case "CogToOriginX":
                pipeline.Add(cxTranslate);
                break;

            case "CogToOriginY":
                pipeline.Add(cyTranslate);
                break;

            case "CogToOriginXY":
                pipeline.Add(cxTranslate);
                pipeline.Add(cyTranslate);
                break;

            case "BottomLeftToOrigin":
                pipeline.Add(blxTranslate);
                pipeline.Add(blyTranslate);
                break;

            case "None":
            default:
                break;
            }

            switch (config.Translation_Scaling.Scaling)
            {
            case "X01":
                pipeline.Add(xScale);
                if (config.Features.Contains("P"))
                {
                    pipeline.Add(pScale);
                }
                break;

            case "Y01":
                pipeline.Add(yScale);
                if (config.Features.Contains("P"))
                {
                    pipeline.Add(pScale);
                }
                break;

            case "P01":
                pipeline.Add(pScale);
                break;

            case "X01Y01":
                pipeline.Add(xScale);
                pipeline.Add(yScale);
                pipeline.Add(pScale);
                break;

            case "X01Y0prop":
                pipeline.Add(xyUniformScale);
                if (config.Features.Contains("P"))
                {
                    pipeline.Add(pScale);
                }
                break;

            case "Y01X0prop":
                pipeline.Add(yxUniformScale);
                if (config.Features.Contains("P"))
                {
                    pipeline.Add(pScale);
                }
                break;

            case "None":
                if (config.Features.Contains("P"))
                {
                    pipeline.Add(pRelativeScale);
                }
                break;

            default:
                break;
            }

            Type ip;

            switch (config.Interpolation)
            {
            case "Cubic":
                ip = typeof(CubicInterpolation);
                break;

            case "Linear":
            default:
                ip = typeof(LinearInterpolation);
                break;
            }

            var featurelist = new List <FeatureDescriptor <List <double> > >()
            {
                Features.X, Features.Y, Features.Pressure, Features.Azimuth, Features.Altitude
            };

            //resample after transformations
            switch (config.ResamplingType_Filter)
            {
            case "SampleCount":
                pipeline.Add(new ResampleSamplesCountBased()
                {
                    InputFeatures     = featurelist,
                    OutputFeatures    = featurelist,
                    OriginalTFeature  = Features.T,
                    ResampledTFeature = Features.T,
                    NumOfSamples      = (int)config.ResamplingParam,
                    InterpolationType = ip
                });
                break;

            case "P_FillPenUp":
            case "FillPenUp":
                pipeline.Add(new FillPenUpDurations()
                {
                    InputFeatures     = featurelist,
                    OutputFeatures    = featurelist,
                    TimeInputFeature  = Features.T,
                    TimeOutputFeature = Features.T,
                    InterpolationType = ip
                });
                break;

            case "None":
            default:
                break;
            }

            var ClassifierFeatures = new List <FeatureDescriptor>();

            switch (config.Features)
            {
            case "X":
                ClassifierFeatures.Add(Features.X);
                break;

            case "XP":
                ClassifierFeatures.Add(Features.X);
                ClassifierFeatures.Add(Features.Pressure);
                break;

            case "Y":
                ClassifierFeatures.Add(Features.Y);
                break;

            case "YP":
                ClassifierFeatures.Add(Features.Y);
                ClassifierFeatures.Add(Features.Pressure);
                break;

            case "P":
                ClassifierFeatures.Add(Features.Pressure);
                break;

            case "Azimuth":
                ClassifierFeatures.Add(Features.Azimuth);
                break;

            case "Altitude":
                ClassifierFeatures.Add(Features.Altitude);
                break;

            case "XY":
                ClassifierFeatures.Add(Features.X);
                ClassifierFeatures.Add(Features.Y);
                break;

            case "XYP":
                ClassifierFeatures.Add(Features.X);
                ClassifierFeatures.Add(Features.Y);
                ClassifierFeatures.Add(Features.Pressure);
                break;

            case "XYPAzimuthAltitude":
                ClassifierFeatures.Add(Features.X);
                ClassifierFeatures.Add(Features.Y);
                ClassifierFeatures.Add(Features.Pressure);
                ClassifierFeatures.Add(Features.Azimuth);
                ClassifierFeatures.Add(Features.Altitude);
                break;

            default:
                break;
            }

            Func <double[], double[], double> distance = null;

            switch (config.Distance)
            {
            case "Euclidean":
                distance = Accord.Math.Distance.Euclidean;
                break;

            case "Manhattan":
                distance = Accord.Math.Distance.Manhattan;
                break;

            default:
                break;
            }
            IClassifier classifier;

            if (config.Classifier == "Dtw")
            {
                classifier = new DtwClassifier(distance);
                (classifier as DtwClassifier).Features = ClassifierFeatures;
            }
            else if (config.Classifier == "OptimalDtw")
            {
                classifier = new OptimalDtwClassifier(distance)
                {
                    Features = ClassifierFeatures,
                    Sampler  = b.Sampler
                };
            }
            else
            {
                throw new NotSupportedException();
            }

            b.Verifier = new Model.Verifier()
            {
                Pipeline   = pipeline,
                Classifier = classifier
            };

            b.Parameters = config.ToKeyValuePairs().ToList();

            return(b);
        }