Fix produced json
This commit is contained in:
parent
5553f8994f
commit
e96347a7b2
@ -372,7 +372,7 @@ namespace NanoBrain {
|
||||
}
|
||||
}
|
||||
|
||||
public Cluster Clone() {
|
||||
public Cluster Copy() {
|
||||
Cluster clone = new() {
|
||||
name = this.name,
|
||||
prefab = this.prefab,
|
||||
@ -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) {
|
||||
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.name != cluster.name) {
|
||||
if (synapse.neuron.parent.baseName == cluster.name)
|
||||
continue;
|
||||
|
||||
ExternalClusterData clusterData = new(synapse.neuron.parent);
|
||||
if (GetCluster(clusterData.name) == null) {
|
||||
//if (this.clusters.Find(data => data.name == clusterData.name) == null) {
|
||||
if (GetCluster(clusterData.name) == null)
|
||||
this.clusters.Add(clusterData);
|
||||
//Debug.Log("Add cluster");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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