public void AddConnection(Neuron transmitter, Neuron receptor, float EmphasisIncrease, bool force) { //if (ReferenceEquals(transmitter, receptor) || transmitter == null) if (transmitter == receptor || transmitter == null) { return; } if (transmitter.FireState == FireStates.AutoFire) { return; } if (transmitter.AxonLength < Math.Abs(transmitter.Column - receptor.Column)) { return; } //if (receptor.Rank != transmitter.Rank + 1) // this.LogWarning ("receptor.Rank != transmitter.Rank + 1"); // Suppress connections between InterNeurons if (transmitter.NeuronType == NeuronTypes.Interneuron && receptor.NeuronType == NeuronTypes.Interneuron) { return; } if (transmitter.FireState == FireStates.AutoFire && (receptor.FireState == FireStates.AutoFire || receptor.NeuronType == NeuronTypes.MirrorNeuron)) { return; } /**** * if (transmitter.NeuronType == Neuron.NeuronTypes.Interneuron || receptor.NeuronType == Neuron.NeuronTypes.Interneuron) * EmphasisIncrease *= 0.382f; // golden ratio ***/ Synapse synapse = null; lock (receptor.SyncObject) { foreach (Synapse s in receptor.Synapses) { if (s.Axon == transmitter) { synapse = s; break; } } } // respect circular references if (synapse == null && receptor.ConnectionType == ConnectionTypes.LocalLayer) { lock (transmitter.SyncObject) { foreach (Synapse s in transmitter.Synapses) { if (s.Axon == receptor) { synapse = s; break; } } } } if (synapse == null) { synapse = new Synapse(); synapse.Emphasis = EmphasisIncrease; synapse.Axon = transmitter; if (receptor.AddSynapse(synapse, force)) { lock (transmitter.SyncObject) { transmitter.AxonOutputCount++; } globals.IncreaseTotalEmphasis((double)synapse.Emphasis); globals.IncreaseConnectionCount(); } } else { //lock (synapse.SyncLock) // Don't lock here !! //{ if (globals.MaxEmphasis == 0 || synapse.Emphasis < globals.MaxEmphasis) { float OldEmphasis = synapse.Emphasis; //synapse.Emphasis += EmphasisIncrease; synapse.IncreaseEmphasis(EmphasisIncrease); globals.IncreaseTotalEmphasis((double)(synapse.Emphasis - OldEmphasis)); } //} } }
public bool AddSynapse(Synapse synapse, bool force) { lock (SyncObject) { if (force) { if (MaxSynapses > 0 && Synapses.Count >= MaxSynapses) { return(false); } Synapses.Add(synapse); return(true); } if (MaxSynapses > 0 && m_SynapseAddedThisRound) { return(false); } if (MaxSynapses == 0 || Synapses.Count == 0) { Synapses.Add(synapse); m_SynapseAddedThisRound = true; return(true); } else if (Synapses.Count > MaxSynapses) { return(false); } else { if (m_RequestedConnections.ContainsKey(synapse.Axon.Key)) { int score = m_RequestedConnections[synapse.Axon.Key]; if (score > 100) // 7th contact { Synapses.Add(synapse); m_SynapseAddedThisRound = true; m_RequestedConnections.Clear(); return(true); } else { m_RequestedConnections[synapse.Axon.Key] = score + 40; return(false); } } else { if (m_RequestedConnections.Count > 12) { m_RequestedConnections.Remove(m_RequestedConnections.Keys.Skip(ThreadSafeRandom.Next(11)).First()); } m_RequestedConnections.Add(synapse.Axon.Key, 40); return(false); } } } }
public void Listen() { if (m_NeuronType == NeuronTypes.Perceptron || FireState != FireStates.Idle) { return; } if (m_NeuronType == NeuronTypes.MirrorNeuron && globals.GlobalAwakeness < 0) { return; } lock (SyncObject) { m_SynapseAddedThisRound = false; m_Energy += (1f - m_Energy) * 0.001f; // Original //m_Energy += (1f - m_Energy) * 0.00025f; // Test am 8.1.2014 if (m_Energy > 1f) { m_Energy = 1f; } m_Stimulus -= 0.001f * (m_Stimulus / 10f); //m_Stimulus -= 0.005f * m_Stimulus; if (m_Stimulus < 0.001f) { m_Stimulus = 0.001f; } float input = 0; // much slower than below //input = Synapses.Sum(s => s.Axon.AxonOutput * s.Emphasis * (1f - m_Excitement)); //foreach (Synapse synapse in Synapses) for (int i = 0; i < Synapses.Count; i++) { Synapse synapse = Synapses [i]; input += synapse.Axon.AxonOutput * synapse.Emphasis * (1f - m_Excitement); } /*** * if (this.m_NeuronType == NeuronTypes.Interneuron) * { * if (Threshold < 1f) * Threshold = 1f; * } * else * { * if (Threshold < globals.GlobalThreshold) * Threshold = globals.GlobalThreshold; * } ***/ if (Threshold < globals.GlobalThreshold) { Threshold = globals.GlobalThreshold; } /*** * if (input > 0) { * int iTest = Rank; * } ***/ if (input >= Threshold) { // too noisy here ? I'm quiet if (input > Threshold * 3f) { Threshold *= 1.5f; return; } Threshold = input + 0.1f + (float)(ThreadSafeRandom.NextDouble() / 10.0); InvokeFireInternal(0.01f); } else { // Adjust Threshold //m_Threshold -= 0.001f; //m_Threshold -= 0.0025f; // 15. Dezember 2015: release 2.5 times faster //Threshold -= 0.01f; // 15. Dezember 2015: release 2.5 times faster //Threshold -= 0.1f; // Jul 2016: release 10 times faster //Threshold -= Threshold * 0.05f; // Jul 2016: release 10 times faster /*** * if (this.m_NeuronType == NeuronTypes.Interneuron) * { * if (Threshold < 1f) * Threshold = 1f; * } * else * { * if (Threshold < globals.GlobalThreshold) * Threshold = globals.GlobalThreshold; * } ***/ Threshold = Math.Max(globals.GlobalThreshold, Threshold - (Threshold * 0.05f)); //m_Excitement -= 0.001f * m_Excitement; ////m_Excitement -= 0.005f * m_Excitement; //if (m_Excitement < 0f) // m_Excitement = 0f; // ******* ORIGINAL ******** //if (m_FireState == FireStates.fire) // m_Excitement -= 0.00025f * m_Excitement; //else // m_Excitement = 0f; //switch (m_FireState) //{ // case FireStates.idle: // //m_Excitement -= 0.005f * m_Excitement; // m_Excitement = 0f; // break; // case FireStates.fire: // // Do nothing, we rise up excitement // // or lower just a little to distinct from others // m_Excitement -= 0.00025f * m_Excitement; // break; // case FireStates.autofire: // m_Excitement = 0f; // break; //} switch (FireState) { case FireStates.Idle: m_Excitement -= 0.005f * m_Excitement; break; case FireStates.Fire: // Do nothing, we rise up excitement // or lower just a little to distinct from others m_Excitement -= 0.00025f * m_Excitement; break; case FireStates.AutoFire: m_Excitement = 0f; break; } if (m_Excitement < 0f) { m_Excitement = 0f; } // No Autofire for Interneurons // When dreaming if (!globals.IsAwake) { //if (m_Energy > 0.1 && this.m_NeuronType == NeuronTypes.PyramidCell && FireState == FireStates.idle) if (m_Energy > 0.1 && FireState == FireStates.Idle) { // For empty still unassigned neurons //if (Synapses.Count < 24) if (Synapses.Count < 6) { //if (Synapses.Count < 12) m_Stimulus = 0.01f; } double r = ThreadSafeRandom.NextDouble() * 1000.0; if ((m_Energy / (float)globals.CachedNeuronCount) + (m_Energy * m_Stimulus * globals.AutoFireFactor) > r) // war *100 { DoAutoFireInternal(); } } } } } }
public bool AddSynapse(Synapse synapse) { return(AddSynapse(synapse, false)); }