Fix calculating the weight average
This commit is contained in:
parent
e96347a7b2
commit
120e705157
@ -966,6 +966,20 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ProcessWeights(Func<float, float> processor) {
|
||||||
|
if (processor is null)
|
||||||
|
throw new ArgumentNullException(nameof(processor));
|
||||||
|
int thisNucleiCount = this.nuclei.Count;
|
||||||
|
|
||||||
|
for (int i = 0; i < thisNucleiCount; i++) {
|
||||||
|
if (this.nuclei[i] is Neuron thisNeuron) {
|
||||||
|
|
||||||
|
thisNeuron.ProcessWeight(processor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#region Receivers
|
#region Receivers
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -346,6 +346,17 @@ namespace NanoBrain {
|
|||||||
thisSynapse.weight = processor(thisSynapse.weight, sourceSynapse.weight);
|
thisSynapse.weight = processor(thisSynapse.weight, sourceSynapse.weight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ProcessWeight(Func<float, float> processor) {
|
||||||
|
int thisSynapseCount = this.synapses.Count;
|
||||||
|
|
||||||
|
for (int i = 0; i < thisSynapseCount; i++) {
|
||||||
|
Synapse thisSynapse = this.synapses[i];
|
||||||
|
if (thisSynapse.trainable) {
|
||||||
|
thisSynapse.weight = processor(thisSynapse.weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,11 +56,15 @@ namespace NanoBrain {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
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++) {
|
||||||
// Member member = members[memberIx];
|
// Debug.Log($"{((Neuron)result.nuclei[0]).synapses[0].weight}");
|
||||||
// result.ProcessWeightsFrom(member.brain, Average);
|
Member member = members[memberIx];
|
||||||
// }
|
result.ProcessWeightsFrom(member.brain, Sum);
|
||||||
|
}
|
||||||
|
// Debug.Log($"R {((Neuron)result.nuclei[0]).synapses[0].weight}");
|
||||||
|
result.ProcessWeights(w => w / members.Count);
|
||||||
|
|
||||||
|
// Debug.Log($"A {((Neuron)result.nuclei[0]).synapses[0].weight}");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +140,11 @@ namespace NanoBrain {
|
|||||||
return (a + b) / 2;
|
return (a + b) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static float Sum(float a, float b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected List<Member> GenerateRandom() {
|
protected List<Member> GenerateRandom() {
|
||||||
return GenerateRandom(int.MaxValue);
|
return GenerateRandom(int.MaxValue);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user