Exemplo n.º 1
0
		public Synapse(int inputindex, Neuron target, double weight)
		{
			this.Source = null;
			this.Target = target;
			this.Weight = weight;
			this.LastDiff = 0; 
			this.InputIndex = inputindex;
		}
Exemplo n.º 2
0
		public Synapse(Neuron source, Neuron target, double weight)
		{
			this.Source = source;
			this.Target = target;
			this.Weight = weight;
			this.LastDiff = 0;
			InputIndex = -1;
		}
Exemplo n.º 3
0
 public NeuralLayer(int numNeurons, int inputs, NeuralNetwork net)
 {
     Neurons = new Neuron[numNeurons];
     NumInputs = inputs;
     for(int i = 0; i < numNeurons; i++)
     {
         Neurons[i] = new Neuron(inputs, net);
     }
     //Neurons[0].Debug = true;
 }
Exemplo n.º 4
0
		/// <summary>
		/// Add a neuron to the network.  If a neuron with the same name has
		/// already been added to the network, a <code>DuplicateNeuronException</code>
		/// is thrown.  This need not be the same neuron, but all neurons that
		/// are part of this network must have unique names, with respect to
		/// the network.
		/// </summary>
		/// <param name="neuron">The neuron to add</param>
		private void AddNeuron(Neuron neuron) {
			if(neurons.ContainsKey(neuron.Name)) {
				throw new DuplicateNeuronException("Network already contains " + neuron.Name);
			}
			neurons[neuron.Name] = neuron;
		}
Exemplo n.º 5
0
		/// <summary>
		/// Connect two neurons.  This method is used to
		/// build up connections within the network.  The only connection established
		/// by default is the connection to the bias node.
		/// </summary>
		/// <param name="baseNeuron">A base neuron to connect</param>
		/// <param name="dendrite">A dendrite neuron to connect</param>
		public void Connect(Neuron baseNeuron, Neuron dendrite) {
			Axon axon = new Axon();
			axon.Base = baseNeuron;
			axon.Dendrite = dendrite;
			baseNeuron.AddOutputAxon(axon);
			dendrite.AddInputAxon(axon);
			axons.Add(axon);
		}
Exemplo n.º 6
0
		/// <summary>
		/// Connect a neuron to the bias neuron.
		/// </summary>
		/// <param name="neuron">The bias neuron</param>
		private void ConnectToBias(Neuron neuron) {
			Axon biasAxon = new Axon();
			biasAxon.Base = bias;
			biasAxon.Dendrite = neuron;
			bias.AddOutputAxon(biasAxon);
			neuron.AddInputAxon(biasAxon);
			axons.Add(biasAxon);
		}
Exemplo n.º 7
0
		/// <summary>
		/// Adds a "hidden layer" neuron.  Hidden layers get their inputs from either
		/// input neurons or other hidden layers.  They then pass those values to the
		/// next output or hidden layer.
		/// </summary>
		/// <param name="neuron">The new neuron to add</param>
		public void AddInternalNeuron(Neuron neuron) {
			neuron.ActivationFunction = factory.MakeFunction();
			AddNeuron(neuron);
			ConnectToBias(neuron);
		}
Exemplo n.º 8
0
		/// <summary>
		/// Add input neuron.  Input neurons have their value "set" to a given value
		/// and then propagate that value to any neurons they are connected to.
		/// </summary>
		/// <param name="neuron">The new input neuron</param>
		public void AddInputNeuron(Neuron neuron) {
			AddNeuron(neuron);
			inputNeurons[neuron.Name] = neuron;
		}
Exemplo n.º 9
0
		/// <summary>Add output neuron.</summary>
		/// <param name="neuron">The output neuron</param>
		public void AddOutputNeuron(Neuron neuron) {
			neuron.ActivationFunction = factory.MakeFunction();
			AddNeuron(neuron);
			outputNeurons[neuron.Name] = neuron;
			ConnectToBias(neuron);
		}
Exemplo n.º 10
0
		/// <summary>
		/// Create a new instance of a network.  By default a bias node
		/// is added to the network and automatically connected to any
		/// neurons added to the network (except input neurons).
		/// </summary>
		public Network() {
			bias = new Neuron("Bias neuron");
		}
