Java Code Examples for org.neuroph.core.data.DataSet#createFromFile()

The following examples show how to use org.neuroph.core.data.DataSet#createFromFile() . 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: MomentumBackPropagationTest.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    instance = new MomentumBackpropagation();
    instance.setMomentum(0.5);
    xorDataSet = new DataSet(2, 1);
    xorDataSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0}));
    xorDataSet.add(new DataSetRow(new double[]{0, 1}, new double[]{1}));
    xorDataSet.add(new DataSetRow(new double[]{1, 0}, new double[]{1}));
    xorDataSet.add(new DataSetRow(new double[]{1, 1}, new double[]{0}));
    maxError = 0.01;
    instance.setLearningRate(0.5);
    instance.setMaxError(maxError);
    String inputFileName = "src/test/resources/iris_normalized.txt";
    irisDataSet = DataSet.createFromFile(inputFileName, 4, 3, ",", false);

}
 
Example 2
Source File: GRUStockPricePredictionExample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
private static void trainNetwork() {
    DataSet trainingSet = DataSet.createFromFile("google-stock-price-train.csv", 3, 1, ",");
    DataSet testSet = DataSet.createFromFile("google-stock-price-test.csv", 3, 1, ",");

    SequenceModeller sequenceModeller = new SequenceModeller(trainingSet);

    int inputsCount = sequenceModeller.getCharIndex().size();
    int hiddenCount = 100;

    int maxIterations = 100;
    double learningRate = 0.8;

    System.out.println("Creating neural network...");
    RNN gru = new GRU(inputsCount, hiddenCount, new MatrixInitializer(MatrixInitializer.Type.Uniform, 0.1, 0, 0));
    BackPropagationThroughTime bptt = new GRUBackPropagationThroughTime();
    bptt.setLearningRate(learningRate);
    gru.setLearningRule(bptt);

    System.out.println("Training network...");
    bptt.learn(trainingSet, maxIterations);
    System.out.println("Training completed.");

    testNetwork(gru, testSet);
}
 
Example 3
Source File: ClassifierEvaluationSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Evaluation evaluation = new Evaluation();
    evaluation.addEvaluator(new ErrorEvaluator(new MeanSquaredError()));

    String[] classNames = {"Virginica", "Setosa", "Versicolor"};

    MultiLayerPerceptron neuralNet = (MultiLayerPerceptron) NeuralNetwork.createFromFile("irisNet.nnet");
    DataSet dataSet = DataSet.createFromFile("data_sets/iris_data_normalised.txt", 4, 3, ",");

    evaluation.addEvaluator(new ClassifierEvaluator.MultiClass(classNames));
    evaluation.evaluate(neuralNet, dataSet);

    ClassifierEvaluator evaluator = evaluation.getEvaluator(ClassifierEvaluator.MultiClass.class);
    ConfusionMatrix confusionMatrix = evaluator.getResult();
    System.out.println("Confusion matrrix:\r\n");
    System.out.println(confusionMatrix.toString() + "\r\n\r\n");
    System.out.println("Classification metrics\r\n");
    ClassificationMetrics[] metrics = ClassificationMetrics.createFromMatrix(confusionMatrix);
    ClassificationMetrics.Stats average = ClassificationMetrics.average(metrics);
    for (ClassificationMetrics cm : metrics) {
        System.out.println(cm.toString() + "\r\n");
    }
    System.out.println(average.toString());

}
 
Example 4
Source File: TestTimeSeries.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public 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.getLearningRule();
    learningRule.setLearningRate(0.2);
    learningRule.setMomentum(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.out.println("Done training.");          
}
 
Example 5
Source File: IrisFlowers.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void run() throws InterruptedException, ExecutionException {
    System.out.println("Creating training set...");
    // get path to training set
    String dataSetFile = "data_sets/iris_data_normalised.txt";
    int inputsCount = 4;
    int outputsCount = 3;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, ",");
 //   dataSet.setColumnNames(new String[]{"sepal.length", "sepal.width", "petal.length", "petal.width",  "setosa", "versicolor", "virginica"});
    dataSet.setColumnNames(new String[]{"setosa", "versicolor", "virginica"});
    dataSet.shuffle();

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

    String[] classLabels = new String[]{"setosa", "versicolor", "virginica"};
    neuralNet.setOutputLabels(classLabels);

    KFoldCrossValidation crossVal = new KFoldCrossValidation(neuralNet, dataSet, 5);
    EvaluationResult totalResult= crossVal.run();
    List<FoldResult> cflist= crossVal.getResultsByFolds();

}
 
Example 6
Source File: DiabetesSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void run() {
    String dataSetFile = "data_sets/diabetes.txt";
    int inputsCount = 8;
    int outputsCount = 1;

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

    // Creatinig training set (70%) and test set (30%)
    DataSet[] trainTestSplit = dataSet.split(0.7, 0.3);
    DataSet trainingSet = trainTestSplit[0];
    DataSet testSet = trainTestSplit[1];

    // Normalizing training and test set
    Normalizer normalizer = new MaxNormalizer(trainingSet);
    normalizer.normalize(trainingSet);
    normalizer.normalize(testSet);

    System.out.println("Creating neural network...");
    //Create MultiLayerPerceptron neural network
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 20, 10, outputsCount);
    //attach listener to learning rule
    MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
    learningRule.addListener(this);

    learningRule.setLearningRate(0.6);
    learningRule.setMaxError(0.07);
    learningRule.setMaxIterations(100000);

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

    System.out.println("Testing network...");
    testNeuralNetwork(neuralNet, testSet);

}
 
