Switching from INucleus to Nucleus
This commit is contained in:
parent
d48475b483
commit
351f242f2e
108
Cluster.cs
108
Cluster.cs
@ -6,15 +6,15 @@ using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Serializable]
|
||||
public class Cluster : INucleus {
|
||||
public class Cluster : Nucleus {
|
||||
// The ScriptableObject asset from which the runtime object has been created
|
||||
|
||||
[SerializeField]
|
||||
protected string _name;
|
||||
public virtual string name {
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
// [SerializeField]
|
||||
// protected string _name;
|
||||
// public virtual string name {
|
||||
// get => _name;
|
||||
// set => _name = value;
|
||||
// }
|
||||
|
||||
#region Init
|
||||
|
||||
@ -146,7 +146,7 @@ public class Cluster : INucleus {
|
||||
return sortedOrder;
|
||||
}
|
||||
|
||||
public virtual INucleus Clone() {
|
||||
public override INucleus Clone() {
|
||||
//Neuron clone = new(this.cluster, this.name) {
|
||||
Neuron clone = new(this.parent, this.name) {
|
||||
array = this.array,
|
||||
@ -162,7 +162,7 @@ public class Cluster : INucleus {
|
||||
return clone;
|
||||
}
|
||||
|
||||
public INucleus ShallowCloneTo(Cluster parent) {
|
||||
public override INucleus ShallowCloneTo(Cluster parent) {
|
||||
Cluster clone = new(this.prefab, parent) {
|
||||
name = this.name,
|
||||
};
|
||||
@ -181,8 +181,8 @@ public class Cluster : INucleus {
|
||||
|
||||
public ClusterPrefab prefab;
|
||||
|
||||
public ClusterPrefab cluster { get; set; }
|
||||
public Cluster parent { get; set; }
|
||||
// public ClusterPrefab cluster { get; set; }
|
||||
// public Cluster parent { get; set; }
|
||||
|
||||
[SerializeReference]
|
||||
public List<INucleus> nuclei = new();
|
||||
@ -216,12 +216,12 @@ public class Cluster : INucleus {
|
||||
}
|
||||
|
||||
// Not sure if this belongs here...
|
||||
[SerializeReference]
|
||||
private NucleusArray _array;
|
||||
public NucleusArray array {
|
||||
get { return _array; }
|
||||
set { _array = value; }
|
||||
}
|
||||
// [SerializeReference]
|
||||
// private NucleusArray _array;
|
||||
// public NucleusArray array {
|
||||
// get { return _array; }
|
||||
// set { _array = value; }
|
||||
// }
|
||||
|
||||
public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) {
|
||||
foreach (INucleus receptor in this.nuclei) {
|
||||
@ -246,15 +246,15 @@ public class Cluster : INucleus {
|
||||
|
||||
#region Synapses
|
||||
|
||||
[SerializeField]
|
||||
private List<Synapse> _synapses = new();
|
||||
public List<Synapse> synapses => _synapses;
|
||||
// [SerializeField]
|
||||
// private List<Synapse> _synapses = new();
|
||||
// public List<Synapse> synapses => _synapses;
|
||||
|
||||
public Synapse AddSynapse(INucleus sendingNucleus, float weight = 1.0f) {
|
||||
Synapse synapse = new(sendingNucleus, weight);
|
||||
this._synapses.Add(synapse);
|
||||
return synapse;
|
||||
}
|
||||
// public Synapse AddSynapse(INucleus sendingNucleus, float weight = 1.0f) {
|
||||
// Synapse synapse = new(sendingNucleus, weight);
|
||||
// this._synapses.Add(synapse);
|
||||
// return synapse;
|
||||
// }
|
||||
|
||||
// Does this even exist already?
|
||||
public void RemoveSynapse() {
|
||||
@ -265,40 +265,40 @@ public class Cluster : INucleus {
|
||||
|
||||
#region Receivers
|
||||
|
||||
[SerializeReference]
|
||||
private List<INucleus> _receivers = new();
|
||||
public List<INucleus> receivers {
|
||||
get { return _receivers; }
|
||||
set { _receivers = value; }
|
||||
}
|
||||
// [SerializeReference]
|
||||
// private List<INucleus> _receivers = new();
|
||||
// public List<INucleus> receivers {
|
||||
// get { return _receivers; }
|
||||
// set { _receivers = value; }
|
||||
// }
|
||||
|
||||
public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) {
|
||||
this._receivers.Add(receivingNucleus);
|
||||
receivingNucleus.AddSynapse(this, weight);
|
||||
}
|
||||
// public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) {
|
||||
// this._receivers.Add(receivingNucleus);
|
||||
// receivingNucleus.AddSynapse(this, weight);
|
||||
// }
|
||||
|
||||
public void RemoveReceiver(INucleus receiverNucleus) {
|
||||
this._receivers.RemoveAll(receiver => receiver == receiverNucleus);
|
||||
receiverNucleus.synapses.RemoveAll(synapse => synapse.nucleus == this);
|
||||
}
|
||||
// public void RemoveReceiver(INucleus receiverNucleus) {
|
||||
// this._receivers.RemoveAll(receiver => receiver == receiverNucleus);
|
||||
// receiverNucleus.synapses.RemoveAll(synapse => synapse.nucleus == this);
|
||||
// }
|
||||
|
||||
#endregion Receivers
|
||||
|
||||
#region Runtime
|
||||
|
||||
[NonSerialized]
|
||||
private int stale = 1000;
|
||||
public bool isSleeping => lengthsq(this.outputValue) == 0;
|
||||
// [NonSerialized]
|
||||
// private int stale = 1000;
|
||||
// public bool isSleeping => lengthsq(this.outputValue) == 0;
|
||||
|
||||
[NonSerialized]
|
||||
protected float3 _outputValue;
|
||||
public virtual float3 outputValue {
|
||||
get { return _outputValue; }
|
||||
set {
|
||||
this.stale = 0;
|
||||
_outputValue = value;
|
||||
}
|
||||
}
|
||||
// [NonSerialized]
|
||||
// protected float3 _outputValue;
|
||||
// public virtual float3 outputValue {
|
||||
// get { return _outputValue; }
|
||||
// set {
|
||||
// this.stale = 0;
|
||||
// _outputValue = value;
|
||||
// }
|
||||
// }
|
||||
|
||||
#region Update
|
||||
|
||||
@ -324,11 +324,11 @@ public class Cluster : INucleus {
|
||||
// UpdateResult(this.output.outputValue);
|
||||
// }
|
||||
|
||||
public void UpdateStateIsolated() {
|
||||
public override void UpdateStateIsolated() {
|
||||
float3 bias = new(0, 0, 0);
|
||||
UpdateStateIsolated(bias);
|
||||
}
|
||||
public void UpdateStateIsolated(float3 bias) {
|
||||
public override void UpdateStateIsolated(float3 bias) {
|
||||
float3 sum = bias; // new(0, 0, 0);
|
||||
|
||||
//Applying the weight factors
|
||||
@ -364,7 +364,7 @@ public class Cluster : INucleus {
|
||||
// receiver.UpdateState();
|
||||
// }
|
||||
|
||||
public void UpdateNuclei() {
|
||||
public override void UpdateNuclei() {
|
||||
this.stale++;
|
||||
if (this.stale > 5)
|
||||
_outputValue = Vector3.zero;
|
||||
|
||||
@ -4,7 +4,7 @@ using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Serializable]
|
||||
public class MemoryCell : Neuron, INucleus {
|
||||
public class MemoryCell : Neuron {
|
||||
|
||||
public MemoryCell(ClusterPrefab cluster, string name) : base(cluster, name) { }
|
||||
public MemoryCell(Cluster parent, string name) : base(parent, name) { }
|
||||
|
||||
@ -7,7 +7,7 @@ using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Serializable]
|
||||
public class Neuron : Nucleus, INucleus {
|
||||
public class Neuron : Nucleus {
|
||||
|
||||
public Neuron(Cluster parent, string name) {
|
||||
this.parent = parent;
|
||||
@ -351,7 +351,7 @@ public class Neuron : Nucleus, INucleus {
|
||||
public virtual void ProcessStimulus(Vector3 inputValue, string thingName = null) {
|
||||
//this.outputValue = inputValue;
|
||||
this.stale = 0;
|
||||
Debug.Log($"{this.name} processed stimulus");
|
||||
//Debug.Log($"{this.name} processed stimulus");
|
||||
this.bias = inputValue;
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ public abstract class Nucleus : INucleus {
|
||||
public virtual void UpdateStateIsolated(float3 bias) {
|
||||
}
|
||||
|
||||
public void UpdateNuclei() {
|
||||
public virtual void UpdateNuclei() {
|
||||
this.stale++;
|
||||
if (this.stale > 5) {
|
||||
//Debug.Log($"{this.name} goes to sleep, stale = {this.stale}");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user