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