Exemplo n.º 1
0
        public static void Calculate(string[] ids, DataSetLoader offlineLoader, DataSetLoader onlineLoader)
        {
            var offlineSigners = offlineLoader.EnumerateSigners(signer => ids.Contains(signer.ID)).ToList();
            var onlineSigners  = onlineLoader.EnumerateSigners(signer => ids.Contains(signer.ID)).ToList();

            var offlinePipeline = FusionPipelines.GetOfflinePipeline();
            var onlinePipeline  = FusionPipelines.GetOnlinePipeline();
            var fusionPipeline  = FusionPipelines.GetFusionPipeline(onlineSigners, false, 0);

            foreach (var offSigner in offlineSigners)
            {
                Console.WriteLine(offSigner.ID + " started at " + DateTime.Now.ToString("h:mm:ss tt"));
                var onSigner = onlineSigners.Find(signer => signer.ID == offSigner.ID);
                Parallel.ForEach(offSigner.Signatures, offSig =>
                {
                    offlinePipeline.Transform(offSig);
                    var onSig          = onSigner.Signatures.Find(sig => sig.ID == offSig.ID);
                    var onToOnPipeline = FusionPipelines.GetHackedOnToOnPipeline(offSig.GetFeature(FusionFeatures.Bounds));
                    onToOnPipeline.Transform(onSig);
                    onlinePipeline.Transform(onSig);
                }
                                 );

                Parallel.ForEach(offSigner.Signatures, offSig =>
                {
                    fusionPipeline.Transform(offSig);
                    onlinePipeline.Transform(offSig);
                }
                                 );

                var distViewer = FusionPipelines.GetDistanceMatrixViewer(onSigner.Signatures, offSigner.Signatures);
                TxtHelper.Save(TxtHelper.ArrayToLines(distViewer.Calculate()), "distancematrix" + offSigner.ID);
            }
        }
Exemplo n.º 2
0
        public static void Calculate(string[] ids, DataSetLoader offlineLoader, DataSetLoader onlineLoader)
        {
            var offlineSigners = offlineLoader.EnumerateSigners(signer => ids.Contains(signer.ID)).ToList();
            var onlineSigners  = onlineLoader.EnumerateSigners(signer => ids.Contains(signer.ID)).ToList();


            var offlinePipeline = FusionPipelines.GetOfflinePipeline();

            foreach (var offSigner in offlineSigners)
            {
                Console.WriteLine(offSigner.ID + " started at " + DateTime.Now.ToString("h:mm:ss tt"));
                var onSigner = onlineSigners.Find(signer => signer.ID == offSigner.ID);
                Parallel.ForEach(offSigner.Signatures, offSig =>
                {
                    Console.WriteLine("Preprocess - " + offSig.Signer.ID + "_" + offSig.ID + "started at " + DateTime.Now.ToString("h:mm:ss tt"));
                    offlinePipeline.Transform(offSig);
                    var onSig          = onSigner.Signatures.Find(sig => sig.ID == offSig.ID);
                    var onToOnPipeline = FusionPipelines.GetHackedOnToOnPipeline(offSig.GetFeature(FusionFeatures.Bounds));
                    onToOnPipeline.Transform(onSig);
                }
                                 );

                int numOfRef   = 10;
                int numOfGen   = 20;
                var references = onSigner.Signatures.FindAll(sig => sig.Origin == Origin.Genuine).Take(numOfRef).ToList();
                var genuines   = offSigner.Signatures.FindAll(sig => sig.Origin == Origin.Genuine).Take(numOfGen).ToList();

                double[,] results = new double[references.Count, genuines.Count];

                for (int i = 0; i < references.Count; i++)
                {
                    var fusionPipeline = FusionPipelines.GetFusionPipeline(onlineSigners, false, i);
                    Parallel.For(0, genuines.Count, j =>
                    {
                        Console.WriteLine("ref: {0}, sig: {1}", i, j);
                        fusionPipeline.Transform(genuines[j]);
                    }
                                 );
                    var pairingDists = new StrokePairingDistances
                    {
                        InputOfflineTrajectory = FusionFeatures.Trajectory,
                        InputOnlineTrajectory  = FusionFeatures.Trajectory,
                        OnlineSignatures       = onSigner.Signatures,
                        OfflineSignatures      = genuines
                    };
                    var newDists = pairingDists.Calculate();
                    if (newDists.Count != results.GetLength(1))
                    {
                        throw new Exception();
                    }
                    for (int j = 0; j < newDists.Count; j++)
                    {
                        results[i, j] = newDists[j].Item3;
                        Console.WriteLine(results[i, j]);
                    }
                }
                TxtHelper.Save(TxtHelper.ArrayToLines(results), "pairingmatrix" + offSigner.ID);
            }
        }