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

The following examples show how to use org.neuroph.core.data.DataSetRow#getDesiredOutput() . 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: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {

            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example 2
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
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: BostonHousePrice.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example 5
Source File: SwedishAutoInsurance.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void evaluate(NeuralNetwork neuralNet, DataSet dataSet) {

        System.out.println("Calculating performance indicators for neural network.");

        MeanSquaredError mse = new MeanSquaredError();
        MeanAbsoluteError mae = new MeanAbsoluteError();

        for (DataSetRow testSetRow : dataSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();
            double[] networkOutput = neuralNet.getOutput();
            double[] desiredOutput = testSetRow.getDesiredOutput();
            mse.addPatternError(networkOutput, desiredOutput);
            mae.addPatternError(networkOutput, desiredOutput);
        }

        System.out.println("Mean squared error is: " + mse.getTotalError());
        System.out.println("Mean absolute error is: " + mae.getTotalError());
    }
 
Example 6
Source File: BreastCancerSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {
    System.out.println("********************** TEST RESULT **********************");
    for (DataSetRow testSetRow : testSet.getRows()) {
        neuralNet.setInput(testSetRow.getInput());
        neuralNet.calculate();

        // get network output
        double[] networkOutput = neuralNet.getOutput();
        int predicted = interpretOutput(networkOutput);

        // get target/desired output
        double[] desiredOutput = testSetRow.getDesiredOutput();
        int target = (int)desiredOutput[0];

        // count predictions
        countPredictions(predicted, target);
    }

    System.out.println("Total cases: " + total + ". ");
    System.out.println("Correctly predicted cases: " + correct);
    System.out.println("Incorrectly predicted cases: " + incorrect);
    double percentTotal = (correct / (double)total) * 100;
    System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");
}
 
Example 7
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 8
Source File: DiabetesSample.java    From NeurophFramework with Apache License 2.0 6 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**********************RESULT**********************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            // get network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = interpretOutput(networkOutput);

            // get target/desired output
            double[] desiredOutput = testSetRow.getDesiredOutput();
            int target = (int)desiredOutput[0];

            // count predictions
            countPredictions(predicted, target);
        }

        System.out.println("Total cases: " + total + ". ");
        System.out.println("Correctly predicted cases: " + correct);
        System.out.println("Incorrectly predicted cases: " + incorrect);
        double percentTotal = (correct / (double)total) * 100;
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");
    }
 
Example 9
Source File: BrestCancerSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'M (malignant)' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'B (benign)' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
    }
 
Example 10
Source File: SegmentChallengeSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[7] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[7] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[7] - this.correct[7] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[7] * 100 / (double) this.count[7];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        for (int i = 0; i < correct.length - 1; i++) {
            double p = (double) this.correct[i] * 100.0 / (double) this.count[i];
            System.out.println("Segment class: " + getClasificationClass(i + 1) + " - Correct/total: "
                    + this.correct[i] + "/" + count[i] + "(" + formatDecimalNumber(p) + "%). ");
        }

        this.count = new int[8];
        this.correct = new int[8];
        unpredicted = 0;
    }
 
Example 11
Source File: IonosphereSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'Good' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'Bad' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
        this.count = new int[3];
        this.correct = new int[3];
        unpredicted = 0;
    }
 
Example 12
Source File: IonosphereSample2.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'Good' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'Bad' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
        this.count = new int[3];
        this.correct = new int[3];
        unpredicted = 0;
    }
 
Example 13
Source File: GermanCreditDataSample.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        System.out.println("**************************************************");
        System.out.println("**********************RESULT**********************");
        System.out.println("**************************************************");
        for (DataSetRow testSetRow : testSet.getRows()) {
            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[2] + ". ");
        System.out.println("Correctly predicted cases: " + this.correct[2] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[2] - this.correct[2] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");
        double percentTotal = (double) this.correct[2] * 100 / (double) this.count[2];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        double percentM = (double) this.correct[0] * 100.0 / (double) this.count[0];
        System.out.println("Prediction for 'Good credit risk' => (Correct/total): "
                + this.correct[0] + "/" + count[0] + "(" + formatDecimalNumber(percentM) + "%). ");

        double percentB = (double) this.correct[1] * 100.0 / (double) this.count[1];
        System.out.println("Prediction for 'Bad credit risk' => (Correct/total): "
                + this.correct[1] + "/" + count[1] + "(" + formatDecimalNumber(percentB) + "%). ");
    }
 
