bef7ee2 Made Unity.Mathematics optional git-subtree-dir: NanoBrain git-subtree-split: bef7ee24e549963b5cabfb91ada9289bc6dddbe0
94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
using UnityEngine;
|
|
#if UNITY_MATHEMATICS
|
|
using Unity.Mathematics;
|
|
using static Unity.Mathematics.math;
|
|
#endif
|
|
|
|
[System.Serializable]
|
|
public class Receptor : Neuron, IReceptor {
|
|
public Receptor(Cluster parent, string name) : base(parent, name) {
|
|
this.array = new NucleusArray(this);
|
|
if (this.name.IndexOf(":") < 0)
|
|
this.name += ": 0";
|
|
}
|
|
public Receptor(ClusterPrefab prefab, string name) : base(prefab, name) {
|
|
this.array = new NucleusArray(this);
|
|
}
|
|
|
|
public string GetName() {
|
|
return this.name;
|
|
}
|
|
|
|
public override Nucleus ShallowCloneTo(Cluster parent) {
|
|
Receptor clone = new(parent, name) {
|
|
|
|
};
|
|
CloneFields(clone);
|
|
return clone;
|
|
}
|
|
public override Nucleus Clone(ClusterPrefab prefab) {
|
|
Receptor clone = new(prefab, name) {
|
|
array = this._array
|
|
};
|
|
CloneFields(clone);
|
|
// Adding receivers will also add synapses to the receivers
|
|
foreach (Nucleus receiver in this.receivers.ToArray())
|
|
clone.AddReceiver(receiver);
|
|
|
|
return clone;
|
|
}
|
|
|
|
[SerializeReference]
|
|
private NucleusArray _array;
|
|
public NucleusArray array {
|
|
set { _array = value; }
|
|
}
|
|
|
|
public Nucleus[] nucleiArray {
|
|
get { return _array.nuclei; }
|
|
set { _array.nuclei = value; }
|
|
}
|
|
|
|
public void AddReceptorElement(ClusterPrefab prefab) {
|
|
IReceptorHelpers.AddReceptorElement(this, prefab);
|
|
}
|
|
|
|
public void RemoveReceptorElement() {
|
|
IReceptorHelpers.RemoveReceptorElement(this);
|
|
}
|
|
|
|
public virtual void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) {
|
|
IReceptorHelpers.AddArrayReceiver(this, receiverToAdd, weight);
|
|
}
|
|
|
|
public override void UpdateStateIsolated() {
|
|
this.outputValue = this.bias;
|
|
}
|
|
|
|
#if UNITY_MATHEMATICS
|
|
|
|
public override void UpdateNuclei() {
|
|
this.stale++;
|
|
if (this.stale > staleValueForSleep && lengthsq(this.bias) > 0) {
|
|
this.bias = new float3(0, 0, 0);
|
|
this.parent.UpdateFromNucleus(this);
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
public override void UpdateNuclei() {
|
|
this.stale++;
|
|
if (this.stale > staleValueForSleep && this.bias.sqrMagnitude > 0) {
|
|
this.bias = new Vector3(0, 0, 0);
|
|
this.parent.UpdateFromNucleus(this);
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|
|
public override void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) {
|
|
this._array ??= new NucleusArray(this.parent);
|
|
this._array.ProcessStimulus(thingId, inputValue, thingName);
|
|
}
|
|
} |