Fix produced json
This commit is contained in:
parent
5553f8994f
commit
e96347a7b2
@ -372,11 +372,11 @@ namespace NanoBrain {
|
||||
}
|
||||
}
|
||||
|
||||
public Cluster Clone() {
|
||||
public Cluster Copy() {
|
||||
Cluster clone = new() {
|
||||
name = this.name,
|
||||
prefab = this.prefab,
|
||||
version = this.version,
|
||||
version = this.version,
|
||||
parent = this.parent
|
||||
};
|
||||
if (clone.parent != null) {
|
||||
@ -386,7 +386,7 @@ namespace NanoBrain {
|
||||
// first clone the nuclei without their connections
|
||||
foreach (Nucleus nucleus in this.nuclei)
|
||||
nucleus.ShallowCloneTo(clone);
|
||||
|
||||
|
||||
Nucleus[] clonedNuclei = clone.nuclei.ToArray();
|
||||
// Now clone the connections
|
||||
for (int nucleusIx = 0; nucleusIx < this.nuclei.Count; nucleusIx++) {
|
||||
@ -403,8 +403,9 @@ namespace NanoBrain {
|
||||
if (synapseNeuron.parent.prefab != null && synapseNeuron.parent.prefab != clone.prefab) {
|
||||
// Neuron is in another cluster, find the cloned cluster first
|
||||
Cluster sourceCluster = synapseNeuron.parent;
|
||||
Cluster clonedCluster = clone.nuclei.Find(n => n.name == sourceCluster.name) as Cluster;
|
||||
if (clonedCluster == null)
|
||||
//Cluster clonedCluster = clone.nuclei.Find(n => n.name == sourceCluster.name) as Cluster;
|
||||
Nucleus clonedClusterNucleus = clone.nuclei.Find(n => n.name == sourceCluster.name);
|
||||
if (clonedClusterNucleus is not Cluster clonedCluster)
|
||||
continue;
|
||||
|
||||
// Now find the neuron in that cloned cluster
|
||||
@ -433,26 +434,6 @@ namespace NanoBrain {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Nucleus clonedNucleus in clonedNuclei) {
|
||||
if (clonedNucleus is not Cluster clonedCluster)
|
||||
continue;
|
||||
|
||||
List<Cluster> siblings = new() { clonedCluster };
|
||||
for (int instanceIx = 1; instanceIx < clonedCluster.instanceCount; instanceIx++) {
|
||||
// Create another sibling
|
||||
Cluster sibling = new(clonedCluster.prefab, this) {
|
||||
name = $"{clonedCluster.baseName}: {instanceIx}",
|
||||
parent = clone.parent,
|
||||
instanceCount = clone.instanceCount,
|
||||
};
|
||||
siblings.Add(sibling);
|
||||
CopyAllExternalReceivers(clonedCluster, sibling, this);
|
||||
}
|
||||
Cluster[] siblingClusters = siblings.ToArray();
|
||||
foreach (Cluster sibling in siblings)
|
||||
sibling.instances = siblingClusters;
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
@ -512,8 +493,8 @@ namespace NanoBrain {
|
||||
public static int GetNucleusIndex(List<Nucleus> nuclei, Nucleus nucleus) {
|
||||
int i = 0;
|
||||
foreach (Nucleus nucleiElement in nuclei) {
|
||||
//for (int i = 0; i < nuclei.Length; i++) {
|
||||
if (nucleiElement == nucleus)
|
||||
// if (nucleiElement == nucleus)
|
||||
if (nucleiElement.name == nucleus.name)
|
||||
return i;
|
||||
i++;
|
||||
}
|
||||
@ -1124,20 +1105,20 @@ namespace NanoBrain {
|
||||
public ClusterData(Cluster cluster) {
|
||||
this.name = cluster.name;
|
||||
foreach (Nucleus nucleus in cluster.nuclei) {
|
||||
if (nucleus is Neuron neuron) {
|
||||
NeuronData neuronData = new(neuron);
|
||||
this.neurons.Add(neuronData);
|
||||
foreach (Synapse synapse in neuron.synapses) {
|
||||
if (synapse.neuron.parent.name != cluster.name) {
|
||||
ExternalClusterData clusterData = new(synapse.neuron.parent);
|
||||
if (GetCluster(clusterData.name) == null) {
|
||||
//if (this.clusters.Find(data => data.name == clusterData.name) == null) {
|
||||
this.clusters.Add(clusterData);
|
||||
//Debug.Log("Add cluster");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nucleus is not Neuron neuron)
|
||||
continue;
|
||||
|
||||
NeuronData neuronData = new(neuron);
|
||||
this.neurons.Add(neuronData);
|
||||
foreach (Synapse synapse in neuron.synapses) {
|
||||
if (synapse.neuron.parent.baseName == cluster.name)
|
||||
continue;
|
||||
|
||||
ExternalClusterData clusterData = new(synapse.neuron.parent);
|
||||
if (GetCluster(clusterData.name) == null)
|
||||
this.clusters.Add(clusterData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1157,7 +1138,7 @@ namespace NanoBrain {
|
||||
public uint instanceCount;
|
||||
|
||||
public ExternalClusterData(Cluster cluster) {
|
||||
this.name = cluster.name;
|
||||
this.name = cluster.baseName;
|
||||
this.prefabName = cluster.prefab.name;
|
||||
this.instanceCount = (uint)cluster.instanceCount;
|
||||
}
|
||||
|
||||
@ -256,15 +256,15 @@ namespace NanoBrain {
|
||||
/// Check if the neuron is sleeping.
|
||||
/// </summary>
|
||||
/// This will reset the output value if it is sleeping
|
||||
// public void SleepCheck() {
|
||||
// if (this.isSleeping && this.outputSqrMagnitude > 0) {
|
||||
// #if UNITY_MATHEMATICS
|
||||
// this._outputValue = new float3(0, 0, 0);
|
||||
// #else
|
||||
// this._outputValue = new Vector3(0,0,0);
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
// public void SleepCheck() {
|
||||
// if (this.isSleeping && this.outputSqrMagnitude > 0) {
|
||||
// #if UNITY_MATHEMATICS
|
||||
// this._outputValue = new float3(0, 0, 0);
|
||||
// #else
|
||||
// this._outputValue = new Vector3(0,0,0);
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// The time at which the last update has been done
|
||||
@ -791,7 +791,7 @@ namespace NanoBrain {
|
||||
#endregion Back propagation
|
||||
|
||||
private CancellationTokenSource _cts;
|
||||
private Action resetStimulus;
|
||||
private Action resetStimulus;
|
||||
|
||||
/// <summary>
|
||||
/// Process an external stimulus
|
||||
@ -806,7 +806,7 @@ namespace NanoBrain {
|
||||
if (autoResetDelay > 0) {
|
||||
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
long resetTime = now + (long)(autoResetDelay * 1000.0f);
|
||||
Cluster.TimedAction.AddTo(this.parent.actions, this.parent.name + "." +this.name, this.resetStimulus, resetTime);
|
||||
Cluster.TimedAction.AddTo(this.parent.actions, this.parent.name + "." + this.name, this.resetStimulus, resetTime);
|
||||
}
|
||||
}
|
||||
|
||||
@ -839,6 +839,11 @@ namespace NanoBrain {
|
||||
this.activationType = neuron.activator;
|
||||
|
||||
foreach (Synapse synapse in neuron.synapses) {
|
||||
// Check whether synapse exists already first
|
||||
if (this.synapses.Find(s => s.neuronName == synapse.neuron.name) != null)
|
||||
// But then: what to do with the weights???? :-)
|
||||
continue;
|
||||
|
||||
SynapseData synapseData = new(synapse);
|
||||
this.synapses.Add(synapseData);
|
||||
}
|
||||
|
||||
@ -55,11 +55,11 @@ namespace NanoBrain {
|
||||
if (members.Count <= 0)
|
||||
return null;
|
||||
|
||||
Cluster result = members[0].brain.Clone();
|
||||
for (int memberIx = 1; memberIx < members.Count; memberIx++) {
|
||||
Member member = members[memberIx];
|
||||
result.ProcessWeightsFrom(member.brain, Average);
|
||||
}
|
||||
Cluster result = members[0].brain.Copy();
|
||||
// for (int memberIx = 1; memberIx < members.Count; memberIx++) {
|
||||
// Member member = members[memberIx];
|
||||
// result.ProcessWeightsFrom(member.brain, Average);
|
||||
// }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ namespace NanoBrain {
|
||||
// this.clusterName = synapse.neuron.parent.prefab.name;
|
||||
// else
|
||||
// this.clusterName = synapse.neuron.parent.name;
|
||||
this.clusterName = synapse.neuron.parent.name;
|
||||
this.clusterName = synapse.neuron.parent.baseName;
|
||||
this.neuronName = synapse.neuron.name;
|
||||
this.weight = synapse.weight;
|
||||
this.trainable = synapse.trainable;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user