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

The following examples show how to use org.neuroph.core.data.DataSet#iterator() . 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: SimulatedAnnealingLearning.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Used internally to calculate the error for a training set.
 *
 * @param trainingSet The training set to calculate for.
 * @return The error value.
 */
private double determineError(DataSet trainingSet) {
    double result = 0d;

    Iterator<DataSetRow> iterator = trainingSet.iterator();
    while (iterator.hasNext() && !isStopped()) {
        DataSetRow trainingSetRow = iterator.next();
        double[] input = trainingSetRow.getInput();
        getNetwork().setInput(input);
        getNetwork().calculate();
        double[] output = getNetwork().getOutput();
        double[] desiredOutput = trainingSetRow
                .getDesiredOutput();

        double[] patternError = getErrorFunction().addPatternError(desiredOutput, output);
        double sqrErrorSum = 0;
        for (double error : patternError) {
            sqrErrorSum += (error * error);
        }
        result += sqrErrorSum / (2 * patternError.length);

    }

    return result;
}
 
Example 2
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 3
Source File: WekaNeurophSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Prints Neuroph data set
 *
 * @param neurophDataset Dataset Neuroph data set
 */
public static void printDataSet(DataSet neurophDataset) {
    System.out.println("Neuroph dataset");
    Iterator iterator = neurophDataset.iterator();

    while (iterator.hasNext()) {
        DataSetRow row = (DataSetRow) iterator.next();
        System.out.println("inputs");
        System.out.println(Arrays.toString(row.getInput()));
        if (row.getDesiredOutput().length > 0) {
            System.out.println("outputs");
            System.out.println(Arrays.toString(row.getDesiredOutput()));
           // System.out.println(row.getLabel());
        }
    }
}
 
Example 4
Source File: UnsupervisedLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * This method does one learning epoch for the unsupervised learning rules.
 * It iterates through the training set and trains network weights for each
 * element
 * 
 * @param trainingSet
 *            training set for training network
 */
        @Override
public void doLearningEpoch(DataSet trainingSet) {
	Iterator<DataSetRow> iterator = trainingSet.iterator();
	while (iterator.hasNext() && !isStopped()) {
		DataSetRow trainingSetRow = iterator.next();
		learnPattern(trainingSetRow);
	}
}
 
Example 5
Source File: JMLNeurophSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Prints Neuroph data set
 *
 * @param neurophDataset Dataset Neuroph data set
 */
public static void printDataset(DataSet neurophDataset) {
    System.out.println("Neuroph dataset");
    Iterator iterator = neurophDataset.iterator();

    while (iterator.hasNext()) {
        DataSetRow row = (DataSetRow) iterator.next();
        System.out.println("inputs");
        System.out.println(Arrays.toString(row.getInput()));
        if (row.getDesiredOutput().length > 0) {
            System.out.println("outputs");
            System.out.println(Arrays.toString(row.getDesiredOutput()));
        }
    }
}
 
Example 6
Source File: SupervisedLearning.java    From NeurophFramework with Apache License 2.0 3 votes vote down vote up
/**
 * This method implements basic logic for one learning epoch for the
 * supervised learning algorithms. Epoch is the one pass through the
 * training set. This method  iterates through the training set
 * and trains network for each element. It also sets flag if conditions
 * to stop learning has been reached: network error below some allowed
 * value, or maximum iteration count
 *
 * @param trainingSet training set for training network
 */
@Override
public void doLearningEpoch(DataSet trainingSet) {        
    Iterator<DataSetRow> iterator = trainingSet.iterator();
    while (iterator.hasNext() && !isStopped()) { // iterate all elements from training set - maybe remove isStopped from here
        DataSetRow dataSetRow = iterator.next();
        learnPattern(dataSetRow);             // learn current input/output pattern defined by SupervisedTrainingElement
    }
}