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; } } } }
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; } } } }