Fix aging of neurons
This commit is contained in:
parent
e2e169ca60
commit
c8f0f0c9da
@ -382,14 +382,21 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
// Otherwise find the stalest cluster?
|
||||
Cluster stalestCluster = this.siblingClusters[0];
|
||||
// Cluster stalestCluster = this.siblingClusters[0];
|
||||
// for (int ix = 1; ix < this.siblingClusters.Length; ix++) {
|
||||
// if (this.siblingClusters[ix].defaultOutput.stale > stalestCluster.defaultOutput.stale)
|
||||
// stalestCluster = this.siblingClusters[ix];
|
||||
// }
|
||||
|
||||
// Otherwise find longest unused cluster
|
||||
Cluster unusedCluster = this.siblingClusters[0];
|
||||
for (int ix = 1; ix < this.siblingClusters.Length; ix++) {
|
||||
if (this.siblingClusters[ix].defaultOutput.stale > stalestCluster.defaultOutput.stale)
|
||||
stalestCluster = this.siblingClusters[ix];
|
||||
if (this.siblingClusters[ix].defaultOutput.lastUpdate < unusedCluster.defaultOutput.lastUpdate)
|
||||
unusedCluster = this.siblingClusters[ix];
|
||||
}
|
||||
|
||||
RemoveThingCluster(stalestCluster);
|
||||
return stalestCluster;
|
||||
RemoveThingCluster(unusedCluster);
|
||||
return unusedCluster;
|
||||
}
|
||||
|
||||
private void RemoveThingCluster(Cluster cluster) {
|
||||
|
||||
@ -213,11 +213,23 @@ namespace NanoBrain {
|
||||
public Action WhenFiring;
|
||||
|
||||
|
||||
public virtual bool isSleeping => this.outputMagnitude == 0;
|
||||
public virtual bool isSleeping => Time.time - this.lastUpdate > this.timeToSleep; //this.outputMagnitude == 0;
|
||||
public void SleepCheck() {
|
||||
if (this.isSleeping) {
|
||||
#if UNITY_MATHEMATICS
|
||||
this.bias = new float3(0, 0, 0);
|
||||
#else
|
||||
this.bias = new Vector3(0,0,0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// [NonSerialized]
|
||||
// public int stale = 1000;
|
||||
[NonSerialized]
|
||||
public int stale = 1000;
|
||||
public readonly int staleValueForSleep = 20;
|
||||
public float lastUpdate = 0;
|
||||
// public readonly int staleValueForSleep = 20;
|
||||
public readonly float timeToSleep = 1f;
|
||||
|
||||
/// \copydoc NanoBrain::Nucleus::ShallowCloneTo
|
||||
public override Nucleus ShallowCloneTo(Cluster newParent) {
|
||||
@ -288,8 +300,18 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
public override void UpdateStateIsolated() {
|
||||
CheckSleepingSynapses();
|
||||
var result = Combinator();
|
||||
this.outputValue = Activator(result);
|
||||
this.lastUpdate = Time.time;
|
||||
}
|
||||
|
||||
protected void CheckSleepingSynapses() {
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
if (synapse.isSleeping) {
|
||||
synapse.neuron.outputValue = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Combinator
|
||||
@ -524,7 +546,8 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
public void ProcessStimulusDirect(Vector3 inputValue) { //}, int thingId = 0, string thingName = null) {
|
||||
this.stale = 0;
|
||||
// this.stale = 0;
|
||||
this.lastUpdate = Time.time;
|
||||
this.bias = inputValue;
|
||||
this.parent.UpdateFromNucleus(this);
|
||||
}
|
||||
|
||||
@ -28,6 +28,12 @@ namespace NanoBrain {
|
||||
this.neuron = nucleus;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public bool isSleeping {
|
||||
get {
|
||||
return this.neuron.isSleeping;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user