Example #1
0
 public LoginService(IMainProcessor processor)
 {
     this.processor = processor;
     this.isLoggedIn = false;
     this.timer = new Stopwatch();
     this.timer.Start();
     this.priority = new LifoAlgorithm<UserImageItem>();
     this.currentImages = new List<Image<Bgr, byte>>();
 }
        public ProfileFaceDetector()
            : base()
        {
            this.priorityAlgorithm = new LifoAlgorithm<ProfileFaceItem>();

            //this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(true, 0.5)));
            //this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(false, 0.5)));
            this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(true, 1)));
            this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(false, 1)));
            //this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(true, 1.5)));
            //this.priorityAlgorithm.AddAlgorithmItem(new ProfileFacePriorityItem(new ProfileFaceItem(false, 1.5)));
        }
Example #3
0
        //Implement priority
        public FaceDetector(EyeDetector eyeDetector)
        {
            this.eyeDetector = eyeDetector;
            this.lastDetected = new Face();
            this.notDetectedTimer = new Stopwatch();

            this.facePriority = new LifoAlgorithm<BaseFaceDetector>();
            this.frontalFacePriorityItem = new FaceDetectorPriority(new FrontalFaceDetector());
            this.profileFacePriorityItem = new FaceDetectorPriority(new ProfileFaceDetector());
            this.rotatedFacePriorityItem = new FaceDetectorPriority(new RotatedFaceDetector());
            this.facePriority.AddAlgorithmItem(this.frontalFacePriorityItem);
            this.facePriority.AddAlgorithmItem(this.profileFacePriorityItem);
            this.facePriority.AddAlgorithmItem(this.rotatedFacePriorityItem);
        }
        public SingleSequenceBenchmark(int cacheSize, int sequenceSizeMultiplier, int distinctPagesCount)
        {
            CacheSize = cacheSize;
            SequenceSizeMultiplier  = sequenceSizeMultiplier;
            DistinctPagesCount      = distinctPagesCount;
            RandomGeneratorSequence = new Random();

            InputSequence = new int[CacheSize * SequenceSizeMultiplier];

            for (int i = 0; i < InputSequence.Length; i++)
            {
                InputSequence[i] = RandomGeneratorSequence.Next(distinctPagesCount + 1);
            }

            #region Initializing Algorithms

            FifoAlgorithm       = new FifoAlgorithm(cacheSize);
            LargerFifoAlgorithm = new FifoAlgorithm(cacheSize + 1);

            Fifo2Algorithm       = new Fifo2Algorithm(cacheSize);
            LargerFifo2Algorithm = new Fifo2Algorithm(cacheSize + 1);

            LruAlgorithm       = new LruAlgorithm(cacheSize);
            LargerLruAlgorithm = new LruAlgorithm(cacheSize + 1);

            Lru2Algorithm       = new Lru2Algorithm(cacheSize);
            LargerLru2Algorithm = new Lru2Algorithm(cacheSize + 1);

            MruAlgorithm       = new MruAlgorithm(cacheSize);
            LargerMruAlgorithm = new MruAlgorithm(cacheSize + 1);

            BitPlruAlgorithm       = new BitPlruAlgorithm(cacheSize);
            LargerBitPlruAlgorithm = new BitPlruAlgorithm(cacheSize + 1);

            FwfAlgorithm       = new FwfAlgorithm(cacheSize);
            LargerFwfAlgorithm = new FwfAlgorithm(cacheSize + 1);

            LifoAlgorithm       = new LifoAlgorithm(cacheSize);
            LargerLifoAlgorithm = new LifoAlgorithm(cacheSize + 1);

            UniformRandomPageAlgorithm       = new UniformRandomPageAlgorithm(cacheSize);
            LargerUniformRandomPageAlgorithm = new UniformRandomPageAlgorithm(cacheSize + 1);

            #endregion
        }
        public RotatedFaceDetector()
            : base()
        {
            this.priorityAlgorithm = new LifoAlgorithm<RotatedFaceItem>();

            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(19)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-19)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(18)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-18)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(20)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-20)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(22)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-22)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(24)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-24)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(26)));
            this.priorityAlgorithm.AddAlgorithmItem(new RotatedFacePriorityItem(new RotatedFaceItem(-26)));
        }
        public SingleSequenceBenchmarkResult RunBenchmarkForAllAlgorithms()
        {
            var result = new SingleSequenceBenchmarkResult(CacheSize,
                                                           SequenceSizeMultiplier, DistinctPagesCount);

            for (int i = 0; i < InputSequence.Length; i++)
            {
                var currentInput = InputSequence[i];

                if (LargerFifoAlgorithm.HandleSingleInput(currentInput) >
                    FifoAlgorithm.HandleSingleInput(currentInput))
                {
                    result.FifoAnomalyCount++;
                }

                if (LargerFifo2Algorithm.HandleSingleInput(currentInput) >
                    Fifo2Algorithm.HandleSingleInput(currentInput))
                {
                    result.Fifo2AnomalyCount++;
                }

                if (LargerLruAlgorithm.HandleSingleInput(currentInput) >
                    LruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.LruAnomalyCount++;
                }

                if (LargerLru2Algorithm.HandleSingleInput(currentInput) >
                    Lru2Algorithm.HandleSingleInput(currentInput))
                {
                    result.Lru2AnomalyCount++;
                }

                if (LargerMruAlgorithm.HandleSingleInput(currentInput) >
                    MruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.MruAnomalyCount++;
                }

                if (LargerBitPlruAlgorithm.HandleSingleInput(currentInput) >
                    BitPlruAlgorithm.HandleSingleInput(currentInput))
                {
                    result.BitPlruAnomalyCount++;
                }

                if (LargerFwfAlgorithm.HandleSingleInput(currentInput) >
                    FwfAlgorithm.HandleSingleInput(currentInput))
                {
                    result.FwfAnomalyCount++;
                }

                if (LargerLifoAlgorithm.HandleSingleInput(currentInput) >
                    LifoAlgorithm.HandleSingleInput(currentInput))
                {
                    result.LifoAnomalyCount++;
                }

                {
                    var largerPreviousRandomNumbersCount = LargerUniformRandomPageAlgorithm.
                                                           RandomNumbers.Count;

                    var largerUniformRandomPageCost = LargerUniformRandomPageAlgorithm.
                                                      HandleSingleInput(currentInput);

                    if (LargerUniformRandomPageAlgorithm.RandomNumbers.Count >
                        largerPreviousRandomNumbersCount)
                    {
                        UniformRandomPageAlgorithm.RandomNumbers.Add(
                            LargerUniformRandomPageAlgorithm.RandomNumbers.Last());

                        Debug.Assert(UniformRandomPageAlgorithm.RandomNumbers.Count ==
                                     LargerUniformRandomPageAlgorithm.RandomNumbers.Count,
                                     "Error in retaining random numbers between two algorithms.");
                    }

                    var previousRandomNumbersCount = UniformRandomPageAlgorithm.
                                                     RandomNumbers.Count;

                    var uniformRandomPageCost = UniformRandomPageAlgorithm.HandleSingleInput(currentInput);

                    if (UniformRandomPageAlgorithm.RandomNumbers.Count >
                        previousRandomNumbersCount)
                    {
                        LargerUniformRandomPageAlgorithm.RandomNumbers.Add(
                            UniformRandomPageAlgorithm.RandomNumbers.Last());

                        Debug.Assert(UniformRandomPageAlgorithm.RandomNumbers.Count ==
                                     LargerUniformRandomPageAlgorithm.RandomNumbers.Count,
                                     "Error in retaining random numbers between two algorithms.");
                    }

                    if (largerUniformRandomPageCost > uniformRandomPageCost)
                    {
                        result.UniformRandomPageAnomalyCount++;
                    }
                }
            }

            result.FifoCost       = FifoAlgorithm.CurrentCost;
            result.LargerFifoCost = LargerFifoAlgorithm.CurrentCost;

            result.Fifo2Cost       = Fifo2Algorithm.CurrentCost;
            result.LargerFifo2Cost = LargerFifo2Algorithm.CurrentCost;

            result.LruCost       = LruAlgorithm.CurrentCost;
            result.LargerLruCost = LargerLruAlgorithm.CurrentCost;

            result.Lru2Cost       = Lru2Algorithm.CurrentCost;
            result.LargerLru2Cost = LargerLru2Algorithm.CurrentCost;

            result.BitPlruCost       = BitPlruAlgorithm.CurrentCost;
            result.LargerBitPlruCost = LargerBitPlruAlgorithm.CurrentCost;

            result.MruCost       = MruAlgorithm.CurrentCost;
            result.LargerMruCost = LargerMruAlgorithm.CurrentCost;

            result.LifoCost       = LifoAlgorithm.CurrentCost;
            result.LargerLifoCost = LargerLifoAlgorithm.CurrentCost;

            result.FwfCost       = FwfAlgorithm.CurrentCost;
            result.LargerFwfCost = LargerFwfAlgorithm.CurrentCost;

            result.UniformRandomPageCost       = UniformRandomPageAlgorithm.CurrentCost;
            result.LargerUniformRandomPageCost = LargerUniformRandomPageAlgorithm.CurrentCost;

            return(result);
        }