static void Main(string[] args)
        {
            Random seed = new Random();

            CrossValidate(seed);
            return;

            Console.WriteLine("Start time: " + DateTime.Now.ToString());

            DatasetParser datasetParser = new DatasetParser();

            Example[] examples = datasetParser.parseDatasetFile(EXAMPLES_FILENAME);
            Shuffle(examples, seed);

            CharacterRecognition cr = new CharacterRecognition(NUM_NETWORKS,
                                                               NETWORK_NUM_INPUTS, NETWORK_NUM_OUTPUTS,
                                                               NETWORK_NUM_HIDDEN_LAYERS, NETWORK_NUM_NEURONS_PER_HIDDEN_LAYER, seed);

            cr.Initialize(examples);

            /*while (true)
             * {
             *  double[] input = null;
             *  double[] output = cr.RecognizeCharacter(input);
             *
             * foreach(double d in output){Console.Write(d+", ");}Console.WriteLine();
             * }*/

            /*Console.WriteLine("Guessing: ");
             * cr.RecognizeCharacter(new double[] {
             *  0, 1, 0, 0,
             *  0, 1, 0, 0,
             *  0, 1, 1, 0,
             *  0, 0, 1, 0
             * });
             *
             * cr.RecognizeCharacter(new double[] {
             *  0, 1, 1, 0,
             *  1, 1, 0, 1,
             *  0, 0, 1, 1,
             *  0, 0, 1, 0
             * });*/

            Console.WriteLine("Guessing: ");
            cr.RecognizeCharacter(new double[] {
                0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
                0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
                0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
                0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
                1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
                0, 1, 1, 1, 0, 0, 0, 0, 0, 1,
                0, 0, 1, 1, 1, 0, 0, 0, 1, 1,
                0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
                0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
            });
        }
Exemple #2
0
        public void GenerateFromFiles(Random seed, string[] filenames)
        {
            //DatasetParser datasetParser = new DatasetParser();
            //Example[] examples = datasetParser.parseDatasetFile(EXAMPLES_FILENAME);
            //Shuffle(examples, seed);

            this.characterRecognizer = new CharacterRecognition(NUM_NETWORKS,
                                                                NETWORK_NUM_INPUTS, NETWORK_NUM_OUTPUTS,
                                                                NETWORK_NUM_HIDDEN_LAYERS, NETWORK_NUM_NEURONS_PER_HIDDEN_LAYER, seed);
            this.characterRecognizer.InitializeFromFiles(filenames);
        }
        public CrossValidation(Example[] _dataset, int _numTests, ref CharacterRecognition _cr, Random seed)
        {
            this.seed              = seed;
            this.numTests          = _numTests;
            this.datasetPartitions = new List <Example> [this.numTests];
            for (int n = 0; n < this.numTests; n++)
            {
                this.datasetPartitions[n] = new List <Example>();
            }
            for (int i = 0; i < _dataset.Length; i++)
            {
                this.datasetPartitions[i % this.numTests].Add(_dataset[i]);
            }

            this.cr = _cr;
        }
        public CrossValidation(Example[] _dataset, int _numTests, ref CharacterRecognition _cr, Random seed)
        {
            this.seed = seed;
            this.numTests = _numTests;
            this.datasetPartitions = new List<Example>[this.numTests];
            for (int n = 0; n < this.numTests; n++)
            {
                this.datasetPartitions[n] = new List<Example>();
            }
            for (int i = 0; i < _dataset.Length; i++)
            {
                this.datasetPartitions[i % this.numTests].Add(_dataset[i]);
            }

            this.cr = _cr;
        }
Exemple #5
0
        public double CrossValidate(Random seed)
        {
            //Console.WriteLine("Start time: " + DateTime.Now.ToString());
            DatasetParser datasetParser = new DatasetParser();

            Example[] examples = datasetParser.parseDatasetFile(this.EXAMPLES_FILENAME);

            CharacterRecognition cr = new CharacterRecognition(this.NUM_NETWORKS,
                                                               NETWORK_NUM_INPUTS, NETWORK_NUM_OUTPUTS,
                                                               NETWORK_NUM_HIDDEN_LAYERS, NETWORK_NUM_NEURONS_PER_HIDDEN_LAYER
                                                               , seed);

            CrossValidation cv        = new CrossValidation(examples, 5, ref cr, seed);
            double          precision = cv.CalculatePrecision(ref examples);

            //Console.WriteLine(1.0 - precision);
            //Console.WriteLine("End time: " + DateTime.Now.ToString());
            return(1.0 - precision);
        }
        public static void CrossValidate(Random seed)
        {
            DatasetParser datasetParser;

            Example[]            examples;
            CharacterRecognition cr;
            CrossValidation      cv;


            NetworkEvolution.GENERATIONS_NUMBER = 20000;
            NetworkEvolution.STAGNANT_NUMBER    = 50;
            Console.WriteLine("-------stag50||its20000_mut0,003_pop20_30_L1_70-------------------------");
            Console.WriteLine("Start time: " + DateTime.Now.ToString());
            datasetParser = new DatasetParser();
            examples      = datasetParser.parseDatasetFile(EXAMPLES_FILENAME);
            cr            = new CharacterRecognition(NUM_NETWORKS,
                                                     NETWORK_NUM_INPUTS, NETWORK_NUM_OUTPUTS,
                                                     1, new int[] { 70 }, seed);
            cv = new CrossValidation(examples, 5, ref cr, seed);
            Console.WriteLine(cv.CalculatePrecision(ref examples));
            Console.WriteLine("End time: " + DateTime.Now.ToString());
        }