Java Code Examples for org.neuroph.nnet.MultiLayerPerceptron#save()

The following examples show how to use org.neuroph.nnet.MultiLayerPerceptron#save() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrainNetwork.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void train() {
    System.out.println("Training neural network... ");
    MultiLayerPerceptron neuralNet = (MultiLayerPerceptron) NeuralNetwork.createFromFile(config.getTrainedNetworkFileName());

    DataSet dataSet = DataSet.load(config.getNormalizedBalancedFileName());
    neuralNet.getLearningRule().addListener(this);
    neuralNet.learn(dataSet);
    System.out.println("Saving trained neural network to file... ");
    neuralNet.save(config.getTrainedNetworkFileName());
    System.out.println("Neural network successfully saved!");
}
 
Example 2
Source File: PredictingTheReligionSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        // get path to training set
        String dataSetFile = "data_sets/religion_data.txt";
        int inputsCount = 54;
        int outputsCount = 5;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", false);
       
        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 22, outputsCount);
       
        
        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetReligion.nnet");

        System.out.println("Done.");
    }
 
Example 3
Source File: WineClassificationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        // get path to training set
        String dataSetFile = "data_sets/wine_classification_data.txt";
        int inputsCount = 13;
        int outputsCount = 3;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", false);

        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 22, outputsCount);

        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetWineClassification.nnet");

        System.out.println("Done.");
    }
 
Example 4
Source File: GlassIdentificationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");

        String dataSetFile = "data_sets/glass_identification_data.txt";
        int inputsCount = 9;
        int outputsCount = 7;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", false);
        //dataSet.normalize();
        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 22, outputsCount);
       
        
        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.1);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralGlassIdentification.nnet");

        System.out.println("Done.");
    }
 
Example 5
Source File: AnimalsClassificationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        String dataSetFile = "data_sets/animals_data.txt";
        int inputsCount = 20;
        int outputsCount = 7;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", true);
        
        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 22, outputsCount);

        
        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetAnimals.nnet");

        System.out.println("Done.");
    }
 
Example 6
Source File: CarEvaluationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        String dataSetFile = "data_sets/car_evaluation_data.txt";
        int inputsCount = 21;
        int outputsCount = 4;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", false);
       
        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 22, outputsCount);
       
        
        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetCarEvaluation.nnet");

        System.out.println("Done.");
    }
 
Example 7
Source File: IrisClassificationSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 *  Runs this sample
 */
public static void main(String[] args) {    
    // get the path to file with data
    String inputFileName = "data_sets/iris_data_normalised.txt";
    
    // create MultiLayerPerceptron neural network
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(4, 16, 3);
    // create training set from file
    DataSet irisDataSet = DataSet.createFromFile(inputFileName, 4, 3, ",");

    // attach learningn listener to print out info about error at each iteration
    neuralNet.getLearningRule().addListener((event)->{
        BackPropagation bp = (BackPropagation) event.getSource();
        System.out.println("Current iteration: " + bp.getCurrentIteration());
        System.out.println("Error: " + bp.getTotalNetworkError());        
    });
    
    neuralNet.getLearningRule().setLearningRate(0.5);
    neuralNet.getLearningRule().setMaxError(0.01);
    neuralNet.getLearningRule().setMaxIterations(30000);

    // train the network with training set
    neuralNet.learn(irisDataSet);

    neuralNet.save("irisNet.nnet");
    
    System.out.println("Done training.");
    System.out.println("Testing network...");
}
 