Example 7
Source File: RunExampleEvaluation.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    NeuralNetwork nnet = NeuralNetwork.createFromFile("irisNet.nnet");
    DataSet dataSet =  DataSet.createFromFile("data_sets/iris_data_normalised.txt", 4, 3, ",");
    
    Evaluation.runFullEvaluation(nnet, dataSet);
     
}
 
Example 8
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 9
Source File: BalanceScaleSample.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/balance_scale_data.txt";
        int inputsCount = 20;
        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("MyNeuralNetBalanceScale.nnet");

        System.out.println("Done.");
    }
 
Example 10
Source File: BackPropagationTest.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    instance = new BackPropagation();
    xorDataSet = new DataSet(2, 1);
    xorDataSet.add(new DataSetRow(new double[]{0, 0}, new double[]{0}));
    xorDataSet.add(new DataSetRow(new double[]{0, 1}, new double[]{1}));
    xorDataSet.add(new DataSetRow(new double[]{1, 0}, new double[]{1}));
    xorDataSet.add(new DataSetRow(new double[]{1, 1}, new double[]{0}));
    maxError = 0.01;
    instance.setLearningRate(0.5);
    instance.setMaxError(maxError);
    String inputFileName = "src/test/resources/iris_normalized.txt";
    irisDataSet = DataSet.createFromFile(inputFileName, 4, 3, ",", false);

}
 
Example 11
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 12
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 13
Source File: BrestCancerSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {

        System.out.println("Creating training and test set from file...");
        String dataSetFile = "data_sets/breast cancer.txt";
        int inputsCount = 30;
        int outputsCount = 2; // use onlz one output - binarz classification, transform dat aset

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

        //Creatinig training set (70%) and test set (30%)
        DataSet[] trainTestSplit = dataSet.split(0.7, 0.3);
        DataSet trainingSet = trainTestSplit[0];
        DataSet testSet = trainTestSplit[1];

        //Normalizing data set
        Normalizer normalizer = new MaxNormalizer(trainingSet);
        normalizer.normalize(trainingSet);
        normalizer.normalize(testSet);

        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);

        learningRule.setLearningRate(0.3);
        learningRule.setMaxError(0.001);
        learningRule.setMaxIterations(5000);

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

        System.out.println("Testing network...\n\n");
        testNeuralNetwork(neuralNet, testSet);

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

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

    }
 
Example 14
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {
    System.out.println("Creating training set...");
    String dataSetFileName = "data_sets/autodata.txt";
    int inputsCount = 1;
    int outputsCount = 1;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFileName, 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 training and test set
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    Adaline neuralNet = new Adaline(1);

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

    // train the network with training set
    System.out.println("Training network...");
    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: PimaIndiansDiabetes.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/pimadata.txt";
    int inputsCount = 8;
    int outputsCount = 1;

    // create data set from file
    DataSet dataSet = DataSet.createFromFile(dataSetFile, inputsCount, outputsCount, "\t", 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 training and test set
    Normalizer norm = new MaxNormalizer(trainingSet);
    norm.normalize(trainingSet);
    norm.normalize(testSet);

    System.out.println("Creating neural network...");
    MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(TransferFunctionType.TANH, inputsCount, 15, 5, 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.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: Banknote.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/databanknote.txt";
    int inputsCount = 4;
    int outputsCount = 1;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(trainingSetFileName, 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(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 17
Source File: BostonHousePrice.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/bostonhouse.txt";
    int inputsCount = 13;
    int outputsCount = 1;

    // create training set from file
    DataSet dataSet = DataSet.createFromFile(trainingSetFileName, inputsCount, outputsCount, ",");
    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(this);

    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: IonosphereSample2.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void run() {

        System.out.println("Creating training and test set from file...");
        String dataSetFile = "data_sets/ionosphere.csv";
        int inputsCount = 34;
        int outputsCount = 1;

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

        //Normalizing data set
        Normalizer normalizer = new MaxNormalizer(dataSet);
        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];

        // ovde ubaci u petlju sa hidden neuronima i learning rates

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

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

        learningRule.setLearningRate(0.4);
        learningRule.setMaxError(0.01);
        learningRule.setMaxIterations(10000);

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

//        System.out.println("Testing network...\n\n");
//        testNeuralNetwork(neuralNet, testSet);

        System.out.println("Done.");
        System.out.println("**************************************************");
//        }
    }
 
Example 19
Source File: ShuttleLandingControlSample.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/shuttle_landing_control_data.txt";
        int inputsCount = 15;
        int outputsCount = 2;

        // 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, 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("MyNeuralNetShuttle.nnet");

        System.out.println("Done.");
    }
 
Example 20
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.");
    }