• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NeuralNetwork类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.neuroph.core.NeuralNetwork的典型用法代码示例。如果您正苦于以下问题:Java NeuralNetwork类的具体用法?Java NeuralNetwork怎么用?Java NeuralNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NeuralNetwork类属于org.neuroph.core包,在下文中一共展示了NeuralNetwork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testNeuralNet(NeuralNetwork nnet, DataSet dataSet, String setName) {
    int counter = 0;
    for (DataSetRow row : dataSet.getRows()) {
        nnet.setInput(row.getInput());
        nnet.calculate();
        double[] networkOutput = nnet.getOutput();
        if (isOutputSame(networkOutput, row.getDesiredOutput())) {
            counter++;
        } else {
            for (int i = 0; i < row.getDesiredOutput().length; i++) {
                if (row.getDesiredOutput()[i] == 1) {
                    Integer d = errorMap.get(i);
                    if (d == null) {
                        errorMap.put(i, 1);
                    } else {
                        errorMap.put(i, ++d);
                    }
                    break;
                }
            }
        }
    }

    System.out.println(setName + " success rate: " + (counter / (double) dataSet.size()));
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:26,代码来源:OneToOneHVTest.java


示例2: testLearnedNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testLearnedNeuralNet(DataSet trainingSet, DataSet testSet) {
    NeuralNetwork nnet = NeuralNetwork.createFromFile(NNET_NAME);
    System.out.println("Testing loaded neural network");
    //testNeuralNet(nnet, trainingSet, "Training set");
    testNeuralNet(nnet, testSet, "Test set");
    for(Map.Entry<Integer, Integer> entry : errorMap.entrySet()) {
        //System.out.println(entry.getKey() + " " + entry.getValue());
    }
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:10,代码来源:OneToOneHVTest.java


示例3: testNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testNeuralNet(NeuralNetwork nnet, DataSet dataSet, String setName) {
    int counter = 0;
    for (DataSetRow row : dataSet.getRows()) {
        nnet.setInput(row.getInput());
        nnet.calculate();
        double[] networkOutput = nnet.getOutput();

        if (isOutputSame(networkOutput, row.getDesiredOutput())) {
            counter++;
        } else {
            for (int i = 0; i < row.getDesiredOutput().length; i++) {
                if (row.getDesiredOutput()[i] == 1) {
                    Integer d = errorMap.get(i);
                    if (d == null) {
                        errorMap.put(i, 1);
                    } else {
                        errorMap.put(i, ++d);
                    }
                    break;
                }
            }
        }
    }

    System.out.println(setName + " success rate: " + (counter / (double) dataSet.size()));
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:27,代码来源:EnglishOneToOneHorizontalTest_SmallTest.java


示例4: startCheck

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
@FXML
private void startCheck(ActionEvent event) throws IOException {
    if (nnetSrc == null || imgSrc == null) {
        Calert.showAlert("Invalid Data", "Select Required Files", Alert.AlertType.ERROR);
        return;
    }
    try {
        nnet = NeuralNetwork.load(new FileInputStream(nnetSrc)); // load trained neural network saved with Neuroph Studio
        System.out.println("Learning Rule = " + nnet.getLearningRule());
        ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the 
        HashMap<String, Double> output = imageRecognition.recognizeImage(ImageIO.read(imgSrc));
        if (output == null) {
            System.err.println("Image Recognition Failed");
        }
        double real = output.get("real");
        double fake = output.get("faked");
        System.out.println(output.toString());
        Calert.showAlert("Result", "Real = " + real + "\nFake = " + fake, Alert.AlertType.INFORMATION);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(SingleImageAnalyzerController.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:afsalashyana,项目名称:FakeImageDetection,代码行数:23,代码来源:SingleImageAnalyzerController.java


示例5: main

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
public static void main(String[] args) {
    try {
        System.out.println("usage java -jar nn.jar image_to_be_processed file_of_neural_network");
        System.out.println("Loading Image....");
        image = ImageIO.read(new File(args[0]));
        System.out.println("Loading NN....");
        File NNetwork = new File(args[1]);
        if (!NNetwork.exists()) {
            System.err.println("Cant Find NN");
            return;
        }
        nnet = NeuralNetwork.load(new FileInputStream(NNetwork)); // load trained neural network saved with Neuroph Studio
        System.out.println("Load Image Recog Plugin....");
        imageRecognition = (ImageRecognitionPlugin) nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network
        System.out.println("Recognize Image....");
        HashMap<String, Double> output = imageRecognition.recognizeImage(image);
        System.out.println("Output is....");
        System.out.println(output.toString());
    } catch (IOException ex) {
        Logger.getLogger(NeuralNetProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:afsalashyana,项目名称:FakeImageDetection,代码行数:23,代码来源:NeuralNetProcessor.java


示例6: doRun

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
@Override
public void doRun() {
    try {
        System.out.println("Starting training thread....." + sampleDimension.toString() + " and " + imageLabels.toString());

        HashMap<String, BufferedImage> imagesMap = new HashMap<String, BufferedImage>();
        for (File file : srcDirectory.listFiles()) {
            imageLabels.add(FilenameUtils.removeExtension(file.getName()));
            if (sampleDimension.getWidth() > 0 && sampleDimension.getHeight() > 0) {
                Double w = sampleDimension.getWidth();
                Double h = sampleDimension.getHeight();
                imagesMap.put(file.getName(), ImageUtilities.resizeImage(ImageUtilities.loadImage(file), w.intValue(), h.intValue()));
            }
        }
        Map<String, FractionRgbData> imageRgbData = ImageUtilities.getFractionRgbDataForImages(imagesMap);
        DataSet learningData = ImageRecognitionHelper.createRGBTrainingSet(imageLabels, imageRgbData);

        nnet = NeuralNetwork.load(new FileInputStream(nnFile)); //Load NNetwork
        MomentumBackpropagation mBackpropagation = (MomentumBackpropagation) nnet.getLearningRule();
        mBackpropagation.setLearningRate(learningRate);
        mBackpropagation.setMaxError(maxError);
        mBackpropagation.setMomentum(momentum);

        System.out.println("Network Information\nLabel = " + nnet.getLabel()
                + "\n Input Neurons = " + nnet.getInputsCount()
                + "\n Number of layers = " + nnet.getLayersCount()
        );

        mBackpropagation.addListener(this);
        System.out.println("Starting training......");
        nnet.learn(learningData, mBackpropagation);
        //Training Completed
        listener.batchImageTrainingCompleted();
    } catch (FileNotFoundException ex) {
        System.out.println(ex.getMessage() + "\n" + ex.getLocalizedMessage());
    }

}
 
开发者ID:afsalashyana,项目名称:FakeImageDetection,代码行数:39,代码来源:BatchImageTrainer.java


示例7: main

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
/**
 * Runs this sample
 */
public static void main(String args[]) {
 
        // create training set (logical AND function)
        DataSet trainingSet = new DataSet(2, 1);
        trainingSet.addRow(new DataSetRow(new double[]{0, 0}, new double[]{0}));
        trainingSet.addRow(new DataSetRow(new double[]{0, 1}, new double[]{0}));
        trainingSet.addRow(new DataSetRow(new double[]{1, 0}, new double[]{0}));
        trainingSet.addRow(new DataSetRow(new double[]{1, 1}, new double[]{1}));

        // create perceptron neural network
        NeuralNetwork myPerceptron = new Perceptron(2, 1);
        // learn the training set
        myPerceptron.learn(trainingSet);
        // test perceptron
        System.out.println("Testing trained perceptron");
        testNeuralNetwork(myPerceptron, trainingSet);
        // save trained perceptron
        myPerceptron.save("mySamplePerceptron.nnet");
        // load saved neural network
        NeuralNetwork loadedPerceptron = NeuralNetwork.load("mySamplePerceptron.nnet");
        // test loaded neural network
        System.out.println("Testing loaded perceptron");
        testNeuralNetwork(loadedPerceptron, trainingSet);

}
 
开发者ID:East196,项目名称:maker,代码行数:29,代码来源:PerceptronSample.java


示例8: SimulatedAnnealingLearning

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
/**
 * Construct a simulated annleaing trainer for a feedforward neural network.
 * 
 * @param network
 *            The neural network to be trained.
 * @param startTemp
 *            The starting temperature.
 * @param stopTemp
 *            The ending temperature.
 * @param cycles
 *            The number of cycles in a training iteration.
 */
public SimulatedAnnealingLearning(final NeuralNetwork network,
		final double startTemp, final double stopTemp, final int cycles) {
	this.network = network;
	this.temperature = startTemp;
	this.startTemperature = startTemp;
	this.stopTemperature = stopTemp;
	this.cycles = cycles;

	this.weights = new double[NeuralNetworkCODEC
			.determineArraySize(network)];
	this.bestWeights = new double[NeuralNetworkCODEC
			.determineArraySize(network)];

	NeuralNetworkCODEC.network2array(network, this.weights);
	NeuralNetworkCODEC.network2array(network, this.bestWeights);
}
 
开发者ID:fiidau,项目名称:Y-Haplogroup-Predictor,代码行数:29,代码来源:SimulatedAnnealingLearning.java


示例9: setDefaultIO

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
/**
 * Sets default input and output neurons for network (first layer as input,
 * last as output)
 */
public static void setDefaultIO(NeuralNetwork nnet) {
              ArrayList<Neuron> inputNeuronsList = new ArrayList<Neuron>();
               Layer firstLayer = nnet.getLayerAt(0);
               for (Neuron neuron : firstLayer.getNeurons() ) {
                   if (!(neuron instanceof BiasNeuron)) {  // dont set input to bias neurons
                       inputNeuronsList.add(neuron);
                   }
               }

               Neuron[] inputNeurons = new Neuron[inputNeuronsList.size()];
               inputNeurons = inputNeuronsList.toArray(inputNeurons);
	Neuron[] outputNeurons = ((Layer) nnet.getLayerAt(nnet.getLayersCount()-1)).getNeurons();

	nnet.setInputNeurons(inputNeurons);
	nnet.setOutputNeurons(outputNeurons); 
}
 
开发者ID:fiidau,项目名称:Y-Haplogroup-Predictor,代码行数:21,代码来源:NeuralNetworkFactory.java


示例10: testLearnedNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testLearnedNeuralNet(DataSet trainingSet, DataSet testSet) {
    NeuralNetwork nnet = NeuralNetwork.createFromFile(NNET_NAME);
    System.out.println("Testing loaded neural network");
    //testNeuralNet(nnet, trainingSet, "Training set");
    testNeuralNet(nnet, testSet, "Test set");
    for(Map.Entry<Integer, Integer> entry : errorMap.entrySet()) {
        System.out.println(entry.getKey() + " " + entry.getValue());
    }
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:10,代码来源:OneToOneNonUniqueDiagonalTest.java


示例11: main

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
public static void main(String[] args) {

// create training set (logical XOR function)
        DataSet trainingSet = new DataSet(2, 1);
        trainingSet.addRow(new DataSetRow(new double[]{0, 0}, new double[]{0}));
        trainingSet.addRow(new DataSetRow(new double[]{0, 1}, new double[]{1}));
        trainingSet.addRow(new DataSetRow(new double[]{1, 0}, new double[]{1}));
        trainingSet.addRow(new DataSetRow(new double[]{1, 1}, new double[]{0}));


// create multi layer perceptron
        MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron(TransferFunctionType.SIGMOID, 2, 3, 1);
        myMlPerceptron.setLearningRule(new BackPropagation());
// learn the training set
        myMlPerceptron.learn(trainingSet);
// test perceptron
        System.out.println("Testing trained neural network");
        testNeuralNetwork(myMlPerceptron, trainingSet);

// save trained neural network
        myMlPerceptron.save("myMlPerceptron.nnet");

// load saved neural network
        NeuralNetwork loadedMlPerceptron = NeuralNetwork.createFromFile("myMlPerceptron.nnet");

// test loaded neural network
        System.out.println("Testing loaded neural network");
        testNeuralNetwork(loadedMlPerceptron, trainingSet);

    }
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:31,代码来源:TestLearn.java


示例12: testNeuralNetwork

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
public static void testNeuralNetwork(NeuralNetwork nnet, DataSet testSet) {

        for(DataSetRow dataRow : testSet.getRows()) {
            nnet.setInput(dataRow.getInput());
            nnet.calculate();
            double[ ] networkOutput = nnet.getOutput();
            System.out.print("Input: " + Arrays.toString(dataRow.getInput()) );
            System.out.println(" Output: " + Arrays.toString(networkOutput) );
        }

    }
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:12,代码来源:TestLearn.java


示例13: testLearnedNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testLearnedNeuralNet(DataSet trainingSet, DataSet testSet) {
        NeuralNetwork nnet = NeuralNetwork.createFromFile(NNET_NAME);
        System.out.println("Testing loaded neural network");
        //testNeuralNet(nnet, trainingSet, "Training set");
        testNeuralNet(nnet, testSet, "Test set");
//        for(Map.Entry<Integer, Integer> entry : errorMap.entrySet()) {
//            System.out.println(entry.getKey() + " " + entry.getValue());
//        }
    }
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:10,代码来源:EnglishOneToOneHorizontalTest_SmallTest.java


示例14: testNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testNeuralNet(NeuralNetwork nnet, DataSet dataSet, String setName) {
    int counter = 0;
    for (DataSetRow row : dataSet.getRows()) {
        nnet.setInput(row.getInput());
        nnet.calculate();
        double[] networkOutput = nnet.getOutput();

       // System.out.println(Arrays.toString(networkOutput));

        if (isOutputSame(networkOutput, row.getDesiredOutput())) {
            counter++;
        } else {
            for (int i = 0; i < row.getDesiredOutput().length; i++) {
                if (row.getDesiredOutput()[i] == 1) {
                    Integer d = errorMap.get(i);
                    if (d == null) {
                        errorMap.put(i, 1);
                    } else {
                        errorMap.put(i, ++d);
                    }
                    break;
                }
            }
        }
    }

    System.out.println(setName + " success rate: " + (counter / (double) dataSet.size()));
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:29,代码来源:EnglishOneToOneDiagonalCrossTest_SmallTest.java


示例15: testNeuralNet

import org.neuroph.core.NeuralNetwork; //导入依赖的package包/类
private static void testNeuralNet(NeuralNetwork nnet, DataSet dataSet, String setName) {
    int counter = 0;
    for (DataSetRow row : dataSet.getRows()) {
        nnet.setInput(row.getInput());
        nnet.calculate();
        double[] networkOutput = nnet.getOutput();
        //System.out.println(Arrays.toString(networkOutput));

        if (isOutputSame(networkOutput, row.getDesiredOutput())) {
            counter++;
        } else {
            for (int i = 0; i < row.getDesiredOutput().length; i++) {
                if (row.getDesiredOutput()[i] == 1) {
                    Integer d = errorMap.get(i);
                    if (d == null) {
                        errorMap.put(i, 1);
                    } else {
                        errorMap.put(i, ++d);
                    }
                    break;
                }
            }
        }
    }

    System.out.println(setName + " success rate: " + (counter / (double) dataSet.size()));
}
 
开发者ID:fgulan,项目名称:final-thesis,代码行数:28,代码来源:OneToOneHorizontalTest_SmallTest.java



注:本文中的org.neuroph.core.NeuralNetwork类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EpochCounter类代码示例发布时间:2022-05-23
下一篇:
Java ForeignAttributesImpl类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap