码迷,mamicode.com
首页 > 其他好文 > 详细

Neuroph studio 入门教程

时间:2016-04-30 18:20:22      阅读:2064      评论:0      收藏:0      [点我收藏+]

标签:

PERCEPTRON

Perceptron is a simple two layer neural network with several neurons in input layer, and one or more neurons in output layer. All neurons use step transfer function and network can use LMS based learning algorithm such as Perceptron Learning or Delta Rule. This network can be used as a linear classifier, and it can only be applied to linear separable problems.

技术分享

To create and train Perceptron neural network using Neuroph Studio do the following:

  1. Create Neuroph Project.
  2. Create Perceptron network.
  3. Create training set (in main menu choose Training >New Training Set).
  4. Train network
  5. Test trained network

Step 1. Create Neuroph project.

Click File > New Project.

技术分享

 

Select Neuroph Project, click Next.

技术分享

 

Enter project name and location, click Finish.

技术分享

Project is created, now create neural network. 

Step 2. Create Perceptron network.

Click File > New File

技术分享

 

Select project from Project drop-down menu, select Neural Network file type, click next.

技术分享

 

Enter network name, select Perceptron network type, click next.

技术分享

 

In new perceptron dialog enter number ofneurons in input (2) and output layer (1) , choose Perceptron Learningand click Create button.

技术分享

This will create the Perceptron neural network with two neurons in input, and one in output layer. By default, all neurons with Steptransfer functions.

技术分享

Now we shall train this simple network to learn logical AND function. First we have to create the training setaccording to AND truth table.

 

Step 3.  To create training set, click File>New File to open Data Set wizard.

技术分享

 

Select DataSet file type, then click next.

技术分享

 

Enter training set name, number of inputs andoutputs as shown on picture below and click Finish button.

技术分享

 

Then create training set by entering training elements as input and desired output values of neurons in input and outputlayer. Use Add row button to add new elements, and click OK button when finished.

技术分享

 

Step 4. Training network. To start network training procedure, drag n‘ drop training set to corresponding field in the network window, and ‘Train‘ button will become enabled in toolbar. Click the ‘Train‘ button to open Set Learning Parameters dialog.

技术分享

 

In Set Learning parameters dialoguse default learning parameters, and just click the Train button.

技术分享

 

When the Total Net Error is zero, thetraining is complete.

技术分享

 

Step 5. After the training is complete, you can test the network for the whole training set by selecting training set to test, and clicking Test button..

技术分享

 

This will show test results in the new tab.

技术分享

 

To test single input, use Set Input button. This will open Set Network Input dialog in which you can enter input values for network delimited withspace.

技术分享

 

The result of network test is shown on picture below. Network learned logical AND function. As we can see the outputneuron has value 1. Test the network to see how it behaves for other input values.

技术分享

 

 

PERCEPTRON IN JAVA CODE

package org.neuroph.samples;

import java.util.Arrays;
import org.neuroph.core.NeuralNetwork;
import org.neuroph.nnet.Perceptron;
import org.neuroph.core.data.DataSet;
import org.neuroph.core.data.DataSetRow;

/**
* This sample shows how to create, train, save and load simple Perceptron neural network
*/
public class PerceptronSample {

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.createFromFile("mySamplePerceptron.nnet");

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

}

public static void testNeuralNetwork(NeuralNetwork nnet, DataSet tset) {

for(DataSetRow dataRow : tset.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) );

}

}

}

EXTERNAL LINKS

To learn more about the Perceptrons see:

Neuroph studio 入门教程

标签:

原文地址:http://www.cnblogs.com/100thMountain/p/5448982.html

(0)
(2)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!