NanoBrain-unitypackage/MemoryCell.cs

62 lines
1.7 KiB
C#

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) {}
#region Parameters
// Returns the memorized value weighted by time
// return lastValue * (current time - last time)
// [SerializeField]
// public bool deltaValue = false;
#endregion Parameters
#region State
private float3 _memorizedValue;
private float _memorizedTime;
public override void UpdateState() {
// A memorycell does not have an activation function
float3 result = new(0, 0, 0);
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;
UpdateResult(result);
}
public override void UpdateResult(Vector3 result) {
// output value is the previous value
// if (this.deltaValue) {
// float deltaTime = Time.time - this._memorizedTime;
// this._outputValue = this._memorizedValue * deltaTime;
// }
//else
this.outputValue = this._memorizedValue;
// Store the result for the next time
this._memorizedValue = result;
this._memorizedTime = Time.time;
foreach (INucleus receiver in this.receivers)
receiver.UpdateState();
}
#endregion State
}