Exemple #1
0
        static void Main(string[] args)
        {
            InputLoader loader = new InputLoader();

            loader.LoadFile("digits.csv");
            Stopwatch sw = new Stopwatch();

            var heursiticDetection = new HeuristicDetection(10, 5, quantity: 50, numberOfPoints: 500);
            var hypothesis         = new CurrentHypothesis();

            foreach (var input in loader.AllElements())
            {
                ///For every new input we extract n points of interest
                ///And create a feature vector which characterizes the spatial relationship between these features
                ///For every heuristic we get a dictionary of points of interest
                DetectedPoints v = heursiticDetection.getFeatureVector(input.Item1);

                ///Compare this feature vector agaist each of the other feature vectors we know about
                sw.Reset();
                sw.Start();
                TestResult r = hypothesis.Predict(v);
                Debug.Print("Prediction: " + sw.Elapsed.Milliseconds.ToString());
                var best = r.BestResult();
                if (best != null && best.Item2 != 0)
                {
                    LogProgress(best.Item1, input.Item2);
                }

                sw.Reset();
                sw.Start();
                hypothesis.Train(v, input.Item2, r);
                Debug.Print("Training: " + sw.Elapsed.Milliseconds.ToString());
                //heursiticDetection.pointsOfInterest.Add(HeuristicDetection.Generate(10, 5, 10));
            }
        }
Exemple #2
0
        public DetectedPoints getFeatureVector(int[][] p)
        {
            DetectedPoints output = new DetectedPoints();

            foreach (var a in pointsOfInterest)
            {
                output[a.IndexVal] = a.Locate(p);
            }
            return(output);
        }
        public TestResult Predict(DetectedPoints pts)
        {
            TestResult result = new TestResult();
            Dictionary <Label, double> results = new Dictionary <Label, double>();

            foreach (var a in library)
            {
                double comparison = a.Value.Compare(pts);
                results[a.Key] = comparison;
            }
            result.Add(results);
            return(result);
        }
 internal void Sanitize(DetectedPoints pts)
 {
     foreach (var heur in pts.Keys)
     {
         foreach (var eval in pts[heur].Keys)
         {
             if (!this[heur].ContainsKey(eval))
             {
                 continue;
             }
             //We want to compare two geometrical pixel spaces:
             if (comparePixelSpaces(pts[heur][eval], this[heur][eval]) > 1000)
             {
                 this[heur].Remove(eval);
             }
             //int union = pts[heur][eval].Union(this[heur][eval]).Count();
             //double spaceSize = (pts[heur][eval].Count() + this[heur][eval].Count() - union) + .0001;
             //comparison += ((double)union) / spaceSize;
         }
     }
 }
        ///We are interested in the spatial relationship between detected points across different
        ///pieces of input contrlling for their labels
        public double Compare(DetectedPoints pts)
        {
            double comparison = 0;

            foreach (var heur in pts.Keys)
            {
                foreach (var eval in pts[heur].Keys)
                {
                    if (!this[heur].ContainsKey(eval))
                    {
                        continue;
                    }
                    //We want to compare two geometrical pixel spaces:
                    comparison += comparePixelSpaces(pts[heur][eval], this[heur][eval]);
                    //int union = pts[heur][eval].Union(this[heur][eval]).Count();
                    //double spaceSize = (pts[heur][eval].Count() + this[heur][eval].Count() - union) + .0001;
                    //comparison += ((double)union) / spaceSize;
                }
            }
            return(comparison);
        }
 internal void Train(DetectedPoints pts, Label label, TestResult result)
 {
     if (!library.ContainsKey(label))
     {
         library[label] = pts;
     }
     else
     {
         var baseVal = library[label].Compare(pts);
         foreach (var a in library)
         {
             if (a.Key == label)
             {
                 continue;
             }
             var a1 = a.Value.Compare(pts);
             if (a1 > baseVal)
             {
                 a.Value.Sanitize(pts);
             }
         }
     }
 }