Java Code Examples for org.neuroph.core.data.DataSetRow#getInput()

The following examples show how to use org.neuroph.core.data.DataSetRow#getInput() . 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: DataSetStatistics.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @return arithmetic mean for each input in data set
 */
@Deprecated
public double[] inputsMean() {
    double[] mean = new double[dataSet.getInputSize()];

    for (DataSetRow row : dataSet.getRows()) {
        double[] currentInput = row.getInput();
        for (int i = 0; i < dataSet.getInputSize(); i++) {
            mean[i] += currentInput[i];
        }
    }
    for (int i = 0; i < dataSet.getInputSize(); i++) {
        mean[i] /= (double) dataSet.getRows().size();
    }
    return mean;
}
 
Example 3
Source File: DataSetStatistics.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param dataSet Neuroph dataset
 * @return maximum value for each input in data set
 */
@Deprecated
public double[] inputsMax() {

    int inputSize = dataSet.getInputSize();
    double[] maxColumnElements = new double[inputSize];

    for (int i = 0; i < inputSize; i++) {
        maxColumnElements[i] = -Double.MAX_VALUE;
    }

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < inputSize; i++) {
            maxColumnElements[i] = Math.max(maxColumnElements[i], input[i]);
        }
    }

    return maxColumnElements;
}
 
Example 4
Source File: DataSetStatistics.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param dataSet Neuroph dataset
 * @return minimum value for each variable in data set
 */
@Deprecated
public double[] inputsMin() {

    int inputSize = dataSet.getInputSize();
    double[] minColumnElements = new double[inputSize];

    for (int i = 0; i < inputSize; i++) {
        minColumnElements[i] = Double.MAX_VALUE;
    }

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < inputSize; i++) {
            minColumnElements[i] = Math.min(minColumnElements[i], input[i]);
        }
    }
    return minColumnElements;
}
 
Example 5
Source File: DataSetStatistics.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
@Deprecated
public double[] inputsStandardDeviation(double[] mean2) {
    double[] sum = new double[mean2.length];

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < input.length; i++) {
            sum[i] = (input[i] - mean2[i]) * (input[i] - mean2[i]);
        }
    }

    double[] std = new double[mean2.length];
    for (int i = 0; i < mean2.length; i++) {
        std[i] = Math.sqrt(sum[i] / (dataSet.size() - 1));    // calculate as sample deviation not population
    }

    return std;
}
 
Example 6
Source File: KMeansClustering.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public KMeansClustering(DataSet dataSet) {
    this.dataSet = dataSet;
    this.dataVectors = new KVector[dataSet.size()];
    // iterate dataset and create dataVectors field
    this.dataVectors = new KVector[dataSet.size()];
     // iterate dataset and create dataVectors field
    int i=0;
    for(DataSetRow row : dataSet.getRows()) {
        KVector vector = new KVector(row.getInput());
        this.dataVectors[i]=vector;
        i++;
        
    }        
}
 
Example 7
Source File: KMeansClustering.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public KMeansClustering(DataSet dataSet, int numberOfClusters) {
    this.dataSet = dataSet;
    this.numberOfClusters = numberOfClusters;
    this.dataVectors = new KVector[dataSet.size()];
     // iterate dataset and create dataVectors field
    int i=0;
    for(DataSetRow row : dataSet.getRows()) {
        KVector vector = new KVector(row.getInput());
        this.dataVectors[i]=vector;
        i++;
        
    }
}
 
Example 8
Source File: HopfieldLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates weights for the hopfield net to learn the specified training
 * set
 * 
 * @param trainingSet
 *            training set to learn
 */
public void learn(DataSet trainingSet) {
	int M = trainingSet.size();
	int N = neuralNetwork.getLayerAt(0).getNeuronsCount();
	Layer hopfieldLayer = neuralNetwork.getLayerAt(0);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (j == i)
				continue;
			Neuron ni = hopfieldLayer.getNeuronAt(i);
			Neuron nj = hopfieldLayer.getNeuronAt(j);
			Connection cij = nj.getConnectionFrom(ni);
			Connection cji = ni.getConnectionFrom(nj);
			double w = 0;
			for (int k = 0; k < M; k++) {
				DataSetRow trainingSetRow = trainingSet.getRowAt(k);
				double pki = trainingSetRow.getInput()[i];
				double pkj = trainingSetRow.getInput()[j];
				w = w + pki * pkj;
			} // k
			cij.getWeight().setValue(w);
			cji.getWeight().setValue(w);
		} // j
	} // i

}
 
Example 9
Source File: ZeroMeanNormalizer.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void normalize(DataSet dataSet) {

    for (DataSetRow row : dataSet.getRows()) {
        double[] normalizedInput = row.getInput();

        for (int i = 0; i < dataSet.getInputSize(); i++) {
            normalizedInput[i] = (normalizedInput[i] - meanInput[i]) / stdInput[i];
        }
        row.setInput(normalizedInput);
    }
}
 
Example 10
Source File: DecimalScaleNormalizer.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Finds max values for all columns in dataset (inputs and outputs)
 * Sets max column values to maxIn and maxOut fields
 * @param dataSet
 */
private void findMaxVectors(DataSet dataSet) {
    int inputSize = dataSet.getInputSize();
    int outputSize = dataSet.getOutputSize();

    // init with minimum values
    maxIn = new double[inputSize];
    for (int i = 0; i < inputSize; i++) {
        maxIn[i] = Double.MIN_VALUE;
    }

    maxOut = new double[outputSize];
    for (int i = 0; i < outputSize; i++) {
        maxOut[i] = Double.MIN_VALUE;
    }


    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < inputSize; i++) {
            if (input[i] > maxIn[i]) {
                maxIn[i] = input[i];
            }
        }

        double[] output = dataSetRow.getDesiredOutput();
        for (int i = 0; i < outputSize; i++) {
            if (output[i] > maxOut[i]) {
                maxOut[i] = output[i];
            }
        }

    }
}
 
