public virtual void run()
        {
            Console.WriteLine("Creating training and test set from file...");
            string trainingSetFileName = "data_sets/segment challenge.txt";
            string testSetFileName     = "data_sets/segment test.txt";
            int    inputsCount         = 19;
            int    outputsCount        = 7;

            //Create training data set from file
            DataSet trainingSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ",");

            Console.WriteLine("Training set size: " + trainingSet.Rows.Count);
            trainingSet.shuffle();
            trainingSet.shuffle();

            //Normalizing training data set
            Normalizer normalizer = new MaxNormalizer();

            normalizer.normalize(trainingSet);

            //Create test data set from file
            DataSet testSet = DataSet.createFromFile(testSetFileName, inputsCount, outputsCount, ",");

            Console.WriteLine("Test set size: " + testSet.Rows.Count);
            Console.WriteLine("--------------------------------------------------");
            testSet.shuffle();
            testSet.shuffle();

            //Normalizing training data set
            normalizer.normalize(testSet);

            Console.WriteLine("Creating neural network...");
            //Create MultiLayerPerceptron neural network
            MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 17, 10, outputsCount);
            //attach listener to learning rule
            MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule;

            learningRule.addListener(this);

            learningRule.LearningRate  = 0.01;
            learningRule.MaxError      = 0.001;
            learningRule.MaxIterations = 12000;

            Console.WriteLine("Training network...");
            //train the network with training set
            neuralNet.learn(trainingSet);

            Console.WriteLine("Testing network...\n\n");
            testNeuralNetwork(neuralNet, testSet);

            Console.WriteLine("Done.");
            Console.WriteLine("**************************************************");
            //        }
        }
Example #2
0
        public virtual void run()
        {
            Console.WriteLine("Creating training and test set from file...");
            string trainingSetFileName = "data_sets/diabetes.txt";
            int    inputsCount         = 8;
            int    outputsCount        = 2;

            //Create data set from file
            DataSet dataSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ",");

            dataSet.shuffle();

            //Normalizing data set
            Normalizer normalizer = new MaxNormalizer();

            normalizer.normalize(dataSet);

            //Creatinig training set (70%) and test set (30%)
            DataSet[] trainingAndTestSet = dataSet.createTrainingAndTestSubsets(70, 30);
            DataSet   trainingSet        = trainingAndTestSet[0];
            DataSet   testSet            = trainingAndTestSet[1];

            //        for (int i = 0; i < 21; i++) {
            Console.WriteLine("Creating neural network...");
            //Create MultiLayerPerceptron neural network
            MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 9, outputsCount);
            //            System.out.println("HIDDEN COUNT: " + i);
            //attach listener to learning rule
            MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule;

            learningRule.addListener(this);

            learningRule.LearningRate  = 0.05;
            learningRule.MaxError      = 0.01;
            learningRule.MaxIterations = 10000;

            Console.WriteLine("Training network...");
            //train the network with training set
            neuralNet.learn(trainingSet);

            Console.WriteLine("Testing network...\n\n");
            testNeuralNetwork(neuralNet, testSet);

            Console.WriteLine("Done.");
            Console.WriteLine("**************************************************");
            //        }
        }
        public virtual void run()
        {
            Console.WriteLine("Creating training set...");
            string trainingSetFileName = "data_sets/cpu_data.txt";
            int    inputsCount         = 7;
            int    outputsCount        = 1;

            // create training set from file
            DataSet    dataSet    = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ",", false);
            Normalizer normalizer = new MaxNormalizer();

            normalizer.normalize(dataSet);


            Console.WriteLine("Creating neural network...");
            // create MultiLayerPerceptron neural network
            MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 16, outputsCount);


            // attach listener to learning rule
            MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule;

            learningRule.addListener(this);

            // set learning rate and max error
            learningRule.LearningRate = 0.2;
            learningRule.MaxError     = 0.01;

            Console.WriteLine("Training network...");
            // train the network with training set
            neuralNet.learn(dataSet);

            Console.WriteLine("Training completed.");
            Console.WriteLine("Testing network...");

            testNeuralNetwork(neuralNet, dataSet);

            Console.WriteLine("Saving network");
            // save neural network to file
            neuralNet.save("MyNeuralNetCPU.nnet");

            Console.WriteLine("Done.");
        }
Example #4
0
        public virtual void train()
        {
            // get the path to file with data
            string inputFileName = "C:\\timeseries\\BSW15";

            // create MultiLayerPerceptron neural network
            neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, 5, 10, 1);
            MomentumBackpropagation learningRule = (MomentumBackpropagation)neuralNet.LearningRule;

            learningRule.LearningRate = 0.2;
            learningRule.Momentum     = 0.5;
            // learningRule.addObserver(this);
            learningRule.addListener(this);

            // create training set from file
            trainingSet = DataSet.createFromFile(inputFileName, 5, 1, "\t", false);
            // train the network with training set
            neuralNet.learn(trainingSet);

            System.Console.WriteLine("Done training.");
        }