public ProblemInstance Produce(TrademarkRepository rep)
        {
            var random = new Random();
            var res    = new ProblemInstance {
                TrademarkRepository = rep
            };

            int n = random.Next(2, rep.AllTrademarks.Count);

            var trademarkIndices = Enumerable.Range(0, rep.AllTrademarks.Count).ToArray();

            Shuffle(trademarkIndices);

            for (int i = 0; i < n; i++)
            {
                if (res.TrainingSetRatio <= trainingSetRatio)
                {
                    res.TrainingSet.Add(rep.AllTrademarks[trademarkIndices[i]]);
                }
                else
                {
                    res.ControlSet.Add(rep.AllTrademarks[trademarkIndices[i]]);
                }
            }

            return(res);
        }
Beispiel #2
0
        public ProblemInstance Produce(TrademarkRepository rep)
        {
            var res = new ProblemInstance {
                TrademarkRepository = rep
            };

            foreach (var trademark in rep.AllTrademarks)
            {
                if (Path.GetFileNameWithoutExtension(trademark.FilePath).Contains("T"))
                {
                    res.TrainingSet.Add(trademark);
                }
                else
                {
                    res.ControlSet.Add(trademark);
                }
            }
            return(res);
        }
Beispiel #3
0
        static void Main()
        {
            var preprocessor = new AForgeImagePreprocessor();
            var rep          = new TrademarkRepository(InputDir, preprocessor);

            var classifier = new GansClassifier(rep.AllTrademarkClasses.Count);
            //var classifier = new ColorMomentANNClassifier(rep.AllTrademarkClasses.Count);
            //var classifier = new ColorMomentMetricClassifier();

            var estimator = new CrossValidationEstimator(40, TrainingSetRatio, rep);

            //var estimator = new NaiveEstimator(problem);

            Console.WriteLine("Classes: {0} ({1:P02} each); Training set: {2:F0}; Control set: {3:F0}", rep.AllTrademarkClasses.Count, 1.0 / rep.AllTrademarkClasses.Count, rep.AllTrademarks.Count * TrainingSetRatio, rep.AllTrademarks.Count * (1 - TrainingSetRatio));

            var estimate = estimator.Estimate(classifier);

            Console.WriteLine(@"{0}: {1:P02}", classifier.GetType().Name, estimate);
        }
 public CrossValidationEstimator(int sampleCount, double trainingSetRatio, TrademarkRepository trademarkRepository)
 {
     this.sampleCount         = sampleCount;
     this.trademarkRepository = trademarkRepository;
     problemSource            = new RandomProblemSource(trainingSetRatio);
 }