Java implementation of non-learning single-layer Perceptron (log III)

Source: Internet
Author: User

Requirements are as follows:

So when the neuron output function is selected in the Hard pole function, if you want to divide into the above four types, you must have 2 neurons, in fact, for all classification problems, n neurons can be divided into 2 of the n-th type.

The relationships demonstrated in the previous section are:

Thus the values of all weights are calculated.

The code is implemented as follows:

The first class is the class used to manipulate the actual operation, and the real core content is in perceptronclassifynolearn .

 Packagecom.cgrj.com;Importjava.util.Arrays;ImportOrg.neuroph.core.data.DataSet;ImportOrg.neuroph.core.data.DataSetRow;ImportOrg.neuroph.nnet.Perceptron; Public classMyneturol { Public Static voidMain (string[] args) {//TODO auto-generated Method StubDataSet trainingset=NewDataSet (2,2); Trainingset.addrow (NewDatasetrow (New Double[]{1,2},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{1,1},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{2,0},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{2,-1},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{-1,2},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{-2,1},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{-1,-1},New Double[]{double.nan,double.nan}]); Trainingset.addrow (NewDatasetrow (New Double[]{-2,-2},New Double[]{double.nan,double.nan}]); Perceptronclassifynolearn Perceptronclassifynolearn=NewPerceptronclassifynolearn (2);  for(Datasetrow row:trainingSet.getRows ()) {Perceptronclassifynolearn.setinput (Row.getinput ());            Perceptronclassifynolearn.calculate (); Double[] networkoutput=Perceptronclassifynolearn.getoutput (); System.out.println (Arrays.tostring (Row.getinput ())+"="+arrays.tostring (networkoutput)); }                            }}

Perceptronclassifynolearn Rules the input layer and output layer properties and rules, because it is not learned, so its decision rules are still set, in this class.

 Packagecom.cgrj.com;ImportOrg.neuroph.core.Layer;Importorg.neuroph.core.NeuralNetwork;ImportOrg.neuroph.core.Neuron;ImportOrg.neuroph.nnet.comp.neuron.BiasNeuron;ImportOrg.neuroph.nnet.comp.neuron.InputNeuron;Importorg.neuroph.util.ConnectionFactory;Importorg.neuroph.util.LayerFactory;Importorg.neuroph.util.NeuralNetworkFactory;ImportOrg.neuroph.util.NeuralNetworkType;Importorg.neuroph.util.NeuronProperties;ImportOrg.neuroph.util.TransferFunctionType; Public classPerceptronclassifynolearnextendsNeuralnetwork { PublicPerceptronclassifynolearn (intInputneuronscount) {             This. Createnetwork (Inputneuronscount); }        Private voidCreatenetwork (intInputneuronscount) {            //setting up a network-aware machine             This. Setnetworktype (Neuralnetworktype.perceptron); //constructs an input neuron that represents the stimulation of the inputNeuronproperties inputneuronproperties=Newneuronproperties (); Inputneuronproperties.setproperty ("Neurontype", Inputneuron.class); //input layer consisting of input neuronsLayer inputlayer=Layerfactory.createlayer (inputneuronscount,inputneuronproperties);  This. AddLayer (Inputlayer); //add Biasneron to the input layer to indicate neuron biasInputlayer.addneuron (NewBiasneuron ()); //Building output NeuronsNeuronproperties outputneuronproperties=Newneuronproperties (); Outputneuronproperties.setproperty ("Transferfunction", Transferfunctiontype.step); Layer Outputlayer=layerfactory.createlayer (2, outputneuronproperties);  This. AddLayer (Outputlayer);            Connectionfactory.fullconnect (Inputlayer, Outputlayer); Neuralnetworkfactory.setdefaultio ( This); Neuron N=outputlayer.getneuronat (0); N.getinputconnections () [0].getweight (). SetValue (-3); N.getinputconnections () [1].getweight (). SetValue (-1); N.getinputconnections () [2].getweight (). SetValue (1); N=outputlayer.getneuronat (1); N.getinputconnections () [0].getweight (). SetValue (1); N.getinputconnections () [1].getweight (). SetValue (-2); N.getinputconnections () [2].getweight (). SetValue (0); }}

Java implementation of non-learning single-layer Perceptron (log III)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.