org.neuroph.core.events.LearningEvent Java Examples

The following examples show how to use org.neuroph.core.events.LearningEvent. 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: KohonenLearning.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
@Override
public void learn(DataSet trainingSet) {
               
	for (int phase = 0; phase < 2; phase++) {
		for (int k = 0; k < iterations[phase]; k++) {
			Iterator<DataSetRow> iterator = trainingSet.iterator();
			while (iterator.hasNext() && !isStopped()) {
				DataSetRow trainingSetRow = iterator.next();
				learnPattern(trainingSetRow, nR[phase]);				
			} // while
			currentIteration = k;
                               fireLearningEvent(new LearningEvent(this, LearningEvent.Type.EPOCH_ENDED));
			if (isStopped()) return;
		} // for k
		learningRate = learningRate * 0.5;
	} // for phase
}
 
Example #2
Source File: BreastCancerSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #3
Source File: IonosphereSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #4
Source File: IonosphereSample2.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #5
Source File: MNISTExample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
        public void handleLearningEvent(LearningEvent event) {
            BackPropagation bp = (BackPropagation) event.getSource();
            LOG.info("Current iteration: " + bp.getCurrentIteration());
            LOG.info("Error: " + bp.getTotalNetworkError());
            LOG.info("Calculation time: " + (System.currentTimeMillis() - start) / 1000.0);
         //   neuralNetwork.save(bp.getCurrentIteration() + "CNN_MNIST" + bp.getCurrentIteration() + ".nnet");
            start = System.currentTimeMillis();
//            NeuralNetworkEvaluationService.completeEvaluation(neuralNetwork, testSet);
        }
 
Example #6
Source File: DiabetesSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #7
Source File: CnnMNIST.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    LOG.info("Epoch no#: [{}]. Error [{}]", bp.getCurrentIteration(), bp.getTotalNetworkError());
    LOG.info("Epoch execution time: {} sec", (System.currentTimeMillis() - start) / 1000.0);
   // neuralNetwork.save(bp.getCurrentIteration() + "_MNIST_CNN-MIC.nnet");

    start = System.currentTimeMillis();
  //  if (bp.getCurrentIteration() % 5 == 0)
  //      Evaluation.runFullEvaluation(neuralNetwork, testSet);
}
 
Example #8
Source File: GermanCreditDataSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #9
Source File: BrestCancerSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
    }
}
 
Example #10
Source File: TrainNetwork.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
        double error = bp.getTotalNetworkError();
        System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
        System.out.println("With total error: " + formatDecimalNumber(error));
    } else {
        System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());

    }
}
 
Example #11
Source File: Cifar10Example.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    LOG.info("Epoch no#: [{}]. Error [{}]", bp.getCurrentIteration(), bp.getTotalNetworkError());
    LOG.info("Epoch execution time: {} sec", (System.currentTimeMillis() - start) / 1000.0);
   // neuralNetwork.save(bp.getCurrentIteration() + "_MNIST_CNN-MIC.nnet");

    start = System.currentTimeMillis();
  //  if (bp.getCurrentIteration() % 5 == 0)
  //      Evaluation.runFullEvaluation(neuralNetwork, testSet);
}
 
Example #12
Source File: DigitsRecognition.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public static void main(String args[]) {

        //create training set from Data.DIGITS
        DataSet dataSet = generateTrainingSet();

        int inputCount = DigitData.CHAR_HEIGHT * DigitData.CHAR_WIDTH;
        int outputCount = DigitData.DIGITS.length;
        int hiddenNeurons = 19;

        //create neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputCount, hiddenNeurons, outputCount);
        //get backpropagation learning rule from network
        BackPropagation learningRule = neuralNet.getLearningRule();

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

        //add learning listener in order to print out training info
        learningRule.addListener(new LearningEventListener() {
            @Override
            public void handleLearningEvent(LearningEvent event) {
                BackPropagation bp = (BackPropagation) event.getSource();
                if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
                    System.out.println();
                    System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations");
                    System.out.println("With total error " + bp.getTotalNetworkError() + '\n');
                } else {
                    System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
                }
            }
        });

        //train neural network
        neuralNet.learn(dataSet);

        //train the network with training set
        testNeuralNetwork(neuralNet, dataSet);

    }
 
