/// <summary> /// Creates perceptron architecture with specified number of neurons in input /// and output layer, specified transfer function /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> /// <param name="outputNeuronsCount">number of neurons in output layer</param> /// <param name="transferFunctionType">neuron transfer function type</param> private void CreateNetwork(int inputNeuronsCount, int outputNeuronsCount, TransferFunctionType transferFunctionType) { // set network type this.NetworkType = NeuralNetworkType.PERCEPTRON; // init neuron settings for input layer NeuronProperties inputNeuronProperties = new NeuronProperties(); inputNeuronProperties.SetProperty("transferFunction", TransferFunctionType.LINEAR); // create input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, inputNeuronProperties); this.AddLayer(inputLayer); NeuronProperties outputNeuronProperties = new NeuronProperties(); outputNeuronProperties.SetProperty("neuronType", typeof(ThresholdNeuron)); outputNeuronProperties.SetProperty("thresh", Math.Abs(ThreadSafeRandom.NextDouble())); outputNeuronProperties.SetProperty("transferFunction", transferFunctionType); // for sigmoid and tanh transfer functions set slope propery outputNeuronProperties.SetProperty("transferFunction.slope", 1); // createLayer output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, outputNeuronProperties); this.AddLayer(outputLayer); // create full conectivity between input and output layer ConnectionFactory.FullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); this.LearningRule = new BinaryDeltaRule(); }
/// <summary> /// Creates MaxNet network architecture /// </summary> /// <param name="neuronsCount">neuron number in network</param> private void CreateNetwork(int neuronsCount) { // set network type this.NetworkType = NeuralNetworkType.MAXNET; // createLayer input layer in layer Layer inputLayer = LayerFactory.createLayer(neuronsCount, new NeuronProperties()); this.AddLayer(inputLayer); // createLayer properties for neurons in output layer NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("neuronType", typeof(CompetitiveNeuron)); neuronProperties.SetProperty("transferFunction", TransferFunctionType.RAMP); // createLayer full connectivity in competitive layer CompetitiveLayer competitiveLayer = new CompetitiveLayer(neuronsCount, neuronProperties); // add competitive layer to network this.AddLayer(competitiveLayer); double competitiveWeight = -(1 / (double)neuronsCount); // createLayer full connectivity within competitive layer ConnectionFactory.FullConnect(competitiveLayer, competitiveWeight, 1); // createLayer forward connectivity from input to competitive layer ConnectionFactory.ForwardConnect(inputLayer, competitiveLayer, 1); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); }
/// <summary> /// Creates an instance of Unsuervised Hebian net with specified number /// of neurons in input layer and output layer, and transfer function /// </summary> /// <param name="inputNeuronsNum">number of neurons in input layer</param> /// <param name="outputNeuronsNum">number of neurons in output layer</param> /// <param name="transferFunctionType">transfer function type</param> private void CreateNetwork(int inputNeuronsNum, int outputNeuronsNum, TransferFunctionType transferFunctionType) { // init neuron properties NeuronProperties neuronProperties = new NeuronProperties(); // neuronProperties.setProperty("bias", new Double(-Math // .abs(Math.random() - 0.5))); // Hebbian network cann not work // without bias neuronProperties.SetProperty("transferFunction", transferFunctionType); neuronProperties.SetProperty("transferFunction.slope", 1); // set network type code this.NetworkType = NeuralNetworkType.UNSUPERVISED_HEBBIAN_NET; // createLayer input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum, neuronProperties); this.AddLayer(inputLayer); // createLayer output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum, neuronProperties); this.AddLayer(outputLayer); // createLayer full conectivity between input and output layer ConnectionFactory.FullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set appropriate learning rule for this network this.LearningRule = new UnsupervisedHebbianLearning(this); //this.setLearningRule(new OjaLearning(this)); }
/// <summary> /// Creates Kohonen network architecture with specified number of neurons in /// input and map layer /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> /// <param name="outputNeuronsCount">number of neurons in output layer</param> private void CreateNetwork(int inputNeuronsCount, int outputNeuronsCount) { // specify input neuron properties (use default: weighted sum input with // linear transfer) NeuronProperties inputNeuronProperties = new NeuronProperties(); // specify map neuron properties NeuronProperties outputNeuronProperties = new NeuronProperties(); outputNeuronProperties.SetProperty("weightsFunction", typeof(Diference)); outputNeuronProperties.SetProperty("summingFunction", typeof(Intensity)); outputNeuronProperties.SetProperty("transferFunction", typeof(Linear)); // set network type this.NetworkType = NeuralNetworkType.KOHONEN; // createLayer input layer Layer inLayer = LayerFactory.createLayer(inputNeuronsCount, inputNeuronProperties); this.AddLayer(inLayer); // createLayer map layer Layer mapLayer = LayerFactory.createLayer(outputNeuronsCount, outputNeuronProperties); this.AddLayer(mapLayer); // createLayer full connectivity between input and output layer ConnectionFactory.FullConnect(inLayer, mapLayer); // set network input and output cells NeuralNetworkFactory.SetDefaultIO(this); this.LearningRule = new KohonenLearning(this); }
/// <summary> /// Creates an instance of Supervised Hebbian Network with specified number /// of neurons in input layer, output layer and transfer function /// </summary> /// <param name="inputNeuronsNum">number of neurons in input layer</param> /// <param name="outputNeuronsNum">number of neurons in output layer</param> /// <param name="transferFunctionType">transfer function type</param> private void CreateNetwork(int inputNeuronsNum, int outputNeuronsNum, TransferFunctionType transferFunctionType) { // init neuron properties NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("transferFunction", transferFunctionType); neuronProperties.SetProperty("transferFunction.slope", 1); neuronProperties.SetProperty("transferFunction.yHigh", 1); neuronProperties.SetProperty("transferFunction.xHigh", 1); neuronProperties.SetProperty("transferFunction.yLow", -1); neuronProperties.SetProperty("transferFunction.xLow", -1); // set network type code this.NetworkType = NeuralNetworkType.SUPERVISED_HEBBIAN_NET; // createLayer input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsNum, neuronProperties); this.AddLayer(inputLayer); // createLayer output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsNum, neuronProperties); this.AddLayer(outputLayer); // createLayer full conectivity between input and output layer ConnectionFactory.FullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set appropriate learning rule for this network this.LearningRule = new SupervisedHebbianLearning(this); }
public static Layer createLayer(int neuronsCount, TransferFunctionType transferFunctionType) { NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("transferFunction", transferFunctionType); Layer layer = createLayer(neuronsCount, neuronProperties); return layer; }
/// <summary> /// Creates Competitive network architecture /// </summary> /// <param name="inputNeuronsCount">input neurons number</param> /// <param name="outputNeuronsCount">neuron properties</param> private void CreateNetwork(int inputNeuronsCount, int outputNeuronsCount) { // set network type this.NetworkType = NeuralNetworkType.COMPETITIVE; // createLayer input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, new NeuronProperties()); this.AddLayer(inputLayer); // createLayer properties for neurons in output layer NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("neuronType", typeof(CompetitiveNeuron)); neuronProperties.SetProperty("weightsFunction", typeof(WeightedInput)); neuronProperties.SetProperty("summingFunction", typeof(Sum)); neuronProperties.SetProperty("transferFunction", TransferFunctionType.RAMP); // createLayer full connectivity in competitive layer CompetitiveLayer competitiveLayer = new CompetitiveLayer(outputNeuronsCount, neuronProperties); // add competitive layer to network this.AddLayer(competitiveLayer); double competitiveWeight = -(1 / (double)outputNeuronsCount); // createLayer full connectivity within competitive layer ConnectionFactory.FullConnect(competitiveLayer, competitiveWeight, 1); // createLayer full connectivity from input to competitive layer ConnectionFactory.FullConnect(inputLayer, competitiveLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); this.LearningRule = new CompetitiveLearning(this); }
/// <summary> /// Creates RbfNetwork architecture with specified number of neurons in input /// layer, output layer and transfer function /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> /// <param name="rbfNeuronsCount">number of neurons in rbf layer</param> /// <param name="outputNeuronsCount">number of neurons in output layer</param> private void CreateNetwork(int inputNeuronsCount, int rbfNeuronsCount, int outputNeuronsCount) { // init neuron settings for this network NeuronProperties rbfNeuronProperties = new NeuronProperties(); rbfNeuronProperties.SetProperty("weightsFunction", typeof(Diference)); rbfNeuronProperties.SetProperty("summingFunction", typeof(Intensity)); rbfNeuronProperties.SetProperty("transferFunction", typeof(Gaussian)); // set network type code this.NetworkType = NeuralNetworkType.RBF_NETWORK; // create input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, TransferFunctionType.LINEAR); this.AddLayer(inputLayer); // create rbf layer Layer rbfLayer = LayerFactory.createLayer(rbfNeuronsCount, rbfNeuronProperties); this.AddLayer(rbfLayer); // create output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, TransferFunctionType.LINEAR); this.AddLayer(outputLayer); // create full conectivity between input and rbf layer ConnectionFactory.FullConnect(inputLayer, rbfLayer); // create full conectivity between rbf and output layer ConnectionFactory.FullConnect(rbfLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set appropriate learning rule for this network this.LearningRule = new LMS(this); }
/// <summary> /// Creates adaline network architecture with specified number of input neurons /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> private void CreateNetwork(int inputNeuronsCount) { // createLayer neuron settings for this network NeuronProperties neuronProperties = new NeuronProperties(); // set network type code this.NetworkType = NeuralNetworkType.ADALINE; // createLayer input layer with specified number of neurons Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, neuronProperties); this.AddLayer(inputLayer); // createLayer output layer (only one neuron) Layer outputLayer = LayerFactory.createLayer(1, neuronProperties); 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 this.LearningRule = new LMS(this); }
/// <summary> /// Creates BAM network architecture /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> /// <param name="outputNeuronsCount">number of neurons in output layer</param> /// <param name="neuronProperties">neuron properties</param> private void CreateNetwork(int inputNeuronsCount, int outputNeuronsCount, NeuronProperties neuronProperties) { // set network type this.NetworkType = NeuralNetworkType.BAM; // create input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, neuronProperties); // add input layer to network this.AddLayer(inputLayer); // create output layer Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, neuronProperties); // add output layer to network this.AddLayer(outputLayer); // create full connectivity from in to out layer ConnectionFactory.FullConnect(inputLayer, outputLayer); // create full connectivity from out to in layer ConnectionFactory.FullConnect(outputLayer, inputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set Hebbian learning rule for this network this.LearningRule = new BinaryHebbianLearning(this); }
/// <summary> /// Creates Instar architecture with specified number of input neurons /// </summary> /// <param name="inputNeuronsCount">number of neurons in input layer</param> private void CreateNetwork(int inputNeuronsCount) { // set network type this.NetworkType = NeuralNetworkType.INSTAR; // init neuron settings for this type of network NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("transferFunction", TransferFunctionType.STEP); // create input layer Layer inputLayer = LayerFactory.createLayer(inputNeuronsCount, neuronProperties); this.AddLayer(inputLayer); // createLayer output layer neuronProperties.SetProperty("transferFunction", TransferFunctionType.STEP); Layer outputLayer = LayerFactory.createLayer(1, neuronProperties); this.AddLayer(outputLayer); // create full conectivity between input and output layer ConnectionFactory.FullConnect(inputLayer, outputLayer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set appropriate learning rule for this network this.LearningRule = new InstarLearning(this); }
/// <summary> /// Creates an instance of Layer with the specified number of neurons with /// specified neuron properties /// </summary> /// <param name="neuronsCount">number of neurons in layer</param> /// <param name="neuronProperties">properties of neurons in layer</param> public Layer(int neuronsCount, NeuronProperties neuronProperties) : this() { for (int i = 0; i < neuronsCount; i++) { Neuron neuron = NeuronFactory.CreateNeuron(neuronProperties); this.AddNeuron(neuron); } }
/// <summary> /// Creates new MultiLayerPerceptron with specified number of neurons in layers /// </summary> /// <param name="neuronsInLayers">collection of neuron number in layers</param> public MultiLayerPerceptron(IList<int> neuronsInLayers) { // init neuron settings NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("useBias", true); neuronProperties.SetProperty("transferFunction", TransferFunctionType.SIGMOID); this.CreateNetwork(neuronsInLayers, neuronProperties); }
/// <summary> /// Creates and returns neuron instance according to the given specification in neuronProperties. /// </summary> /// <param name="neuronProperties">specification of neuron properties</param> /// <returns>returns instance of neuron with specified properties</returns> public static Neuron CreateNeuron(NeuronProperties neuronProperties) { InputFunction inputFunction = null; Type inputFunctionClass = neuronProperties.InputFunction; if (!inputFunctionClass.Equals(" ")) { inputFunction = CreateInputFunction(inputFunctionClass); } else { WeightsFunction weightsFunction = CreateWeightsFunction(neuronProperties.WeightsFunction); SummingFunction summingFunction = CreateSummingFunction(neuronProperties.SummingFunction); inputFunction = new InputFunction(weightsFunction, summingFunction); } TransferFunction transferFunction = CreateTransferFunction(neuronProperties.GetTransferFunctionProperties()); Neuron neuron = null; Type neuronClass = neuronProperties.NeuronType; // use two param constructor to create neuron Type[] paramTypes = { typeof(InputFunction), typeof(TransferFunction) }; ConstructorInfo con = neuronClass.GetConstructor(paramTypes); if (con != null) { Object[] paramList = new Object[2]; paramList[0] = inputFunction; paramList[1] = transferFunction; object o = con.Invoke(paramList); neuron = (Neuron)o; } if (neuron == null) { neuron = (Neuron)Activator.CreateInstance(neuronClass); } if (neuronProperties.HasProperty("thresh")) { ((ThresholdNeuron)neuron).Thresh = ((Double)neuronProperties.GetProperty("thresh")); } else if (neuronProperties.HasProperty("bias")) { ((InputOutputNeuron)neuron).Bias = ((Double)neuronProperties.GetProperty("bias")); } return neuron; }
/// <summary> /// Creates new Hopfield network with specified neuron number /// </summary> /// <param name="neuronsCount">neurons number in Hopfied network</param> public Hopfield(int neuronsCount) { // init neuron settings for hopfield network NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("neuronType", typeof(InputOutputNeuron)); neuronProperties.SetProperty("bias", 0); neuronProperties.SetProperty("transferFunction", TransferFunctionType.STEP); neuronProperties.SetProperty("transferFunction.yHigh", 1); neuronProperties.SetProperty("transferFunction.yLow", 0); this.CreateNetwork(neuronsCount, neuronProperties); }
public MultiLayerPerceptron(TransferFunctionType transferFunctionType, params int[] neuronsInLayers) { // init neuron settings NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.SetProperty("useBias", true); neuronProperties.SetProperty("transferFunction", transferFunctionType); neuronProperties.SetProperty("inputFunction", typeof(WeightedSum)); IList<int> neuronsInLayersVector = new List<int>(); for (int i = 0; i < neuronsInLayers.Length; i++) neuronsInLayersVector.Add(neuronsInLayers[i]); this.CreateNetwork(neuronsInLayersVector, neuronProperties); }
/// <summary> /// Creates Hopfield network architecture /// </summary> /// <param name="neuronsCount">neurons number in Hopfied network</param> /// <param name="neuronProperties">neuron properties</param> private void CreateNetwork(int neuronsCount, NeuronProperties neuronProperties) { // set network type this.NetworkType = NeuralNetworkType.HOPFIELD; // createLayer neurons in layer Layer layer = LayerFactory.createLayer(neuronsCount, neuronProperties); // createLayer full connectivity in layer ConnectionFactory.FullConnect(layer, 0.1); // add layer to network this.AddLayer(layer); // set input and output cells for this network NeuralNetworkFactory.SetDefaultIO(this); // set Hopfield learning rule for this network //this.setLearningRule(new HopfieldLearning(this)); this.LearningRule = new BinaryHebbianLearning(this); }
public static Layer createLayer(int neuronsCount, NeuronProperties neuronProperties) { Layer layer = new Layer(neuronsCount, neuronProperties); return layer; }
/// <summary> /// Creates new MultiLayerPerceptron net with specified number neurons in /// getLayersIterator /// </summary> /// <param name="neuronsInLayers">collection of neuron numbers in layers</param> /// <param name="neuronProperties">neuron propreties</param> public MultiLayerPerceptron(IList<int> neuronsInLayers, NeuronProperties neuronProperties) { this.CreateNetwork(neuronsInLayers, neuronProperties); }
/// <summary> /// Creates new Hopfield network with specified neuron number and neuron /// properties /// </summary> /// <param name="neuronsCount">neurons number in Hopfied network</param> /// <param name="neuronProperties">neuron properties</param> public Hopfield(int neuronsCount, NeuronProperties neuronProperties) { this.CreateNetwork(neuronsCount, neuronProperties); }
/// <summary> /// Creates MultiLayerPerceptron Network architecture - fully connected /// feedforward with specified number of neurons in each layer /// </summary> /// <param name="neuronsInLayers">collection of neuron numbers in getLayersIterator</param> /// <param name="neuronProperties">neuron propreties</param> protected void CreateNetwork(IList<int> neuronsInLayers, NeuronProperties neuronProperties) { // set network type this.NetworkType = NeuralNetworkType.MULTI_LAYER_PERCEPTRON; // create input layer NeuronProperties inputNeuronProperties = new NeuronProperties(TransferFunctionType.LINEAR); Layer layer = LayerFactory.createLayer(neuronsInLayers[0], inputNeuronProperties); bool useBias = true; // use bias neurons by default if (neuronProperties.HasProperty("useBias")) { useBias = (Boolean)neuronProperties.GetProperty("useBias"); } if (useBias) { layer.AddNeuron(new BiasNeuron()); } this.AddLayer(layer); // create layers Layer prevLayer = layer; //for(Integer neuronsNum : neuronsInLayers) for (int layerIdx = 1; layerIdx < neuronsInLayers.Count; layerIdx++) { int neuronsNum = neuronsInLayers[layerIdx]; // createLayer layer layer = LayerFactory.createLayer(neuronsNum, neuronProperties); if (useBias && (layerIdx < (neuronsInLayers.Count - 1))) { layer.AddNeuron(new BiasNeuron()); } // add created layer to network this.AddLayer(layer); // createLayer full connectivity between previous and this layer if (prevLayer != null) ConnectionFactory.FullConnect(prevLayer, layer); prevLayer = layer; } // set input and output cells for network NeuralNetworkFactory.SetDefaultIO(this); // set learnng rule //this.setLearningRule(new BackPropagation(this)); this.LearningRule = new MomentumBackpropagation(); // this.setLearningRule(new DynamicBackPropagation()); }
/// <summary> /// Creates and returns a new instance of Multi Layer Perceptron /// </summary> /// <param name="layersStr">space separated number of neurons in layers</param> /// <param name="transferFunctionType">transfer function type for neurons</param> /// <param name="learningRule">instance of Multi Layer Perceptron</param> /// <param name="useBias"></param> /// <param name="connectIO"></param> /// <returns></returns> public static MultiLayerPerceptron CreateMLPerceptron(String layersStr, TransferFunctionType transferFunctionType, Type learningRule, bool useBias, bool connectIO) { IList<int> layerSizes = VectorParser.ParseInteger(layersStr); NeuronProperties neuronProperties = new NeuronProperties(transferFunctionType, useBias); MultiLayerPerceptron nnet = new MultiLayerPerceptron(layerSizes, neuronProperties); // set learning rule if (learningRule.Name.Equals(typeof(BackPropagation).Name)) { nnet.LearningRule = new BackPropagation(); } else if (learningRule.Name.Equals(typeof(MomentumBackpropagation).Name)) { nnet.LearningRule = new MomentumBackpropagation(); } else if (learningRule.Name.Equals(typeof(DynamicBackPropagation).Name)) { nnet.LearningRule = new DynamicBackPropagation(); } // connect io if (connectIO) { nnet.ConnectInputsToOutputs(); } return nnet; }
/// <summary> /// Create an instance of CompetitiveLayer with the specified number of /// neurons with neuron properties /// </summary> /// <param name="neuronNum">neuron number in this layer</param> /// <param name="neuronProperties">properties for the nurons in this layer</param> public CompetitiveLayer(int neuronNum, NeuronProperties neuronProperties) : base(neuronNum, neuronProperties) { MaxIterations = 100; }