org.neuroph.core.events.LearningEventListener Java Examples

The following examples show how to use org.neuroph.core.events.LearningEventListener. 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: LearningRule.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public synchronized void addListener(LearningEventListener listener) {
    if (listener == null)
        throw new IllegalArgumentException("listener is null!");
    
    if (!listeners.contains(listener)) {
        listeners.add(listener);
    }
}
 
Example #2
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 #3
Source File: LearningRule.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public synchronized void removeListener(LearningEventListener listener) {
    if (listener == null)
        throw new IllegalArgumentException("listener is null!");        
    
    listeners.remove(listener);
}
 
Example #4
Source File: LearningRule.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
protected synchronized void fireLearningEvent(LearningEvent evt) {
    for (LearningEventListener listener : listeners) {
      listener.handleLearningEvent(evt);
    }
}