/// <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 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(typeof(Neuron), typeof(Difference), typeof(Linear)); // transfer function - input function - neuron type // 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.DefaultIO = this; this.LearningRule = new KohonenLearning(); }
/// <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 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> /// Calculates weights for the hopfield net to learn the specified training /// set /// </summary> /// <param name="trainingSet"> /// training set to learn </param> public override void learn(DataSet trainingSet) { int M = trainingSet.size(); int N = neuralNetwork.getLayerAt(0).NeuronsCount; Layer hopfieldLayer = neuralNetwork.getLayerAt(0); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (j == i) { continue; } Neuron ni = hopfieldLayer.getNeuronAt(i); Neuron nj = hopfieldLayer.getNeuronAt(j); Connection cij = nj.getConnectionFrom(ni); Connection cji = ni.getConnectionFrom(nj); double w = 0; for (int k = 0; k < M; k++) { DataSetRow trainingSetRow = trainingSet.getRowAt(k); double pki = trainingSetRow.Input[i]; double pkj = trainingSetRow.Input[j]; w = w + pki * pkj; } // k cij.Weight.Value = w; cji.Weight.Value = w; } // j } // i }
private void createMatrixLayers() { matrixLayers = new MatrixLayer[sourceNetwork.LayersCount]; matrixLayers[0] = new MatrixInputLayer(sourceNetwork.getLayerAt(0).NeuronsCount); MatrixLayer prevLayer = matrixLayers[0]; for (int i = 1; i < sourceNetwork.LayersCount; i++) { Layer layer = sourceNetwork.getLayerAt(i); MatrixMlpLayer newBpLayer = new MatrixMlpLayer(layer, prevLayer, new Tanh()); matrixLayers[i] = newBpLayer; prevLayer = newBpLayer; } }
/// <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(); }
private void createProductLabels(Layer layer) { layer.getNeuronAt(0).Label = "Samsung LCD TV LE-32A330"; layer.getNeuronAt(1).Label = "Samsung LCD TV LE-32A558"; layer.getNeuronAt(2).Label = "LG LCD TV 32LG2000"; layer.getNeuronAt(3).Label = "LG LCD TV 32LG5010"; layer.getNeuronAt(4).Label = "Sony LCD TV KDL-32L4000K"; layer.getNeuronAt(5).Label = "Sony LCD TV KDL-32S4000"; layer.getNeuronAt(6).Label = "Sony LCD TV KDL-32W4000K"; layer.getNeuronAt(7).Label = "Samsung Digital Camera S760"; layer.getNeuronAt(8).Label = "Samsung Digital Camera L100"; layer.getNeuronAt(9).Label = "Samsung Digital Camera S850"; layer.getNeuronAt(10).Label = "LG Digital Camera DMCLS80E"; layer.getNeuronAt(11).Label = "LG Digital Camera DMCLZ8E"; layer.getNeuronAt(12).Label = "Sony Digital Camera DSCW120S"; layer.getNeuronAt(13).Label = "Sony Digital Camera DSCW130S"; layer.getNeuronAt(14).Label = "Samsung Mobile Phone E251"; layer.getNeuronAt(15).Label = "Samsung Mobile Phone U600"; layer.getNeuronAt(16).Label = "Sony Mobile Phone KP100"; layer.getNeuronAt(17).Label = "Sony Mobile Phone KE850"; layer.getNeuronAt(18).Label = "LG Mobile Phone K330"; layer.getNeuronAt(19).Label = "LG Mobile Phone K660"; }
/// <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("inputFunction", typeof(Difference)); rbfNeuronProperties.setProperty("transferFunction", util.TransferFunctionType.Gaussian.ToString()); // 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.DefaultIO = this; // set appropriate learning rule for this network this.LearningRule = new RBFLearning(); }
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(); }
private void createPromoLabels(Layer layer) { layer.getNeuronAt(0).Label = "Sales"; layer.getNeuronAt(1).Label = "New"; layer.getNeuronAt(2).Label = "Bestseller"; }
private void createPriceLabels(Layer layer) { layer.getNeuronAt(0).Label = "Low Price"; layer.getNeuronAt(1).Label = "Mid Price"; layer.getNeuronAt(2).Label = "High Price"; }
private void createBrandLabels(Layer layer) { layer.getNeuronAt(0).Label = "Samsung"; layer.getNeuronAt(1).Label = "LG"; layer.getNeuronAt(2).Label = "Sony"; }
private void createTypeLabels(Layer layer) { layer.getNeuronAt(0).Label = "LCD TV"; layer.getNeuronAt(1).Label = "Digital Camera"; layer.getNeuronAt(2).Label = "Mobile Phone"; }