NanoBrain-unitypackage/MemoryCell.cs
Pascal Serrarens 9fcbaa5bf8 Squashed 'NanoBrain/' changes from b3423b9..bef7ee2
bef7ee2 Made Unity.Mathematics optional

git-subtree-dir: NanoBrain
git-subtree-split: bef7ee24e549963b5cabfb91ada9289bc6dddbe0
2026-04-07 14:07:27 +02:00

66 lines
1.7 KiB
C#

using System;
#if UNITY_MATHEMATICS
using Unity.Mathematics;
#endif
[Serializable]
public class MemoryCell : Neuron {
public MemoryCell(ClusterPrefab cluster, string name) : base(cluster, name) { }
public MemoryCell(Cluster parent, string name) : base(parent, name) { }
public bool staticMemory = false;
public override bool isSleeping {
get {
if (staticMemory)
return false;
return base.isSleeping;
}
}
public override Nucleus ShallowCloneTo(Cluster newParent) {
MemoryCell clone = new(newParent, this.name);
CloneFields(clone);
clone.staticMemory = this.staticMemory;
return clone;
}
#region State
private bool initialized = false;
#if UNITY_MATHEMATICS
private float3 _memorizedValue;
#else
private UnityEngine.Vector3 _memorizedValue;
#endif
public override void UpdateStateIsolated() {
// A memorycell does not have an activation function
var result = Combinator();
if (initialized)
// Output the previous, memorized value
this.outputValue = this._memorizedValue;
else {
// The first time, the result is directly set in output
this.outputValue = result;
this.initialized = true;
}
// Store the result for the next time
this._memorizedValue = result;
}
public override void UpdateNuclei() {
if (staticMemory)
// Static memory does not get stale or go to sleep
return;
base.UpdateNuclei();
}
#endregion State
}