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

View File

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