using System; using UnityEngine; using Unity.Mathematics; using static Unity.Mathematics.math; [Serializable] public class MemoryCell : Neuron { public MemoryCell(ClusterPrefab cluster, string name) : base(cluster, name) { } public MemoryCell(Cluster parent, string name) : base(parent, name) { } public override Nucleus ShallowCloneTo(Cluster newParent) { MemoryCell clone = new(newParent, this.name) { array = this.array, curve = this.curve, curvePreset = this.curvePreset, curveMax = this.curveMax, average = this.average }; return clone; } #region State private float3 _memorizedValue; private float _memorizedTime; public override void UpdateStateIsolated() { float3 bias = new(0, 0, 0); UpdateStateIsolated(bias); } public override void UpdateStateIsolated(float3 bias) { // A memorycell does not have an activation function float3 result = bias; int n = 0; //Applying the weight factgors foreach (Synapse synapse in this.synapses) { result += synapse.weight * synapse.nucleus.outputValue; if (lengthsq(synapse.nucleus.outputValue) != 0) n++; } if (this.average) result /= n; this.outputValue = this._memorizedValue; // Store the result for the next time this._memorizedValue = result; this._memorizedTime = Time.time; } #endregion State }