/// <summary> /// Обучить нейрон-победитель. /// </summary> /// <param name="neuronWinner">Нейрон-победитель.</param> /// <param name="inputEntity">Входной вектор.</param> /// <param name="learningRate">Скорость обучения.</param> public void StudyNeuron(KohonenNeuron neuronWinner, NetworkDataEntity inputEntity, double learningRate) { for (int i = 0; i < neuronWinner.Weights.Count(); i++) { neuronWinner.Weights[i] = neuronWinner.Weights[i] + learningRate * (inputEntity.AttributeValues[i].GetNormalizedValue(NormalizationType) - neuronWinner.Weights[i]); } }
private void CreateGraphFromANN() { BidirectionalGraph <object, IEdge <object> > g = new BidirectionalGraph <object, IEdge <object> >(); if (RNA is Kohonen) { int inputN = ((Kohonen)RNA).GetInputLayerSize(); for (int x = 0; x < inputN; x++) { g.AddVertex("Input-" + (x + 1).ToString()); } KohonenNeuron[,] layer = ((Kohonen)RNA).GetCompetitiveLayer(); for (int i = 0; i < ((Kohonen)RNA).GetCompetitiveLayerLength(); i++) { for (int j = 0; j < ((Kohonen)RNA).GetCompetitiveLayerLength(); j++) { KohonenNeuron neuron = layer[i, j]; g.AddVertex(neuron); for (int x2 = 0; x2 < inputN; x2++) { g.AddEdge(new Edge <object>("Input-" + (x2 + 1).ToString(), neuron)); } } } } else //is Backpropagation { List <BackpropagationLayer> layers = ((Backpropagation)RNA).GetLayers(); foreach (BackpropagationLayer layer in layers) { foreach (BackpropagationNeuron neuron in layer.neurons) { g.AddVertex(neuron); } } foreach (BackpropagationLayer layer in layers) { foreach (BackpropagationNeuron neuron in layer.neurons) { foreach (BackpropagationConnection conn in neuron.listConnection) { g.AddEdge(new Edge <object>(conn.neuron, neuron)); } } } } graphLayout.Graph = g; graphLayout.LayoutMode = LayoutMode.Automatic; graphLayout.LayoutAlgorithmType = "Tree"; }
/// <summary> /// Получить нейрон-победитель. /// </summary> /// <param name="inputEntity">Входной вектор.</param> /// <returns>Нейрон-победитель для входного вектора.</returns> public override KohonenNeuron GetNeuronWinner(NetworkDataEntity inputEntity) { var attributeValues = inputEntity.AttributeValues.Select(v => v.GetNormalizedValue(NormalizationType)); double minDistance = GetEuclideanDistance(Neurons[0].Weights, attributeValues); KohonenNeuron neuronWinner = Neurons[0]; for (int i = 1; i < Neurons.Count; i++) { double currentDistance = GetEuclideanDistance(Neurons[i].Weights, attributeValues); if (currentDistance < minDistance) { minDistance = currentDistance; neuronWinner = Neurons[i]; } } return(neuronWinner); }
private void btnRecognize_Click(object sender, RoutedEventArgs e) { if (IsPatternRight()) { if (RNA is Backpropagation) { double[] ret = RNA.Recognize(GetInputPattern()); DrawGraph(); txtResult.Text = ""; string linebreak = ""; string comma = ""; foreach (double r in ret) { txtResult.Text += comma + linebreak + r.ToString(); linebreak = "\n"; comma = ", "; } } else // is Kohonen { KohonenNeuron neuron = ((Kohonen)RNA).RecognizeWinnerNeuron(GetInputPattern()); txtResult.Text = "Neurônio Vencedor: " + neuron.ToString() + "\n\n"; txtResult.Text += "Pesos:"; int x = 1; foreach (double w in neuron.weights) { txtResult.Text += "\nInput-" + x.ToString() + ": " + w.ToString(); x++; } } } else { MessageBox.Show("Padrão de entrada com formato incorreto!"); txtInputPattern.Focus(); } }
private void Click_Edge(object sender, RoutedEventArgs e) { if (RNA is Backpropagation) { BackpropagationNeuron source = (BackpropagationNeuron)((Edge <object>)(((EdgeControl)sender).Edge)).Source; BackpropagationNeuron target = (BackpropagationNeuron)((Edge <object>)(((EdgeControl)sender).Edge)).Target; foreach (BackpropagationConnection conn in target.listConnection) { if (conn.neuron == source) { graphText.Content = "Peso: " + conn.valueWeight; break; } } } else // is Kohonen { string source = (string)((Edge <object>)(((EdgeControl)sender).Edge)).Source; KohonenNeuron target = (KohonenNeuron)((Edge <object>)(((EdgeControl)sender).Edge)).Target; string[] sA = source.Split('-'); int wIndex = (Convert.ToInt32(sA[1]) - 1); graphText.Content = "Peso: " + target.weights[wIndex]; } }