Example 11
Source File: MaxNormalizer.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
* Finds max values for columns in input and output vector for given data set
* @param dataSet
*/
private void init(DataSet dataSet) {
    int inputSize = dataSet.getInputSize();
    int outputSize = dataSet.getOutputSize();

    maxIn = new double[inputSize];
    for(int i=0; i<inputSize; i++) {
        maxIn[i] = Double.MIN_VALUE;
    }

    maxOut = new double[outputSize];
    for(int i=0; i<outputSize; i++)
        maxOut[i] = Double.MIN_VALUE;

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < inputSize; i++) {
            if (Math.abs(input[i]) > maxIn[i]) {
                maxIn[i] = Math.abs(input[i]);
            }
         }

        double[] output = dataSetRow.getDesiredOutput();
        for (int i = 0; i < outputSize; i++) {
            if (Math.abs(output[i]) > maxOut[i]) {
                maxOut[i] = Math.abs(output[i]);
            }
        }
    }
}
 
Example 12
Source File: UnsupervisedLearning.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Trains network with the pattern from the specified training element
 * 
 * @param DataSetItem
 *            unsupervised training element which contains network input
 */
protected void learnPattern(DataSetRow trainingElement) {
	double[] input = trainingElement.getInput();
	this.neuralNetwork.setInput(input);
	this.neuralNetwork.calculate();
	this.updateNetworkWeights();
}
 
Example 13
Source File: DigitsRecognition.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns training data as instance of DataSet
 * @return  training data as DataSet instance
 */
public static DataSet generateTrainingSet() {

    DataSet dataSet = new DataSet(DigitData.CHAR_WIDTH * DigitData.CHAR_HEIGHT, DigitData.DIGITS.length);

    for (int i = 0; i < DigitData.DIGITS.length; i++) {
        // setup input
        DataSetRow inputRow = DigitData.convertImageIntoData(DigitData.DIGITS[i]);
        double[] input = inputRow.getInput();

        // setup output
        double[] output = new double[DigitData.DIGITS.length];

        for (int j = 0; j < DigitData.DIGITS.length; j++) {
            if (j == i) {
                output[j] = 1;
            } else {
                output[j] = 0;
            }
        }
        //creating new training element with specified input and output
        DataSetRow row = new DataSetRow(input, output);
        //adding row to data set
        dataSet.add(row);
    }
    return dataSet;
}
 
Example 14
Source File: RangeNormalizer.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
/**
 * Find min and max values for each position in vectors.
 *
 * @param dataSet
 */
private void findMaxAndMinVectors(DataSet dataSet) {
    int inputSize = dataSet.getInputSize();
    int outputSize = dataSet.getOutputSize();

    maxIn = new double[inputSize];
    minIn = new double[inputSize];

    for(int i=0; i<inputSize; i++) {
        maxIn[i] = Double.MIN_VALUE;
        minIn[i] = Double.MAX_VALUE;
    }

    maxOut = new double[outputSize];
    minOut = new double[outputSize];

    for(int i=0; i<outputSize; i++) {
        maxOut[i] = Double.MIN_VALUE;
        minOut[i] = Double.MAX_VALUE;
    }

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < inputSize; i++) {
            if (input[i] > maxIn[i]) {
                maxIn[i] = input[i];
            }
            if (input[i] < minIn[i]) {
                minIn[i] = input[i];
            }
        }

        double[] output = dataSetRow.getDesiredOutput();
        for (int i = 0; i < outputSize; i++) {
            if (output[i] > maxOut[i]) {
                maxOut[i] = output[i];
            }
            if (output[i] < minOut[i]) {
                minOut[i] = output[i];
            }
        }

    }
}
 
Example 15
Source File: MaxMinNormalizer.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
/**
* Initialize normalizer: finds min and max values for all the columns in the data set.
* 
* @param dataSet 
*/
private void init(DataSet dataSet) {
    int numInputs = dataSet.getInputSize();
    int numOutputs = dataSet.getOutputSize();

    maxIn = new double[numInputs];
    minIn = new double[numInputs];

    for (int i = 0; i < numInputs; i++) {
        maxIn[i] = Double.MIN_VALUE;
        minIn[i] = Double.MAX_VALUE;
    }

    maxOut = new double[numOutputs];
    minOut = new double[numOutputs];

    for (int i = 0; i < numOutputs; i++) {
        maxOut[i] = Double.MIN_VALUE;
        minOut[i] = Double.MAX_VALUE;
    }

    for (DataSetRow dataSetRow : dataSet.getRows()) {
        double[] input = dataSetRow.getInput();
        for (int i = 0; i < numInputs; i++) {
            if (Math.abs(input[i]) > maxIn[i]) {
                maxIn[i] = Math.abs(input[i]);
            }
            if (Math.abs(input[i]) < minIn[i]) {
                minIn[i] = Math.abs(input[i]);
            }
        }

        double[] output = dataSetRow.getDesiredOutput();
        for (int i = 0; i < numOutputs; i++) {
            if (Math.abs(output[i]) > maxOut[i]) {
                maxOut[i] = Math.abs(output[i]);
            }
            if (Math.abs(output[i]) < minOut[i]) {
                minOut[i] = Math.abs(output[i]);
            }
        }
    }
}