Пример #1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     nn = new NeuralNetworksLib.NetworkModels.NeuralNetwork(0.9, 0, 0, new int[] { 3, 3, 1 });
     ttpEpochs.SetToolTip(prgEpochs, "Not Running");
     ttpEpochs.Active  = true;
     UIThread          = Dispatcher.CurrentDispatcher;
     treeView1.TopNode = nn.ToTreeNode();
     gfx = nn.CreateDrawing(pictureBox1, 400, 100, 1.5f);
 }
Пример #2
0
        public void Initialize(NeuralNetwork network, RectangleF pbxBounds)
        {
            LayerIndex  = -1;
            LayerWidths = new float[network.Count];
            float maxWidth = 0;
            float height   = (network.Count * LayerDistance) + NeuronDiameter;

            for (int i = 0; i < network.Count; ++i)
            {
                var layer = network[i];
                var width = (layer.Count * NeuronDistance) + NeuronDiameter;
                if (width > maxWidth)
                {
                    maxWidth = width;
                }
                LayerWidths[i] = width;
            }

            bool pbxWidthWise = pbxBounds.Width > pbxBounds.Height;
            bool netWidthWise = maxWidth > height;

            if (pbxWidthWise != netWidthWise)
            {
                Rotated   = true;
                NextLayer = () =>
                {
                    ++LayerIndex;
                    CurrentY  = (LayerWidths[LayerIndex] / ZoomFactor) + 10;
                    CurrentX += LayerDistance;
                };
                NextNeuron = () =>
                {
                    CurrentY += NeuronDistance;
                    CurrentNeuronConnectorOut = new PointF(CurrentX + NeuronDiameter, CurrentY + CenterModifier);
                    CurrentNeuronConnectorIn  = new PointF(CurrentX, CurrentY + CenterModifier);
                };
                Reset = () => CurrentX = 10;
            }
            else
            {
                Rotated   = false;
                NextLayer = () =>
                {
                    ++LayerIndex;
                    CurrentX  = (LayerWidths[LayerIndex] / ZoomFactor) + 10;
                    CurrentY += LayerDistance;
                };
                NextNeuron = () =>
                {
                    CurrentX += NeuronDistance;
                    CurrentNeuronConnectorOut = new PointF(CurrentX + CenterModifier, CurrentY + NeuronDiameter);
                    CurrentNeuronConnectorIn  = new PointF(CurrentX + CenterModifier, CurrentY);
                };
                Reset = () => CurrentY = 10;
            }

            float zoomFactor = (
                pbxWidthWise ? pbxBounds.Width : pbxBounds.Height
                ) / (
                (netWidthWise ? maxWidth : height) + 10
                );

            InitializeDefault(zoomFactor);
        }