Example #13
Source File: IterativeLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Runs one learning iteration with the specified training set and fires
 * event to notify observers. This method does the the doLearningEpoch() and in addtion
 * notifes observrs when iteration is done.
 *
 * @param trainingSet training set to learn
 */
public void doOneLearningIteration(DataSet trainingSet) {
    beforeEpoch();
    doLearningEpoch(trainingSet);
    afterEpoch();
    // notify listeners        
    fireLearningEvent(new LearningEvent(this, LearningEvent.Type.LEARNING_STOPPED)); 
}
 
Example #14
Source File: IterativeLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public final void learn(DataSet trainingSet) {
    setTrainingSet(trainingSet); // set this field here su subclasses can access it 
    onStart();

    while (!isStopped()) {
        beforeEpoch();
        doLearningEpoch(trainingSet);
        this.currentIteration++;
        afterEpoch();

        // now check if stop condition is satisfied
        if (hasReachedStopCondition()) {
            stopLearning();
        } else if (!iterationsLimited && (currentIteration == Integer.MAX_VALUE)) {
            // if counter has reached max value and iteration number is not limited restart iteration counter
            this.currentIteration = 1;
        }

        // notify listeners that epoch has ended
        fireLearningEvent(new LearningEvent(this, LearningEvent.Type.EPOCH_ENDED));

        // Thread safe pause when learning is paused
        if (this.pausedLearning) {
            synchronized (this) {
                while (this.pausedLearning) {
                    try {
                        this.wait();
                    } catch (Exception e) {
                    }
                }
            }
        }

    }
    onStop();
    fireLearningEvent(new LearningEvent(this, LearningEvent.Type.LEARNING_STOPPED));
}
 
Example #15
Source File: RBFClassificationSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    LMS lr = (LMS) event.getSource();
    System.out.println(lr.getCurrentIteration() + ". iteration | Total network error: " + lr.getTotalNetworkError());
}
 
Example #16
Source File: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #17
Source File: SegmentChallengeSample.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/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(dataSetFile, inputsCount, outputsCount, ",");
        System.out.println("Training set size: " + trainingSet.getRows().size());
        trainingSet.shuffle();

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

        //Create test data set from file
        DataSet testSet = DataSet.createFromFile(testSetFileName, inputsCount, outputsCount, ",");
        System.out.println("Test set size: " + testSet.getRows().size());
        System.out.println("--------------------------------------------------");
        testSet.shuffle();

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

        System.out.println("Creating neural network...");
        //Create MultiLayerPerceptron neural network
        MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(inputsCount, 17, 10, outputsCount);
        //attach listener to learning rule
        MomentumBackpropagation learningRule = (MomentumBackpropagation) neuralNet.getLearningRule();
        learningRule.addListener((event) -> {
            BackPropagation bp = (BackPropagation) event.getSource();
            if (event.getEventType().equals(LearningEvent.Type.LEARNING_STOPPED)) {
                double error = bp.getTotalNetworkError();
                System.out.println("Training completed in " + bp.getCurrentIteration() + " iterations, ");
                System.out.println("With total error: " + formatDecimalNumber(error));
            } else {
                System.out.println("Iteration: " + bp.getCurrentIteration() + " | Network error: " + bp.getTotalNetworkError());
            }
        });

        learningRule.setLearningRate(0.01);
        learningRule.setMaxError(0.001);
        learningRule.setMaxIterations(12000);

        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 #18
Source File: IrisFlowers.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #19
Source File: Banknote.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #20
Source File: LensesClassificationSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #21
Source File: CarEvaluationSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #22
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    LMS bp = (LMS) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #23
Source File: PredictingPokerHandsSample.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #24
Source File: Abalone.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #25
Source File: Sonar.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #26
Source File: WineQualityClassification.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #27
Source File: WheatSeeds.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #28
Source File: Ionosphere.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #29
Source File: PimaIndiansDiabetes.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    MomentumBackpropagation bp = (MomentumBackpropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
}
 
Example #30
Source File: BatchImageTrainer.java    From FakeImageDetection with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleLearningEvent(LearningEvent event) {
    BackPropagation bp = (BackPropagation) event.getSource();
    System.out.println(bp.getCurrentIteration() + ". iteration | Total network error: " + bp.getTotalNetworkError());
    listener.batchImageTrainingUpdate(bp.getCurrentIteration(), bp.getTotalNetworkError());
}