subcluster seems to work
This commit is contained in:
parent
728ef1767c
commit
8a414816e5
21
Cluster.cs
21
Cluster.cs
@ -110,12 +110,12 @@ public class Cluster : INucleus {
|
||||
// Now clone the connections
|
||||
for (int nucleusIx = 0; nucleusIx < nucleiArray.Length; nucleusIx++) {
|
||||
IReceptor receptor = nucleiArray[nucleusIx];
|
||||
IReceptor clonedReceptor = clonedNuclei[nucleusIx];
|
||||
if (clonedReceptor == null)
|
||||
IReceptor clonedSender = clonedNuclei[nucleusIx];
|
||||
if (clonedSender == null)
|
||||
continue;
|
||||
|
||||
// Copy the receivers, which will also create the synapses
|
||||
foreach (INucleus receiver in nucleiArray[nucleusIx].receivers) {
|
||||
foreach (INucleus receiver in receptor.receivers) {
|
||||
int ix = GetNucleusIndex(nucleiArray, receiver);
|
||||
if (ix < 0)
|
||||
continue;
|
||||
@ -123,7 +123,16 @@ public class Cluster : INucleus {
|
||||
if (clonedNuclei[ix] is not INucleus clonedReceiver)
|
||||
continue;
|
||||
|
||||
clonedReceptor.AddReceiver(clonedReceiver);
|
||||
// Find the synapse for the weight
|
||||
float weight = 1;
|
||||
foreach (Synapse synapse in receiver.synapses) {
|
||||
if (synapse.nucleus == receptor) {
|
||||
weight = synapse.weight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
clonedSender.AddReceiver(clonedReceiver, weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -287,9 +296,9 @@ public class Cluster : INucleus {
|
||||
set { _receivers = value; }
|
||||
}
|
||||
|
||||
public virtual void AddReceiver(INucleus receivingNucleus) {
|
||||
public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) {
|
||||
this._receivers.Add(receivingNucleus);
|
||||
receivingNucleus.AddSynapse(this);
|
||||
receivingNucleus.AddSynapse(this, weight);
|
||||
}
|
||||
|
||||
public void RemoveReceiver(INucleus receiverNucleus) {
|
||||
|
||||
@ -33,7 +33,7 @@ public interface IReceptor {
|
||||
// Receivers
|
||||
public List<INucleus> receivers { get; set; }
|
||||
|
||||
public void AddReceiver(INucleus receiver);
|
||||
public void AddReceiver(INucleus receiver, float weight = 1);
|
||||
public void RemoveReceiver(INucleus receiverNucleus);
|
||||
|
||||
#endregion static
|
||||
|
||||
10
Neuron.cs
10
Neuron.cs
@ -181,10 +181,6 @@ public class Neuron : INucleus {
|
||||
// Debug.LogError("No neuroid network");
|
||||
}
|
||||
|
||||
// public Neuron(string name) {
|
||||
// this._name = name;
|
||||
// }
|
||||
|
||||
// this clone the nucleus without the synapses and receivers
|
||||
public virtual IReceptor ShallowCloneTo(Cluster newParent) {
|
||||
Neuron clone = new(newParent, this.name) {
|
||||
@ -246,9 +242,9 @@ public class Neuron : INucleus {
|
||||
return clone;
|
||||
}
|
||||
|
||||
public virtual void AddReceiver(INucleus receivingNucleus) {
|
||||
public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) {
|
||||
this._receivers.Add(receivingNucleus);
|
||||
receivingNucleus.AddSynapse(this);
|
||||
receivingNucleus.AddSynapse(this, weight);
|
||||
}
|
||||
|
||||
public void RemoveReceiver(INucleus receiverNucleus) {
|
||||
@ -294,6 +290,7 @@ public class Neuron : INucleus {
|
||||
float3 sum = inputValue;//new(0, 0, 0);
|
||||
int n = 0;
|
||||
|
||||
Debug.Log($"{this.parent.name}.{this.name}: {inputValue}");
|
||||
//Applying the weight factgors
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
if (synapse.nucleus == this) {
|
||||
@ -301,6 +298,7 @@ public class Neuron : INucleus {
|
||||
synapse.weight = deltaTime;
|
||||
}
|
||||
sum += synapse.weight * synapse.nucleus.outputValue;
|
||||
Debug.Log($" {synapse.weight} * {synapse.nucleus.outputValue}");
|
||||
// Perhaps synapses should be removed when the output value goes to 0....
|
||||
if (lengthsq(synapse.nucleus.outputValue) != 0)
|
||||
n++;
|
||||
|
||||
@ -102,9 +102,9 @@ public class Receptor : IReceptor {
|
||||
|
||||
protected int[] thingIds; // every receiver can handle a thing with this id
|
||||
|
||||
public virtual void AddReceiver(INucleus receivingNucleus) {
|
||||
public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) {
|
||||
this._receivers.Add(receivingNucleus);
|
||||
receivingNucleus.AddSynapse(this);
|
||||
receivingNucleus.AddSynapse(this, weight);
|
||||
}
|
||||
|
||||
public void RemoveReceiver(INucleus receiverNucleus) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user