public virtual string classify(double[] pattern) { //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: org.neuroph.core.NeuralNetwork<?> nnet = getParentNetwork(); NeuralNetwork nnet = ParentNetwork; nnet.Input = pattern; nnet.calculate(); Neuron maxNeuron = null; double maxOutput = double.Epsilon; foreach (Neuron neuron in nnet.OutputNeurons) { if (neuron.Output > maxOutput) { maxOutput = neuron.Output; maxNeuron = neuron; } } if (maxOutput > threshold) { return(maxNeuron.Label); } else { return(null); } }
/// <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 createPriceConnections() { int[] low = new int[] { 0, 2, 4, 7, 10, 16, 18 }; int[] mid = new int[] { 3, 5, 8, 11, 12, 14, 19 }; int[] high = new int[] { 1, 6, 9, 13, 15, 17 }; // input connections for the first price class for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(low[i]); Neuron toNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(0); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the second price class for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(mid[i]); Neuron toNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(1); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the third price class for (int i = 0; i < 6; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(high[i]); Neuron toNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(2); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the first price class for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(0); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(low[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the second price class for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(1); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(mid[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the third price class for (int i = 0; i < 6; i++) { Neuron fromNeuron = this.getLayerAt(priceLayerIdx).getNeuronAt(2); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(high[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } }
private void createBrandConnections() { int[] samsung = new int[] { 0, 1, 7, 8, 9, 14, 15 }; int[] lg = new int[] { 2, 3, 10, 11, 16, 17 }; int[] sony = new int[] { 4, 5, 6, 12, 13, 18, 19 }; // create samsung input sonnections for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(samsung[i]); Neuron toNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(0); this.createConnection(fromNeuron, toNeuron, 0.1); } // create input connections for LG for (int i = 0; i < 6; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(lg[i]); Neuron toNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(1); this.createConnection(fromNeuron, toNeuron, 0.1); } // create input connections for sony for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(sony[i]); Neuron toNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(2); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the first brand for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(0); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(samsung[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the second brand for (int i = 0; i < 6; i++) { Neuron fromNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(1); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(lg[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the third brand for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(brandLayerIdx).getNeuronAt(2); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(sony[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } }
private void createPromoConnections() { int[] sales = new int[] { 0, 10, 19 }; int[] new_products = new int[] { 6, 9 }; int[] bestsellers = new int[] { 3, 12, 14 }; // input connections for the first promo type for (int i = 0; i < sales.Length; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(sales[i]); Neuron toNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(0); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the second promo type for (int i = 0; i < new_products.Length; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(new_products[i]); Neuron toNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(1); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the third promo type for (int i = 0; i < bestsellers.Length; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(bestsellers[i]); Neuron toNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(2); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the first promo type for (int i = 0; i < sales.Length; i++) { Neuron fromNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(0); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(sales[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the second promo type for (int i = 0; i < new_products.Length; i++) { Neuron fromNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(1); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(new_products[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the third promo type for (int i = 0; i < bestsellers.Length; i++) { Neuron fromNeuron = this.getLayerAt(promoLayerIdx).getNeuronAt(2); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(bestsellers[i]); this.createConnection(fromNeuron, toNeuron, 0.1); } }
private void createTypeConnections() { // input connections for the first product type for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(i); Neuron toNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(0); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the second product type for (int i = 7; i < 14; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(i); Neuron toNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(1); this.createConnection(fromNeuron, toNeuron, 0.1); } // input connections for the third product type for (int i = 14; i < 20; i++) { Neuron fromNeuron = this.getLayerAt(inputLayerIdx).getNeuronAt(i); Neuron toNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(2); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the first product type for (int i = 0; i < 7; i++) { Neuron fromNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(0); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(i); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the second product type for (int i = 7; i < 14; i++) { Neuron fromNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(1); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(i); this.createConnection(fromNeuron, toNeuron, 0.1); } // output connections for the third product type for (int i = 14; i < 20; i++) { Neuron fromNeuron = this.getLayerAt(typeLayerIdx).getNeuronAt(2); Neuron toNeuron = this.getLayerAt(outputLayerIdx).getNeuronAt(i); this.createConnection(fromNeuron, toNeuron, 0.1); } }
/// <summary> /// Returns the index position in layer for the specified neuron /// </summary> /// <param name="neuron"> neuron object </param> /// <returns> index position of specified neuron </returns> public virtual int IndexOf(Neuron neuron) { return(neurons.IndexOf(neuron)); }
/// <summary> /// Removes neuron from layer /// </summary> /// <param name="neuron"> neuron to remove </param> public void removeNeuron(Neuron neuron) { int index = IndexOf(neuron); removeNeuronAt(index); }
/// <summary> /// Creates a new connection to specified neuron with specified weight value /// </summary> /// <param name="fromNeuron"> neuron to connect from </param> /// <param name="toNeuron"> neuron to connect to </param> /// <param name="weightVal"> /// weight value for this connection </param> public Connection(Neuron fromNeuron, Neuron toNeuron, double weightVal) : this(fromNeuron, toNeuron, new Weight(weightVal)) { }