pre: activation function to synapse neuron
This commit is contained in:
parent
cd74c312dc
commit
b9b942760b
@ -75,30 +75,19 @@ public class Neuroid : Nucleus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateState() {
|
public override void UpdateState() {
|
||||||
Vector3 sum = Vector3.zero;
|
Vector3 result = Vector3.zero;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
foreach (Synapse synapse in this.synapses) {
|
foreach (Synapse synapse in this.synapses) {
|
||||||
if (synapse.nucleus.isSleeping)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Vector3 outputValue = synapse.nucleus.outputValue;
|
Vector3 outputValue = synapse.nucleus.outputValue;
|
||||||
float weight = synapse.weight;
|
// As this is the activation function, it should be evaluated in the synapse.nucleus...
|
||||||
float activatedValue = curve.Evaluate(outputValue.magnitude);
|
float activatedValue = curve.Evaluate(outputValue.magnitude);
|
||||||
float magnitude = weight * activatedValue;
|
float magnitude = synapse.weight * activatedValue;
|
||||||
//Spherical sVector = new(magnitude, outputValue.direction);
|
|
||||||
|
|
||||||
sum += magnitude * outputValue.normalized;//sVector.ToVector3();
|
result += magnitude * outputValue.normalized;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Spherical result;
|
|
||||||
Vector3 result;
|
|
||||||
if (average)
|
if (average)
|
||||||
//result = Spherical.FromVector3(sum / n);
|
result /= n;
|
||||||
result = sum / n;
|
|
||||||
else
|
|
||||||
//result = Spherical.FromVector3(sum);
|
|
||||||
result = sum;
|
|
||||||
|
|
||||||
UpdateResult(result);
|
UpdateResult(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class Nucleus {
|
|||||||
public NanoBrainObj brain { get; set; }
|
public NanoBrainObj brain { get; set; }
|
||||||
|
|
||||||
private Vector3 _outputValue;
|
private Vector3 _outputValue;
|
||||||
public Vector3 outputValue //{ get; set; }
|
public Vector3 outputValue
|
||||||
{
|
{
|
||||||
get { return _outputValue; }
|
get { return _outputValue; }
|
||||||
set {
|
set {
|
||||||
@ -154,7 +154,7 @@ public class Nucleus {
|
|||||||
public virtual void UpdateState() { }
|
public virtual void UpdateState() { }
|
||||||
|
|
||||||
public void UpdateResult(Vector3 result) {
|
public void UpdateResult(Vector3 result) {
|
||||||
// float d = Spherical.Distance(result, this.outputValue);
|
// float d = Vector3.Distance(result, this.outputValue);
|
||||||
// if (d < 0.1f) {
|
// if (d < 0.1f) {
|
||||||
// //Debug.Log($"insignificant update: {d}");
|
// //Debug.Log($"insignificant update: {d}");
|
||||||
// return;
|
// return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user