示例#1
0
        public void NotifyNeuronsWeightChange(int layerNo, int neuronNo, int inputNo, double newWeight)
        {
            Network.Topology.Layers[layerNo].Neurons[neuronNo].Inputs[inputNo].Weight = newWeight;
            Network.PropagateValuesForward(null, layerNo);
            RefreshDgvNeurons();
            MainWindow.ucDialogDgvNeuronsShow.SetControls(dgvNeurons, (int)nudDigits.Value);

            dgvNeurons.Focus();
            TestNetwork();
        }
示例#2
0
        private void BCreateNetwork_Click(object sender, EventArgs e)
        {
            // TODO: ERROR: Un-check "network uses bias" on crete and will be crash!
            // TODO: ERROR: Something is wrong when new network is bigger (I don't think smaller) then current before creating new one.
            if (nudMinWeight.Value > nudMaxWeight.Value)
            {
                MessageBox.Show(this, "Minimum weight is greater than maximum weight!", "Wrong minimum and maximum weight values", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // TODO: EVOLUTION: validation seems to be neccesery! All rows should be fill correctly or should be information about not used rows
            List <LayerCreationInfo> layerCreationInfoList = new List <LayerCreationInfo>();

            for (int row = 0; row < dgvLayers.RowCount; row++)
            {
                if (dgvLayers.Rows[row].Cells["NeuronsQuantity"].Value == null ||
                    dgvLayers.Rows[row].Cells["Function"].Value == null)
                {
                    continue;
                }

                String quantity = dgvLayers.Rows[row].Cells["NeuronsQuantity"].Value.ToString();
                try
                {
                    int intQuantity = Int32.Parse(quantity);

                    if (intQuantity < 1)
                    {
                        MessageBox.Show(this, quantity + " <- this value is a bed idea!", "Wrong value", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    layerCreationInfoList.Add(new LayerCreationInfo()
                    {
                        HowManyNeuronsPerLayer = intQuantity + (cbUsesBiasNeurons.Checked ? 1 : 0),
                        LayerNo = row,
                        LayerActivationFunction   = ActivationFunctionFromRowIdx(row),
                        PreviousLayerNeuronsCount = layerCreationInfoList.Count == 0 ? 0 : layerCreationInfoList.ElementAt(layerCreationInfoList.Count - 1).HowManyNeuronsPerLayer
                    });
                } catch (FormatException)
                {
                    MessageBox.Show(this, quantity + " is not a decimal value!", "Wrong value", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            // last layer has addde redundant bias neuron, need decrease neurons count:
            layerCreationInfoList.Last().HowManyNeuronsPerLayer--;

            if (layerCreationInfoList.Count < 2)
            {
                MessageBox.Show(this, "Network must have at least two layers!", "Need more layers", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            RandomWeight.MinWeight = (double)nudMinWeight.Value;
            RandomWeight.MaxWeight = (double)nudMaxWeight.Value;

            Topology      topology = new Topology(layerCreationInfoList, cbUsesBiasNeurons.Checked);
            NeuralNetwork network  = new NeuralNetwork(
                topology,
                (double)nudMinWeight.Value,
                (double)nudMaxWeight.Value,
                cbLearningMethod.SelectedIndex == 0 ? NeuralNetwork.LearningMethod.NOT_LINEAR : NeuralNetwork.LearningMethod.LINEAR,
                tbName.Text
                );

            network.PropagateValuesForward();

            MainWindow.NotifyNetworkCreated(network);
            this.Visible = false;
        }