private void DrawNeuralNetPair(Diagram diagram, out List<ShapeNode>[] nodes, BasicNetwork neuralNet) { if (diagram.Items.Count > 0) diagram.ClearAll(); ProcessPair pp = cbProcessPair.SelectedItem as ProcessPair; TemplXML.FormData form = ConvertDataArrayToXml(templ, trainingData[pp.Pair].InputArray); double dx = 400; double rastNode = 30; double startYF = 50; double startX = dx + 50; // + (neuralNet.LayerCount - 1) * 300; double startY = 50; double diam = 30; double startYMax = startY; nodes = new List<ShapeNode>[neuralNet.LayerCount]; string label = "null"; graphPairLinkInput = new List<DiagramLink>(neuralNet.Flat.LayerCounts[neuralNet.LayerCount - 1]); for (int i = neuralNet.LayerCount - 1; i >= 0; i--) { List<ShapeNode> curN = new List<ShapeNode>(); for (int j = 0; j < neuralNet.Flat.LayerCounts[i]; j++) { ShapeNode tmp = DiagramHelper.CreateNode(diagram, startX, startY, diam, diam, j.ToString()); tmp.MouseLeftButtonDown += nodeSelected_MouseLeftButtonDown; curN.Add(tmp); if (i == neuralNet.LayerCount - 1 && j < neuralNet.InputCount) { ShapeNode q = DiagramHelper.CreateNode(Shapes.Rectangle, diagram, startX - dx - 200, startY - 10, 200, 50, form.Values[j].Field.Title); if (form.Values[j] is TemplXML.FormDataValueNumber) { var tmpF = form.Values[j] as TemplXML.FormDataValueNumber; label = string.Format("{0}", tmpF.Value); } else { var tmpF = form.Values[j] as TemplXML.FormDataValueSelect; label = tmpF.Value.Title; } var tmpLink = DiagramHelper.CreateLink(diagram, q, tmp, label); tmpLink.MouseLeftButtonDown += linkSelect_MouseLeftButtonDown; graphPairLinkInput.Add(tmpLink); } startY += diam + rastNode; } nodes[i] = curN; startX += dx; if (startYMax < startY) startYMax = startY; if (i != 0) startY = startYMax / 2 - neuralNet.Flat.LayerCounts[i - 1] * (rastNode + diam) / 2; } string tmpWeigth; int countN; for (int i = neuralNet.LayerCount - 1; i > 0; i--) { countN = countN = neuralNet.Flat.LayerCounts[i - 1]; if (i - 1 == neuralNet.LayerCount - 2 && neuralNet.GetLayerBiasActivation(i - 1) > 0) countN -= 1; for (int x = 0; x < neuralNet.Flat.LayerCounts[i]; x++) { for (int y = 0; y < countN; y++) { tmpWeigth = neuralNet.GetWeight(neuralNet.LayerCount - i - 1, x, y).ToString("F4"); var link = DiagramHelper.CreateLink(diagram, nodes[i][x], nodes[i - 1][y], tmpWeigth); link.MouseLeftButtonDown += linkSelect_MouseLeftButtonDown; } } } }
/// <summary> /// Craete a freeform network from a basic network. /// </summary> /// <param name="network">The basic network to use.</param> public FreeformNetwork(BasicNetwork network) { if (network.LayerCount < 2) { throw new FreeformNetworkError( "The BasicNetwork must have at least two layers to be converted."); } // handle each layer IFreeformLayer previousLayer = null; for (int currentLayerIndex = 0; currentLayerIndex < network .LayerCount; currentLayerIndex++) { // create the layer IFreeformLayer currentLayer = _layerFactory.Factor(); // Is this the input layer? if (_inputLayer == null) { _inputLayer = currentLayer; } // Add the neurons for this layer for (int i = 0; i < network.GetLayerNeuronCount(currentLayerIndex); i++) { // obtain the summation object. IInputSummation summation = null; if (previousLayer != null) { summation = _summationFactory.Factor(network .GetActivation(currentLayerIndex)); } // add the new neuron currentLayer.Add(_neuronFactory.FactorRegular(summation)); } // Fully connect this layer to previous if (previousLayer != null) { ConnectLayersFromBasic(network, currentLayerIndex - 1, previousLayer, currentLayer); } // Add the bias neuron // The bias is added after connections so it has no inputs if (network.IsLayerBiased(currentLayerIndex)) { IFreeformNeuron biasNeuron = _neuronFactory .FactorRegular(null); biasNeuron.IsBias = true; biasNeuron.Activation = network .GetLayerBiasActivation(currentLayerIndex); currentLayer.Add(biasNeuron); } // update previous layer previousLayer = currentLayer; } // finally, set the output layer. _outputLayer = previousLayer; }
private void DrawNeuralNet(Diagram diagram, out List<ShapeNode>[] nodes, BasicNetwork neuralNet) { if (diagram.Items.Count > 0) diagram.ClearAll(); //получение шаблона InitEvent netInit = cbTrainsLog.SelectedItem as InitEvent; //TemplXML.FormTemplate templ; string pathXML = netInit.Path.Replace(".np4", ".xml"); if (!File.Exists(pathXML)) MessageBox.Show("Форма не найдена"); templ = TemplXML.FormTemplate.FromXml(XElement.Load(pathXML)); double dx = 400; double rastNode = 30; double startYF = 50; double startX = dx + 50; // + (neuralNet.LayerCount - 1) * 300; double startY = 50; double diam = 30; double startYMax = startY; nodes = new List<ShapeNode>[neuralNet.LayerCount]; for (int i = neuralNet.LayerCount - 1 ; i >= 0; i--) { List<ShapeNode> curN = new List<ShapeNode>(); for (int j = 0; j < neuralNet.Flat.LayerCounts[i]; j++) { ShapeNode tmp = DiagramHelper.CreateNode(diagram, startX, startY, diam, diam, j.ToString()); tmp.MouseLeftButtonDown += nodeSelected_MouseLeftButtonDown;; curN.Add(tmp); if (i == neuralNet.LayerCount - 1 && j <neuralNet.InputCount) { ShapeNode q = DiagramHelper.CreateNode(Shapes.Rectangle, diagram, startX - dx, startY, 200, 50, templ.Fields[j].Title); DiagramLink link = DiagramHelper.CreateLink(diagram, q, tmp); link.MouseLeftButtonDown += linkSelect_MouseLeftButtonDown; } startY += diam + rastNode; } nodes[i] = curN; startX += dx; if (startYMax < startY) startYMax = startY; if(i != 0) startY = startYMax / 2 - neuralNet.Flat.LayerCounts[i - 1] * (rastNode + diam) / 2; } string tmpWeigth; int countN; for (int i = neuralNet.LayerCount - 1; i > 0; i--) { countN = countN = neuralNet.Flat.LayerCounts[i - 1]; if (i - 1 == neuralNet.LayerCount - 2 && neuralNet.GetLayerBiasActivation(i - 1) > 0) countN -= 1; for (int x = 0; x < neuralNet.Flat.LayerCounts[i]; x++) { for (int y = 0; y < countN; y++) { tmpWeigth = neuralNet.GetWeight(neuralNet.LayerCount - i - 1, x, y).ToString("F4"); var link = DiagramHelper.CreateLink(diagram, nodes[i][x], nodes[i - 1][y], tmpWeigth); link.MouseLeftButtonDown += linkSelect_MouseLeftButtonDown; } } } }