49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using Unity.Mathematics;
|
|
using static Unity.Mathematics.math;
|
|
|
|
public class Selector : Neuron {
|
|
public Selector(Cluster parent, string name) : base(parent, name) { }
|
|
|
|
public override void UpdateStateIsolated(float3 bias) {
|
|
float3 max = bias;
|
|
float maxSqrLength = lengthsq(max);
|
|
|
|
//Applying the weight factors
|
|
foreach (Synapse synapse in this.synapses) {
|
|
float3 input = synapse.weight * synapse.nucleus.outputValue;
|
|
|
|
float inputSqrlength = lengthsq(input);
|
|
if (inputSqrlength > maxSqrLength) {
|
|
max = input;
|
|
maxSqrLength = inputSqrlength;
|
|
}
|
|
}
|
|
|
|
// Activation function
|
|
float3 result;
|
|
switch (this.curvePreset) {
|
|
case CurvePresets.Linear:
|
|
result = max;
|
|
break;
|
|
case CurvePresets.Sqrt:
|
|
result = normalize(max) * System.MathF.Sqrt(length(max));
|
|
break;
|
|
case CurvePresets.Power:
|
|
result = normalize(max) * System.MathF.Pow(length(max), 2);
|
|
break;
|
|
case CurvePresets.Reciprocal: {
|
|
float magnitude = length(max);
|
|
if (magnitude > 0)
|
|
result = normalize(max) * (1 / magnitude);
|
|
else
|
|
result = float3(0, 0, 0);
|
|
break;
|
|
}
|
|
default:
|
|
float activatedValue = this.curve.Evaluate(length(max));
|
|
result = normalize(max) * activatedValue;
|
|
break;
|
|
}
|
|
this.outputValue = result;
|
|
}
|
|
} |