Java Code Examples for org.neuroph.core.NeuralNetwork#setInput()
The following examples show how to use
org.neuroph.core.NeuralNetwork#setInput() .
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 |
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 |
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: DiabetesSample.java From NeurophFramework with Apache License 2.0 | 6 votes |
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 4
Source File: Classifier.java From NeurophFramework with Apache License 2.0 | 6 votes |
public String classify(double[] pattern) { NeuralNetwork<?> nnet = getParentNetwork(); nnet.setInput(pattern); nnet.calculate(); Neuron maxNeuron = null; double maxOutput = Double.MIN_VALUE; for (Neuron neuron : nnet.getOutputNeurons()) { if (neuron.getOutput() > maxOutput) { maxOutput = neuron.getOutput(); maxNeuron = neuron; } } if (maxOutput > threshold) return maxNeuron.getLabel(); else return null; }
Example 5
Source File: XorResilientPropagationSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Prints network output for each element from the specified training set. * @param neuralNet neural network * @param trainingSet training set */ public static 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 6
Source File: ShuttleLandingControlSample.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 7
Source File: Abalone.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 8
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 9
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 10
Source File: Banknote.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 11
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 12
Source File: PerceptronSample.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * Prints network output for the each element from the specified training set. * @param neuralNet neural network * @param testSet data set used for testing */ public static void testNeuralNetwork(NeuralNetwork neuralNet, DataSet testSet) { for(DataSetRow trainingElement : testSet.getRows()) { neuralNet.setInput(trainingElement.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.print("Input: " + Arrays.toString(trainingElement.getInput()) ); System.out.println(" Output: " + Arrays.toString(networkOutput) ); } }
Example 13
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 14
Source File: WineClassificationSample.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 15
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 16
Source File: Sonar.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: 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 18
Source File: Main.java From NeurophFramework with Apache License 2.0 | 4 votes |
public static void main(String[] args) { System.out.println("Time stamp N1:" + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:MM").format(new Date())); int maxIterations = 10000; NeuralNetwork neuralNet = new MultiLayerPerceptron(4, 9, 1); ((LMS) neuralNet.getLearningRule()).setMaxError(0.001);//0-1 ((LMS) neuralNet.getLearningRule()).setLearningRate(0.7);//0-1 ((LMS) neuralNet.getLearningRule()).setMaxIterations(maxIterations);//0-1 DataSet trainingSet = new DataSet(4, 1); double daxmax = 10000.0D; trainingSet.add(new DataSetRow(new double[]{3710.0D / daxmax, 3690.0D / daxmax, 3890.0D / daxmax, 3695.0D / daxmax}, new double[]{3666.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3690.0D / daxmax, 3890.0D / daxmax, 3695.0D / daxmax, 3666.0D / daxmax}, new double[]{3692.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3890.0D / daxmax, 3695.0D / daxmax, 3666.0D / daxmax, 3692.0D / daxmax}, new double[]{3886.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3695.0D / daxmax, 3666.0D / daxmax, 3692.0D / daxmax, 3886.0D / daxmax}, new double[]{3914.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3666.0D / daxmax, 3692.0D / daxmax, 3886.0D / daxmax, 3914.0D / daxmax}, new double[]{3956.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3692.0D / daxmax, 3886.0D / daxmax, 3914.0D / daxmax, 3956.0D / daxmax}, new double[]{3953.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3886.0D / daxmax, 3914.0D / daxmax, 3956.0D / daxmax, 3953.0D / daxmax}, new double[]{4044.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3914.0D / daxmax, 3956.0D / daxmax, 3953.0D / daxmax, 4044.0D / daxmax}, new double[]{3987.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3956.0D / daxmax, 3953.0D / daxmax, 4044.0D / daxmax, 3987.0D / daxmax}, new double[]{3996.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3953.0D / daxmax, 4044.0D / daxmax, 3987.0D / daxmax, 3996.0D / daxmax}, new double[]{4043.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{4044.0D / daxmax, 3987.0D / daxmax, 3996.0D / daxmax, 4043.0D / daxmax}, new double[]{4068.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3987.0D / daxmax, 3996.0D / daxmax, 4043.0D / daxmax, 4068.0D / daxmax}, new double[]{4176.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{3996.0D / daxmax, 4043.0D / daxmax, 4068.0D / daxmax, 4176.0D / daxmax}, new double[]{4187.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{4043.0D / daxmax, 4068.0D / daxmax, 4176.0D / daxmax, 4187.0D / daxmax}, new double[]{4223.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{4068.0D / daxmax, 4176.0D / daxmax, 4187.0D / daxmax, 4223.0D / daxmax}, new double[]{4259.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{4176.0D / daxmax, 4187.0D / daxmax, 4223.0D / daxmax, 4259.0D / daxmax}, new double[]{4203.0D / daxmax})); trainingSet.add(new DataSetRow(new double[]{4187.0D / daxmax, 4223.0D / daxmax, 4259.0D / daxmax, 4203.0D / daxmax}, new double[]{3989.0D / daxmax})); neuralNet.learn(trainingSet); System.out.println("Time stamp N2:" + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:MM").format(new Date())); DataSet testSet = new DataSet(4, 1); testSet.add(new DataSetRow(new double[]{4223.0D / daxmax, 4259.0D / daxmax, 4203.0D / daxmax, 3989.0D / daxmax})); for (DataSetRow testDataRow : testSet.getRows()) { neuralNet.setInput(testDataRow.getInput()); neuralNet.calculate(); double[] networkOutput = neuralNet.getOutput(); System.out.print("Input: " + Arrays.toString(testDataRow.getInput()) ); System.out.println(" Output: " + Arrays.toString(networkOutput) ); } //Experiments: // calculated //31;3;2009;4084,76 -> 4121 Error=0.01 Rate=0.7 Iterat=100 //31;3;2009;4084,76 -> 4096 Error=0.01 Rate=0.7 Iterat=1000 //31;3;2009;4084,76 -> 4093 Error=0.01 Rate=0.7 Iterat=10000 //31;3;2009;4084,76 -> 4108 Error=0.01 Rate=0.7 Iterat=100000 //31;3;2009;4084,76 -> 4084 Error=0.001 Rate=0.7 Iterat=10000 System.out.println("Time stamp N3:" + new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss:MM").format(new Date())); System.exit(0); }
Example 19
Source File: ActionListCalculateWithWork.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String modelFlag, String workId) throws Exception { logger.debug(effectivePerson, "modelFlag:{}, workId:{}.", modelFlag, workId); try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { ActionResult<List<Wo>> result = new ActionResult<>(); Business business = new Business(emc); Model model = emc.flag(modelFlag, Model.class); if (null == model) { throw new ExceptionEntityNotExist(modelFlag, Model.class); } if (StringUtils.isEmpty(model.getNnet())) { throw new ExceptionModelNotReady(model.getName()); } NeuralNetwork<MomentumBackpropagation> neuralNetwork = null; String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), model.getId()); Element element = cache.get(cacheKey); if (null != element && (null != element.getObjectValue())) { neuralNetwork = ((NeuralNetwork<MomentumBackpropagation>) element.getObjectValue()); } else { if (StringUtils.isEmpty(model.getNnet())) { throw new ExceptionModelNotReady(model.getName()); } neuralNetwork = model.createNeuralNetwork(); NeuralNetworkCODEC.array2network( DoubleTools.byteToDoubleArray(ByteTools.decompressBase64String(model.getNnet())), neuralNetwork); cache.put(new Element(cacheKey, neuralNetwork)); } Wo wo = new Wo(); Work work = emc.flag(workId, Work.class); if (null == work) { throw new ExceptionEntityNotExist(workId, Work.class); } TreeSet<String> inValue = this.convert(business, model, work); double[] inputs = this.inputData(business, model, inValue); neuralNetwork.setInput(inputs); neuralNetwork.calculate(); double[] outputs = neuralNetwork.getOutput(); // double mean = StatUtils.mean(outputs); List<Pair> pairs = new ArrayList<>(); for (int i = 0; i < outputs.length; i++) { // if (outputs[i] > mean) { Pair p = new Pair(); p.setOut(outputs[i]); p.setSerial(i); pairs.add(p); // } } pairs = pairs.stream().sorted(Comparator.comparing(Pair::getOut).reversed()).collect(Collectors.toList()); Integer maxResult = MapTools.getInteger(model.getPropertyMap(), Model.PROPERTY_MLP_MAXRESULT, Model.DEFAULT_MLP_MAXRESULT); if (pairs.size() > maxResult) { pairs = pairs.stream().limit(maxResult).collect(Collectors.toList()); } List<Wo> wos = this.outputData(business, model, pairs); result.setData(wos); return result; } }
Example 20
Source File: BostonHousePrice.java From NeurophFramework with Apache License 2.0 | 4 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)); } }