Java Code Examples for org.neuroph.core.data.DataSet#getRows()
The following examples show how to use
org.neuroph.core.data.DataSet#getRows() .
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: SwedishAutoInsurance.java From NeurophFramework with Apache License 2.0 | 6 votes |
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: MaxMinNormalizer.java From NeurophFramework with Apache License 2.0 | 5 votes |
@Override public void normalize(DataSet dataSet) { for (DataSetRow row : dataSet.getRows()) { normalizeVector(row.getInput(), minIn, maxIn); if (dataSet.isSupervised()) { normalizeVector(row.getDesiredOutput(), minOut, maxOut); } } }
Example 3
Source File: BrestCancerSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
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 4
Source File: MlpNetworkTrainer.java From developerWorks with Apache License 2.0 | 5 votes |
/** * Loads training data for the specified years. The data is assumed to be at a location * specified by the {@link NetworkProperties} object (or <code>network.properties</code> file * if the default location is to be overridden). * * @param yearsForTrainingData * The years for which training data is to be loaded. Each element * should contain a separate year. * * @return Neuroph {@link DataSet} object containing all of the training data to be used. */ protected DataSet loadTrainingData(Integer[] yearsForTrainingData) { DataSet ret = new DataSet(NetworkProperties.getNumberOfInputs(), NetworkProperties.getNumberOfOutputs()); List<DataSet> dataSets = new ArrayList<>(); // // Build out the expected file name based on the constants /// and the years in the parameter for (Integer year : yearsForTrainingData) { String filename = NetworkUtils.computeTrainingDataFileName(year); // NetworkProperties.getBaseDirectory() + File.separator + trainingDataDirectory // + File.separator + // NetworkProperties.getTrainingDataFileBase() + "-" + year + NetworkProperties.getTrainingDataFileExtension(); log.info("Loading training data from file: '" + filename + "'..."); DataSet loadedDataSet = DataSet.load(filename); log.info("Training data loaded: " + loadedDataSet.getRows().size() + " rows."); dataSets.add(loadedDataSet); } // // Now combine all of the data sets into one for (DataSet dataSet : dataSets) { for (DataSetRow row : dataSet.getRows()) { ret.addRow(row); } } log.info("Combined " + dataSets.size() + " data sets, consisting of a total of " + ret.size() + " rows."); // log.info("Shuffling training data..."); ret.shuffle(); return ret; }
Example 5
Source File: Evaluate.java From NeurophFramework with Apache License 2.0 | 5 votes |
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 6
Source File: WineQualityClassification.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { System.out.println("Showing inputs, desired output and neural network output for every row in test set."); for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.println("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println("Output: " + Arrays.toString(networkOutput)); System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput())); } }
Example 7
Source File: ConceptLearningAndClassificationSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.print("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println(" Output: " + Arrays.toString(networkOutput)); } }
Example 8
Source File: HopfieldSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Runs this sample */ public static void main(String args[]) { // create training set (H and T letter in 3x3 grid) DataSet trainingSet = new DataSet(9); trainingSet.add(new DataSetRow(new double[]{1, 0, 1, 1, 1, 1, 1, 0, 1})); // H letter trainingSet.add(new DataSetRow(new double[]{1, 1, 1, 0, 1, 0, 0, 1, 0})); // T letter // create hopfield network Hopfield myHopfield = new Hopfield(9); // learn the training set myHopfield.learn(trainingSet); // test hopfield network System.out.println("Testing network"); // add one more 'incomplete' H pattern for testing - it will be recognized as H trainingSet.add(new DataSetRow(new double[]{1, 0, 0, 1, 0, 1, 1, 0, 1})); // print network output for the each element from the specified training set. for(DataSetRow trainingSetRow : trainingSet.getRows()) { myHopfield.setInput(trainingSetRow.getInput()); myHopfield.calculate(); myHopfield.calculate(); double[] networkOutput = myHopfield.getOutput(); System.out.print("Input: " + Arrays.toString(trainingSetRow.getInput()) ); System.out.println(" Output: " + Arrays.toString(networkOutput) ); } }
Example 9
Source File: IonosphereSample2.java From NeurophFramework with Apache License 2.0 | 5 votes |
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 10
Source File: SegmentChallengeSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
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: KMeansClustering.java From NeurophFramework with Apache License 2.0 | 5 votes |
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 12
Source File: PimaIndiansDiabetes.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { System.out.println("Showing inputs, desired output and neural network output for every row in test set."); for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.println("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println("Output: " + Arrays.toString(networkOutput)); System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput())); } }
Example 13
Source File: MaxNormalizer.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * 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 14
Source File: WheatSeeds.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { System.out.println("Showing inputs, desired output and neural network output for every row in test set."); for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.println("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println("Output: " + Arrays.toString(networkOutput)); System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput())); } }
Example 15
Source File: DecimalScaleNormalizer.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * 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 16
Source File: WineQualityClassification.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { System.out.println("Showing inputs, desired output and neural network output for every row in test set."); for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.println("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println("Output: " + Arrays.toString(networkOutput)); System.out.println("Desired output" + Arrays.toString(testSetRow.getDesiredOutput())); } }
Example 17
Source File: GlassIdentificationSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.print("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println(" Output: " + Arrays.toString(networkOutput)); } }
Example 18
Source File: SwedishAutoInsurance.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { System.out.println("Showing inputs, desired output and neural network output for every row in test set."); for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.println("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println("Output: " + networkOutput[0]); System.out.println("Desired output" + Arrays.toString(networkOutput)); } }
Example 19
Source File: ForestFiresSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
public void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { for (DataSetRow testSetRow : testSet.getRows()) { neuralNet.setInput(testSetRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.print("Input: " + Arrays.toString(testSetRow.getInput())); System.out.println(" Output: " + Arrays.toString(networkOutput)); } }
Example 20
Source File: RangeNormalizer.java From NeurophFramework with Apache License 2.0 | 4 votes |
/** * 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]; } } } }