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