Exemple #1
0
        public void make_new_network()
        {
            FileStream   fs = new FileStream("dataset.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            //double[][] myData = new double[][];
            string[] invector;
            string   invec;
            List <List <double> > our_dat = new List <List <double> >();
            List <double>         temp;

            while (sr.Peek() != -1)
            {
                temp     = new List <double>();
                invec    = sr.ReadLine();
                invector = invec.Split(',');
                for (int i = 0; i < invector.Length; i++)
                {
                    temp.Add(Convert.ToDouble(invector[i]));
                }
                our_dat.Add(temp);
            }
            AForge.Neuro.ActivationNetwork bus = new AForge.Neuro.ActivationNetwork(new AForge.Neuro.BipolarSigmoidFunction(2), our_dat.Count, 10);
            bus.Randomize();
            AForge.Neuro.Learning.BackPropagationLearning learn = new AForge.Neuro.Learning.BackPropagationLearning(bus);
            learn.LearningRate = 0.4;
        }
Exemple #2
0
        /// <summary>
        /// This method learn NN how to ocr basis on fileds placed in cals fields
        /// </summary>
        /// <returns>Amount of learning cycles</returns>
        public int init()
        {
            double[][] learningData = CreateLearningMatrix();
            double[][] outputs      = CreateExpectedResult(learningData);
            patterns = learningData.GetLength(0);

            AForge.Neuro.ActivationNetwork neuralNet =
                new AForge.Neuro.ActivationNetwork(new AForge.Neuro.BipolarSigmoidFunction(0.75), patternSize, patterns, patterns);
            // randomize network`s weights
            neuralNet.Randomize();

            // create network teacher
            AForge.Neuro.Learning.BackPropagationLearning teacher = new AForge.Neuro.Learning.BackPropagationLearning(neuralNet);
            teacher.Momentum     = 0.2f;
            teacher.LearningRate = 0.55f;

            // teach the network
            int    i    = 0;
            Random rand = new Random();
            double error;

            do
            {
                //error = teacher.RunEpoch(input, output);
                error = teacher.RunEpoch(learningData, outputs);
                Console.WriteLine(error);
                i++;
            }while (error > 0.05);
            Network = neuralNet;
            return(i);
        }
Exemple #3
0
        /// <summary>
        /// This method is Loading saved and teached NN
        /// </summary>
        public void LoadSerializedNetwork()
        {
            try
            {
                OpenFileDialog openDialog = new OpenFileDialog();
                openDialog.Filter = "BIN|*.bin";
                openDialog.Title  = "Save an bin File";
                openDialog.ShowDialog();

                // If the file name is not an empty string open it for saving.
                if (openDialog.FileName != "")
                {
                    AForge.Neuro.Network NetworkBuf = AForge.Neuro.ActivationNetwork.Load(openDialog.FileName);
                    Network = (AForge.Neuro.ActivationNetwork)NetworkBuf;
                }
            }
            catch (Exception oException)
            {
                Console.WriteLine("Aplikacja wygenerowała następujący wyjątek: " + oException.Message);
            }
        }