packagecom.cgjr.com;importorg.neuroph.core.Layer;importorg.neuroph.core.NeuralNetwork;importorg.neuroph.nnet.comp.neuron.BiasNeuron;importorg.neuroph.nnet.learning.LMS;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 class Adaline extendsNeuralNetwork {/*** The class fingerprint that is set to indicate serialization compatibility
* with a previous version of the class.*/
private static final long serialVersionUID = 1L;/*** Creates new Adaline network with specified number of neurons in input
* layer
*
*@paraminputNeuronsCount
* number of neurons in input layer*/
public Adaline(int inputNeuronsCount, int outputNeuronsCount, doublelearnRate, TransferFunctionType transferFunction) {this.createNetwork(inputNeuronsCount, outputNeuronsCount, learnRate,transferFunction);
}/*** Creates adaline network architecture with specified number of input
* neurons
*
*@paraminputNeuronsCount
* number of neurons in input layer*/
private void createNetwork(int inputNeuronsCount, int outputNeuronsCount, doublelearnRate,
TransferFunctionType transferFunction) {//set network type code
this.setNetworkType(NeuralNetworkType.ADALINE);//create input layer neuron settings for this network
NeuronProperties inNeuronProperties = newNeuronProperties();
inNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR);//createLayer input layer with specified number of neurons
Layer inputLayer =LayerFactory.createLayer(inputNeuronsCount, inNeuronProperties);
inputLayer.addNeuron(new BiasNeuron()); //add bias neuron (always 1,//and it will act as bias input//for output neuron)
this.addLayer(inputLayer);//create output layer neuron settings for this network
NeuronProperties outNeuronProperties = newNeuronProperties();if (transferFunction ==TransferFunctionType.LINEAR) {
outNeuronProperties.setProperty("transferFunction", TransferFunctionType.LINEAR);
}else{
outNeuronProperties.setProperty("transferFunction", TransferFunctionType.RAMP);
outNeuronProperties.setProperty("transferFunction.slope", new Double(1));
outNeuronProperties.setProperty("transferFunction.yHigh", new Double(1));
outNeuronProperties.setProperty("transferFunction.xHigh", new Double(1));
outNeuronProperties.setProperty("transferFunction.yLow", new Double(-1));
outNeuronProperties.setProperty("transferFunction.xLow", new Double(-1));
}//createLayer output layer (only one neuron)
Layer outputLayer =LayerFactory.createLayer(outputNeuronsCount, outNeuronProperties);this.addLayer(outputLayer);//createLayer full conectivity between input and output layer
ConnectionFactory.fullConnect(inputLayer, outputLayer);//set input and output cells for network
NeuralNetworkFactory.setDefaultIO(this);//set LMS learning rule for this network
LMS l = newLMS();
l.setLearningRate(learnRate);this.setLearningRule(l);
}
}