This commit is contained in:
Pascal Serrarens 2026-08-17 13:01:15 +02:00
parent 120e705157
commit da5a5492dd
3 changed files with 5 additions and 17 deletions

View File

@ -969,17 +969,13 @@ namespace NanoBrain {
public void ProcessWeights(Func<float, float> processor) { public void ProcessWeights(Func<float, float> processor) {
if (processor is null) if (processor is null)
throw new ArgumentNullException(nameof(processor)); throw new ArgumentNullException(nameof(processor));
int thisNucleiCount = this.nuclei.Count;
for (int i = 0; i < thisNucleiCount; i++) {
if (this.nuclei[i] is Neuron thisNeuron) {
for (int i = 0; i < this.nuclei.Count; i++) {
if (this.nuclei[i] is Neuron thisNeuron)
thisNeuron.ProcessWeight(processor); thisNeuron.ProcessWeight(processor);
} }
} }
}
#region Receivers #region Receivers
/// <summary> /// <summary>

View File

@ -349,17 +349,12 @@ namespace NanoBrain {
} }
public void ProcessWeight(Func<float, float> processor) { public void ProcessWeight(Func<float, float> processor) {
int thisSynapseCount = this.synapses.Count; foreach (Synapse thisSynapse in this.synapses) {
if (thisSynapse.trainable)
for (int i = 0; i < thisSynapseCount; i++) {
Synapse thisSynapse = this.synapses[i];
if (thisSynapse.trainable) {
thisSynapse.weight = processor(thisSynapse.weight); thisSynapse.weight = processor(thisSynapse.weight);
} }
} }
}
/// <summary> /// <summary>
/// Delete the give neuron /// Delete the give neuron
/// </summary> /// </summary>

View File

@ -57,14 +57,11 @@ namespace NanoBrain {
Cluster result = members[0].brain.Copy(); Cluster result = members[0].brain.Copy();
for (int memberIx = 1; memberIx < members.Count; memberIx++) { for (int memberIx = 1; memberIx < members.Count; memberIx++) {
// Debug.Log($"{((Neuron)result.nuclei[0]).synapses[0].weight}");
Member member = members[memberIx]; Member member = members[memberIx];
result.ProcessWeightsFrom(member.brain, Sum); result.ProcessWeightsFrom(member.brain, Sum);
} }
// Debug.Log($"R {((Neuron)result.nuclei[0]).synapses[0].weight}");
result.ProcessWeights(w => w / members.Count); result.ProcessWeights(w => w / members.Count);
// Debug.Log($"A {((Neuron)result.nuclei[0]).synapses[0].weight}");
return result; return result;
} }