Example 8
Source File: Banknote.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating data set...");
    String dataSetFile = "data_sets/ml10standard/databanknote.txt";
    int inputsCount = 4;
    int outputsCount = 1;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",", false);
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 1, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener((event) -> {
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxError(0.01);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");
}
 
Example 9
Source File: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating data set...");
    String dataSetFile = "data_sets/ml10standard/bostonhouse.txt";
    int inputsCount = 13;
    int outputsCount = 1;

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

    // split data into training and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // normalize data
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 2, 2, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(event -> {
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

}
 
Example 10
Source File: IrisFlowers.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating training set...");
    // get path to training set
    String trainingSetFileName = "data_sets/irisdatanormalised.txt";
    int inputsCount = 4;
    int outputsCount = 3;

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

    // splid data into training and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 2, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(this);

    // set learning rate and max error
    learningRule.setLearningRate(0.2);
    learningRule.setMaxError(0.03);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 11
Source File: Sonar.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    String dataSetFile = "data_sets/ml10standard/sonardata.txt";
    int numInputs = 60;
    int numOutputs = 1;

    // create data set from csv file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, numInputs, numOutputs, ",");

    // split data into train and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // create neural network
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, numInputs, 35, 15, numOutputs);

    // set learning rule and add listener
    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener((event) -> {
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    // set learning rate and max error
    learningRule.setLearningRate(0.01);
    learningRule.setMaxError(0.01);

    // train the network with training set
    neuralNet.learn(trainingSet);

    // evaluate network performance on test set
    evaluate(neuralNet, testSet);

    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    //testNeuralNetwork(neuralNet, testSet);
}
 
Example 12
Source File: WineQualityClassification.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating data set...");
    String dataSetFile = "data_sets/ml10standard/wine.txt";
    int inputsCount = 11;
    int outputsCount = 10;

    // create data set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", true);

    // split data into train and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 20, 15, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener((event)->{
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxIterations(5000);

    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 13
Source File: WheatSeeds.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating data set...");
    String dataSetFile = "data_sets/ml10standard/seeds.txt";
    int inputsCount = 7;
    int outputsCount = 3;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t");

    // split data into train and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 15, 2, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener((event)->{
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxError(0.01);
    learningRule.setMaxIterations(5000);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 14
Source File: Abalone.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating training set...");
    // get path to training set
    String trainingSetFileName = "data_sets/abalonerings.txt";
    int inputsCount = 8;
    int outputsCount = 29;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, "\t", true);

    // split data into train and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // normalize data
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 15, 10, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(this);

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxIterations(5000);

    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 15
Source File: IrisFlowers.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating data set...");
    String dataSetFile = "data_sets/ml10standard/irisdatanormalised.txt";
    int inputsCount = 4;
    int outputsCount = 3;

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

    // split data into training and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 2, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener((event)->{
        MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
        System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    });

    // set learning rate and max error
    learningRule.setLearningRate(0.2);
    learningRule.setMaxError(0.03);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");
}
 
Example 16
Source File: ConceptLearningAndClassificationSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        String dataSetFile = "data_sets/concept_learning_and_classification_data_1.txt";
        int inputsCount = 15;
        int outputsCount = 3;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",", false);
       //dataSet.normalize();

        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 10, outputsCount);


        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMomentum(0.7);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetConceptLearning.nnet");

        System.out.println("Done.");
    }
 
Example 17
Source File: Sonar.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating training set...");
    // get path to training set
    String trainingSetFileName = "data_sets/sonardata.txt";
    int inputsCount = 60;
    int outputsCount = 1;

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

    // split data into train and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // normalize data using max normalization
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 15, 10, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(this);

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxError(0.01);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 18
Source File: Ionosphere.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating training set...");
    // get path to training set
    String trainingSetFileName = "data_sets/ionospheredata.txt";
    int inputsCount = 34;
    int outputsCount = 1;

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

    // split data into training and test set
    DataSet[] trainTestSplit = dataSet.split(0.6, 0.4);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // normalize data
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 30, 25, outputsCount);

    neuralNet.setLearningRule(new MomentumBackpropagation());
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(this);

    // set learning rate and max error
    learningRule.setLearningRate(0.1);
    learningRule.setMaxError(0.01);
    System.out.println("Training network...");
    // train the network with training set
    neuralNet.learn(trainingSet);
    System.out.println("Training completed.");
    System.out.println("Testing network...");

    System.out.println("Network performance on the test set");
    evaluate(neuralNet, testSet);

    System.out.println("Saving network");
    // save neural network to file
    neuralNet.save("nn1.nnet");

    System.out.println("Done.");

    System.out.println();
    System.out.println("Network outputs for test set");
    testNeuralNetwork(neuralNet, testSet);
}
 
Example 19
Source File: ForestFiresSample.java    From NeurophFramework with Apache License 2.0 3 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");

        String dataSetFile = "data_sets/forest_fires_data.txt";
        int inputsCount = 29;
        int outputsCount = 1;

        // create training set from file
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",", false);
       
        
        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 25, outputsCount);
       
        
        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetForestFires.nnet");

        System.out.println("Done.");
    }
 
Example 20
Source File: LensesClassificationSample.java    From NeurophFramework with Apache License 2.0 3 votes vote down vote up
public void run() {

        System.out.println("Creating training set...");
        
        String dataSetFile = "data_sets/lenses_data.txt";
        int inputsCount = 9;
        int outputsCount = 3;

        System.out.println("Creating training set...");
        DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, " ", false);


        System.out.println("Creating neural network...");
        // create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 16, outputsCount);


        // attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener(this);

        // set learning rate and max error
        learningRule.setLearningRate(0.2);
        learningRule.setMaxError(0.01);

        System.out.println("Training network...");
        // train the network with training set
        neuralNet.learn(dataSet);

        System.out.println("Training completed.");
        System.out.println("Testing network...");

        testNeuralNetwork(neuralNet, dataSet);

        System.out.println("Saving network");
        // save neural network to file
        neuralNet.save("MyNeuralNetLenses.nnet");

        System.out.println("Done.");
    }