/// <summary> /// Creates Outstar architecture with specified number of neurons in /// output layer /// </summary> /// <param name="outputNeuronsCount"> /// number of neurons in output layer </param> private void createNetwork(int outputNeuronsCount) { // set network type this.NetworkType = NeuralNetworkType.OUTSTAR; // init neuron settings for this type of network NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.setProperty("transferFunction", TransferFunctionType.Step.ToString()); // create input layer Layer inputLayer = LayerFactory.createLayer(1, neuronProperties); this.addLayer(inputLayer); // createLayer output layer neuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString()); Layer outputLayer = LayerFactory.createLayer(outputNeuronsCount, 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.DefaultIO = this; // set outstar learning rule for this network this.LearningRule = new OutstarLearning(); }
/// <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.DefaultIO = this; // set Hebbian learning rule for this network this.LearningRule = new BinaryHebbianLearning(); }
/// <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.ToString()); 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.DefaultIO = this; // set appropriate learning rule for this network this.LearningRule = new UnsupervisedHebbianLearning(); //this.setLearningRule(new OjaLearning(this)); }
/// <summary> /// Creates MaxNet network architecture /// </summary> /// <param name="neuronNum"> /// neuron number in network </param> /// <param name="neuronProperties"> /// neuron properties </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.ToString()); // 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.DefaultIO = 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.ToString()); 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.DefaultIO = this; // set appropriate learning rule for this network this.LearningRule = new SupervisedHebbianLearning(); }
/// <summary> /// Creates 2D layer with specified dimensions, filled with neurons with /// specified properties /// </summary> /// <param name="dimensions"> layer dimensions </param> /// <param name="neuronProperties"> neuron properties </param> public FeatureMapLayer(Dimension2D dimensions, NeuronProperties neuronProperties, Dimension2D kernelDimension) : this(dimensions, kernelDimension) { for (int i = 0; i < dimensions.Height * dimensions.Width; i++) { Neuron neuron = NeuronFactory.createNeuron(neuronProperties); addNeuron(neuron); } }
/// <summary> /// Creates an empty 2D layer with specified dimensions /// </summary> /// <param name="dimensions"> layer dimensions (width and weight) </param> public FeatureMapLayer(Dimension2D dimensions, NeuronProperties neuronProperties) { this.dimensions = dimensions; for (int i = 0; i < dimensions.Height * dimensions.Width; i++) { Neuron neuron = NeuronFactory.createNeuron(neuronProperties); addNeuron(neuron); } }
/// <summary> /// Creates a new instance of InputLayer with specified number of input neurons </summary> /// <param name="neuronsCount"> input neurons count for this layer </param> public InputLayer(int neuronsCount) { NeuronProperties inputNeuronProperties = new NeuronProperties(typeof(InputNeuron), typeof(Linear)); for (int i = 0; i < neuronsCount; i++) { Neuron neuron = NeuronFactory.createNeuron(inputNeuronProperties); this.addNeuron(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.ToString()); neuronProperties.setProperty("transferFunction.yHigh", 1); neuronProperties.setProperty("transferFunction.yLow", 0); this.createNetwork(neuronsCount, 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.DefaultIO = this; // set Hopfield learning rule for this network //this.setLearningRule(new HopfieldLearning(this)); this.LearningRule = new BinaryHebbianLearning(); }
// three layers: input, hidden, output // as mlp add context layer // jordan connect output of output layer to input of context layer // output of context to input of hidden layer private void createNetwork(int inputNeuronsCount, int hiddenNeuronsCount, int contextNeuronsCount, int outputNeuronsCount) { // create input layer InputLayer inputLayer = new InputLayer(inputNeuronsCount); inputLayer.addNeuron(new BiasNeuron()); addLayer(inputLayer); NeuronProperties neuronProperties = new NeuronProperties(); // neuronProperties.setProperty("useBias", true); neuronProperties.setProperty("transferFunction", TransferFunctionType.Sigmoid.ToString()); // use linear or logitic function! (TR-8604.pdf) Layer hiddenLayer = new Layer(hiddenNeuronsCount, neuronProperties); hiddenLayer.addNeuron(new BiasNeuron()); addLayer(hiddenLayer); ConnectionFactory.fullConnect(inputLayer, hiddenLayer); Layer contextLayer = new Layer(contextNeuronsCount, neuronProperties); addLayer(contextLayer); // we might also need bias for context neurons? Layer outputLayer = new Layer(outputNeuronsCount, neuronProperties); addLayer(outputLayer); ConnectionFactory.fullConnect(hiddenLayer, outputLayer); ConnectionFactory.fullConnect(outputLayer, contextLayer); ConnectionFactory.fullConnect(contextLayer, hiddenLayer); // set input and output cells for network NeuralNetworkFactory.DefaultIO = this; // set learnng rule this.LearningRule = new BackPropagation(); }
/// <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) { // set network type code this.NetworkType = NeuralNetworkType.ADALINE; // create input layer neuron settings for this network NeuronProperties inNeuronProperties = new NeuronProperties(); inNeuronProperties.setProperty("transferFunction", TransferFunctionType.Linear.ToString()); // 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 = new NeuronProperties(); outNeuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString()); outNeuronProperties.setProperty("transferFunction.slope", 1); outNeuronProperties.setProperty("transferFunction.yHigh", 1); outNeuronProperties.setProperty("transferFunction.xHigh", 1); outNeuronProperties.setProperty("transferFunction.yLow", -1); outNeuronProperties.setProperty("transferFunction.xLow", -1); // createLayer output layer (only one neuron) Layer outputLayer = LayerFactory.createLayer(1, outNeuronProperties); this.addLayer(outputLayer); // createLayer full conectivity between input and output layer ConnectionFactory.fullConnect(inputLayer, outputLayer); // set input and output cells for network NeuralNetworkFactory.DefaultIO = this; // set LMS learning rule for this network this.LearningRule = new LMS(); }
/// <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); }
public virtual void createDemoNetwork() { int productsCount = 20; int typesCount = 3; int brandsCount = 3; int priceCount = 3; int promoCount = 3; this.NetworkType = NeuralNetworkType.RECOMMENDER; //this.getLayers().clear(); // init neuron settings for this type of network NeuronProperties neuronProperties = new NeuronProperties(); neuronProperties.setProperty("transferFunction", TransferFunctionType.Ramp.ToString()); // for sigmoid and tanh transfer functions neuronProperties.setProperty("transferFunction.slope", 1); // create input layer Layer inputLayer = LayerFactory.createLayer(productsCount, neuronProperties); this.addLayer(inputLayer); createProductLabels(inputLayer); // create product types layer Layer typeLayer = LayerFactory.createLayer(typesCount, neuronProperties); createTypeLabels(typeLayer); this.addLayer(typeLayer); // create brands layer Layer brandLayer = LayerFactory.createLayer(brandsCount, neuronProperties); createBrandLabels(brandLayer); this.addLayer(brandLayer); // create price layer Layer priceLayer = LayerFactory.createLayer(priceCount, neuronProperties); createPriceLabels(priceLayer); this.addLayer(priceLayer); // create price layer Layer promoLayer = LayerFactory.createLayer(promoCount, neuronProperties); createPromoLabels(promoLayer); this.addLayer(promoLayer); // create output layer Layer outputLayer = LayerFactory.createLayer(productsCount, neuronProperties); this.addLayer(outputLayer); createProductLabels(outputLayer); createTypeConnections(); createBrandConnections(); createPriceConnections(); createPromoConnections(); // create reccurent self connections in output layer foreach (Neuron neuron in this.getLayerAt(outputLayerIdx).Neurons) { neuron.addInputConnection(neuron, 1); } // set input and output cells for this network NeuralNetworkFactory.DefaultIO = this; // dont learn the self connections // moze cak i posle svakog prolaza da se primenjuje hebbianovo pravilo a ne samo nakon kupovine // napravi vise varijanti // ako kupuje onda moze da se primenjje winner takes all hebbian learning this.LearningRule = new UnsupervisedHebbianLearning(); }
/// <summary> /// Creates pooling layer with specified kernel, appropriate map /// dimensions in regard to previous layer (fromLayer param) and specified /// number of feature maps with given neuron properties. /// </summary> /// <param name="fromLayer"> previous layer, which will be connected to this layer </param> /// <param name="kernel"> kernel for all feature maps </param> /// <param name="numberOfMaps"> number of feature maps to create in this layer </param> /// <param name="neuronProp"> settings for neurons in feature maps </param> public PoolingLayer(FeatureMapsLayer fromLayer, Dimension2D kernelDim, int numberOfMaps, NeuronProperties neuronProp) { this.kernel = kernel; Dimension2D fromDimension = fromLayer.MapDimensions; int mapWidth = fromDimension.Width / kernel.Width; int mapHeight = fromDimension.Height / kernel.Height; this.mapDimensions = new Dimension2D(mapWidth, mapHeight); createFeatureMaps(numberOfMaps, mapDimensions, kernelDim, neuronProp); }
/// <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) { }