Example #1
0
        static ScoreStats GetScoreStats(int Rows, BlockedImage[] images, Kernel kernel, int InLabel, BlockTracker tracker = null)
        {
            var stats = new ScoreStats();

            for (int i = 0; i < Rows; i++)
            {
                var image = images[i];

                var   action = tracker == null ? null : tracker.GetTrackInOut(image, InLabel);
                float error  = GetScore(image, kernel, action: action);

                if (image.Label == InLabel)
                {
                    stats.InCount++;

                    if (error < kernel.ClassificationCutoff)
                    {
                        stats.InHit++;
                    }
                }
                else
                {
                    stats.OutCount++;

                    if (error < kernel.ClassificationCutoff)
                    {
                        stats.OutHit++;
                    }
                }
            }

            Console.WriteLine($"  - in label {stats.InHit} / {stats.InCount}  - out label {stats.OutHit} / {stats.OutCount}  - {kernel.ShortDescription()}");

            return(stats);
        }
Example #2
0
        static ScoreStats TestThreshold(int Rows, Kernel kernel, float[] source_score, byte[] source_label, float threshold, int InLabel)
        {
            var stats = new ScoreStats();

            for (int i = 0; i < Rows; i++)
            {
                var label = source_label[i];
                var error = source_score[i];

                if (label == InLabel)
                {
                    stats.InCount++;

                    if (error < threshold)
                    {
                        stats.InHit++;
                    }
                }
                else
                {
                    stats.OutCount++;

                    if (error < threshold)
                    {
                        stats.OutHit++;
                    }
                }
            }

            //Console.WriteLine($"  - in label {stats.InHit} / {stats.InCount}  - out label {stats.OutHit} / {stats.OutCount}  - error threshold {threshold:0.0000}  - {kernel.ShortDescription()}");

            return(stats);
        }
Example #3
0
        public ScoreStats[] StatsForClasses()
        {
            var stats = new ScoreStats[NumLabels];

            for (int label = 0; label < NumLabels; label++)
            {
                stats[label] = StatsForClass(label);
            }

            return(stats);
        }
Example #4
0
        static ScoreStats OptimizeKernelCutoff(int Rows, BlockedImage[] blocks, Kernel kernel, int InLabel,
                                               float InLabelMinRatio = 0.05f)
        {
            float[] source_score = GetScores(Rows, blocks, kernel);
            var     labels       = get_labels(blocks);

            ScoreStats best = null;

            for (int i = 0; i < 1000; i++)
            {
                float threshold = .001f + .5f * (float)rnd.NextDouble();
                var   result    = TestThreshold(Rows, kernel, source_score, labels, threshold, InLabel);

                if (best == null || result.InHitRatio > InLabelMinRatio && result.InOutHitRatio > best.InOutHitRatio)
                {
                    best = result;
                    kernel.ClassificationCutoff = threshold;
                }
            }

            return(best);
        }
Example #5
0
        public ScoreStats StatsForClass(int label)
        {
            var stats = new ScoreStats();

            for (int l = 0; l <= NumLabels; l++)
            {
                stats.InCount += Hits(PredictedLabel: l, ActualLabel: label);
            }
            stats.OutCount = Total - stats.InCount;

            for (int l = 0; l <= NumLabels; l++)
            {
                if (l == label)
                {
                    stats.InHit += Hits(PredictedLabel: label, ActualLabel: l);
                }
                else
                {
                    stats.OutHit += Hits(PredictedLabel: label, ActualLabel: l);
                }
            }

            return(stats);
        }