Exemplo n.º 11
0
 /// <summary>
 /// Adds a "hidden layer" neuron.  Hidden layers get their inputs from either
 /// input neurons or other hidden layers.  They then pass those values to the
 /// next output or hidden layer.
 /// </summary>
 /// <param name="neuron">The new neuron to add</param>
 public void AddInternalNeuron(Neuron neuron)
 {
     neuron.ActivationFunction = factory.MakeFunction();
     AddNeuron(neuron);
     ConnectToBias(neuron);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add input neuron.  Input neurons have their value "set" to a given value
 /// and then propagate that value to any neurons they are connected to.
 /// </summary>
 /// <param name="neuron">The new input neuron</param>
 public void AddInputNeuron(Neuron neuron)
 {
     AddNeuron(neuron);
     inputNeurons[neuron.Name] = neuron;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create a new instance of a network.  By default a bias node
 /// is added to the network and automatically connected to any
 /// neurons added to the network (except input neurons).
 /// </summary>
 public Network()
 {
     bias = new Neuron("Bias neuron");
 }
Exemplo n.º 14
0
 void ProcNeuro(Neuron& n);
Exemplo n.º 15
0
        private void RefreshDgvNeurons()
        {
            if (!DoRefreshDgvNeurons)
            {
                return;
            }

            if (Network.Topology.GetAllNeuronsCount() > 50)
            {
                if (MessageBox.Show(this, "There is more than 50 neurons to show. Are you sure you want to see all neurons with details?", "More than 50 neurons",
                                    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) != DialogResult.OK)
                {
                    cbHideDgvNeurons.Checked = true;
                    return;
                }
            }

            int selectedRowIdx    = -1;
            int selectedColumnIdx = -1;

            if (dgvNeurons.SelectedCells.Count == 1)
            {
                selectedRowIdx    = dgvNeurons.SelectedCells[0].RowIndex;
                selectedColumnIdx = dgvNeurons.SelectedCells[0].ColumnIndex;
            }

            dgvNeurons.Rows.Clear();

            dgvNeurons.Columns[2].Visible = Network.Topology.IsNetworkUsingBiases;

            for (int layerNo = 0; layerNo < Network.Topology.Layers.Count; layerNo++)
            {
                Layer layer = Network.Topology.Layers[layerNo];

                String[] tab = new String[dgvNeurons.ColumnCount];
                tab[0] = (layerNo + 1).ToString();

                for (int neuronNo = 0; neuronNo < layer.Neurons.Count; neuronNo++)
                {
                    Neuron neuron = Network.Topology.Layers[layerNo].Neurons[neuronNo];

                    tab[1] = (neuronNo + 1).ToString();
                    tab[2] = neuron.IsBias ? "yes" : "no";
                    tab[3] = layer.LayerActivationFunction.ToString();

                    int idx = 4;

                    for (int inputNo = 0; inputNo < neuron.Inputs.Count; inputNo++)
                    {
                        if (!neuron.IsBias)
                        {
                            Input input = neuron.Inputs[inputNo];

                            if (layerNo == 0)
                            {
                                tab[idx++] = "none";
                                tab[idx++] = Tools.DoubleToString(input.Value, howManyDigitsShowAfterDotPlaces);
                            }
                            else
                            {
                                tab[idx++] = Tools.DoubleToString(input.Weight, howManyDigitsShowAfterDotPlaces);
                                tab[idx++] = Tools.DoubleToString(input.Value, howManyDigitsShowAfterDotPlaces);
                            }
                        }
                        else
                        {
                            tab[idx++] = "none";
                            tab[idx++] = "none";//"1";
                        }
                    }

                    tab[tab.Length - 1] = Tools.DoubleToString(neuron.GetOutputValue(), howManyDigitsShowAfterDotPlaces);

                    dgvNeurons.Rows.Add(tab);
                }
            }

            if (selectedColumnIdx != -1 && selectedRowIdx != -1)
            {
                dgvNeurons[selectedColumnIdx, selectedRowIdx].Selected = true;
            }
        }