Example 14
Source File: Evaluate.java    From NeurophFramework with Apache License 2.0 5 votes vote down vote up
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) {

        for (DataSetRow testSetRow : testSet.getRows()) {

            neuralNet.setInput(testSetRow.getInput());
            neuralNet.calculate();

            //Finding network output
            double[] networkOutput = neuralNet.getOutput();
            int predicted = maxOutput(networkOutput);

            //Finding actual output
            double[] networkDesiredOutput = testSetRow.getDesiredOutput();
            int ideal = maxOutput(networkDesiredOutput);

            //Colecting data for network evaluation
            keepScore(predicted, ideal);
        }

        System.out.println("Total cases: " + this.count[7] + ". ");
        System.out.println("Correct cases: " + this.correct[7] + ". ");
        System.out.println("Incorrectly predicted cases: " + (this.count[7] - this.correct[7] - unpredicted) + ". ");
        System.out.println("Unrecognized cases: " + unpredicted + ". ");

        double percentTotal = (double) this.correct[7] * 100 / (double) this.count[7];
        System.out.println("Predicted correctly: " + formatDecimalNumber(percentTotal) + "%. ");

        for (int i = 0; i < correct.length - 1; i++) {
            double p = (double) this.correct[i] * 100.0 / (double) this.count[i];
            System.out.println("Tree type: " + (i + 1) + " - Correct/total: "
                    + this.correct[i] + "/" + count[i] + "(" + formatDecimalNumber(p) + "%). ");
        }
    }
 
Example 15
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 16
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 17
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 18
Source File: GenerateData.java    From NeurophFramework with Apache License 2.0 4 votes vote down vote up
public void createBalancedTrainingSet(int count) {
    //Creating empety data set
    DataSet balanced = new DataSet(54, 7);
    //Declare counter for all seven type of tree
    int firstType = 0;
    int secondType = 0;
    int thirdType = 0;
    int fourthType = 0;
    int fifthType = 0;
    int sixthType = 0;
    int seventhType = 0;

    DataSet trainingSet = DataSet.load(config.getTrainingFileName());
    List<DataSetRow> rows = trainingSet.getRows();
    System.out.println("Test set size: " + rows.size() + " rows. ");

    for (DataSetRow row : rows) {
        //Taking desired output vector from loaded file
        double[] DesiredOutput = row.getDesiredOutput();
        int index = -1;
        //Find index of number one in output vector.
        for (int i = 0; i < DesiredOutput.length; i++) {
            if (DesiredOutput[i] == 1.0) {
                index = i;
                break;
            }
        }
        //Add row to balanced data set if number of that type of tree is less than maximum
        switch (index + 1) {
            case 1:
                if (firstType < count) {
                    balanced.add(row);
                    firstType++;
                }
                break;
            case 2:
                if (secondType < count) {
                    balanced.add(row);
                    secondType++;
                }
                break;
            case 3:
                if (thirdType < count) {
                    balanced.add(row);
                    thirdType++;
                }
                break;
            case 4:
                if (fourthType < count) {
                    balanced.add(row);
                    fourthType++;
                }
                break;
            case 5:
                if (fifthType < count) {
                    balanced.add(row);
                    fifthType++;
                }
                break;
            case 6:
                if (sixthType < count) {
                    balanced.add(row);
                    sixthType++;
                }
                break;
            case 7:
                if (seventhType < count) {
                    balanced.add(row);
                    seventhType++;
                }
                break;
            default:
                System.out.println("Error with output vector size! ");
        }
    }
    System.out.println("Balanced test set size: " + balanced.getRows().size() + " rows. ");
    System.out.println("Samples per tree: ");
    System.out.println("First type: " + firstType + " samples. ");
    System.out.println("Second type: " + secondType + " samples. ");
    System.out.println("Third type: " + thirdType + " samples. ");
    System.out.println("Fourth type: " + fourthType + " samples. ");
    System.out.println("Fifth type: " + fifthType + " samples. ");
    System.out.println("Sixth type: " + sixthType + " samples. ");
    System.out.println("Seventh type: " + seventhType + " samples. ");

    balanced.save(config.getBalancedFileName());
}
 
Example 19
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]);
            }
        }
    }
}
 
Example 20
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];
            }
        }

    }
}