Cleanup old sleep

This commit is contained in:
Pascal Serrarens 2026-08-14 17:01:25 +02:00
parent a55e899c68
commit 68b43ee476
2 changed files with 21 additions and 21 deletions

View File

@ -121,7 +121,7 @@ namespace NanoBrain {
/// <param name="inputValue"></param> /// <param name="inputValue"></param>
public virtual void SetBias(Vector3 inputValue) { public virtual void SetBias(Vector3 inputValue) {
this.bias = inputValue; this.bias = inputValue;
this.lastUpdate = Time.time; // this.lastUpdate = Time.time;
this.parent?.UpdateFromNucleus(this); this.parent?.UpdateFromNucleus(this);
} }
@ -251,30 +251,30 @@ namespace NanoBrain {
/// <summary> /// <summary>
/// True when the neuron is not persisting and has not be updated for timeToSleep seconds /// True when the neuron is not persisting and has not be updated for timeToSleep seconds
/// </summary> /// </summary>
public virtual bool isSleeping => false; //!persistOutput && (Time.time - this.lastUpdate > timeToSleep); //public virtual bool isSleeping => false; //!persistOutput && (Time.time - this.lastUpdate > timeToSleep);
/// <summary> /// <summary>
/// Check if the neuron is sleeping. /// Check if the neuron is sleeping.
/// </summary> /// </summary>
/// This will reset the output value if it is sleeping /// This will reset the output value if it is sleeping
public void SleepCheck() { // public void SleepCheck() {
if (this.isSleeping && this.outputSqrMagnitude > 0) { // if (this.isSleeping && this.outputSqrMagnitude > 0) {
#if UNITY_MATHEMATICS // #if UNITY_MATHEMATICS
this._outputValue = new float3(0, 0, 0); // this._outputValue = new float3(0, 0, 0);
#else // #else
this._outputValue = new Vector3(0,0,0); // this._outputValue = new Vector3(0,0,0);
#endif // #endif
} // }
} // }
/// <summary> /// <summary>
/// The time at which the last update has been done /// The time at which the last update has been done
/// </summary> /// </summary>
[HideInInspector] // [HideInInspector]
public float lastUpdate = 0; // public float lastUpdate = 0;
/// <summary> /// <summary>
/// Time in seconds after the last update the neuron can go to sleep /// Time in seconds after the last update the neuron can go to sleep
/// </summary> /// </summary>
public static readonly float timeToSleep = 0.5f; // public static readonly float timeToSleep = 0.5f;
/// <summary> /// <summary>
/// When true, Unity will pause exection when this neuron is updated /// When true, Unity will pause exection when this neuron is updated
@ -402,7 +402,7 @@ namespace NanoBrain {
} }
this.combination = Combinator(this.bias, this.synapses); this.combination = Combinator(this.bias, this.synapses);
this.outputValue = Activator(this.combination); this.outputValue = Activator(this.combination);
this.lastUpdate = Time.time; // this.lastUpdate = Time.time;
} }
#region Combinator #region Combinator
@ -437,8 +437,8 @@ namespace NanoBrain {
public static float3 CombinatorSum(float3 bias, List<Synapse> synapses) { public static float3 CombinatorSum(float3 bias, List<Synapse> synapses) {
float3 sum = bias; float3 sum = bias;
foreach (Synapse synapse in synapses) { foreach (Synapse synapse in synapses) {
synapse.neuron.SleepCheck(); // synapse.neuron.SleepCheck();
sum += synapse.weight * synapse.neuron.outputValue; sum += synapse.weight * synapse.neuron._outputValue;
} }
return sum; return sum;
} }
@ -452,8 +452,8 @@ namespace NanoBrain {
public static float3 CombinatorProduct(float3 bias, List<Synapse> synapses) { public static float3 CombinatorProduct(float3 bias, List<Synapse> synapses) {
float3 product = bias; float3 product = bias;
foreach (Synapse synapse in synapses) { foreach (Synapse synapse in synapses) {
synapse.neuron.SleepCheck(); // synapse.neuron.SleepCheck();
product *= synapse.weight * synapse.neuron.outputValue; product *= synapse.weight * synapse.neuron._outputValue;
} }
return product; return product;
} }
@ -798,7 +798,7 @@ namespace NanoBrain {
/// </summary> /// </summary>
/// <param name="inputValue">The value of the stimulus</param> /// <param name="inputValue">The value of the stimulus</param>
public virtual void ProcessStimulus(Vector3 inputValue, float autoResetDelay = 0) { public virtual void ProcessStimulus(Vector3 inputValue, float autoResetDelay = 0) {
this.lastUpdate = Time.time; // this.lastUpdate = Time.time;
this.bias = inputValue; this.bias = inputValue;
this.parent?.UpdateFromNucleus(this); this.parent?.UpdateFromNucleus(this);
this.resetStimulus ??= ResetStimulus; this.resetStimulus ??= ResetStimulus;

View File

@ -88,7 +88,7 @@ namespace NanoBrain {
member.brain.CopyWeightsFrom(ants[parent1].brain); member.brain.CopyWeightsFrom(ants[parent1].brain);
member.brain.ProcessWeightsFrom(ants[parent2].brain, Average); member.brain.ProcessWeightsFrom(ants[parent2].brain, Average);
// LogTrainableWeights(member.brain); // LogTrainableWeights(member.brain);
member.brain.GaussianAdditiveMutation(1e-1f); member.brain.GaussianAdditiveMutation(1e-2f);
// LogTrainableWeights(member.brain); // LogTrainableWeights(member.brain);
} }