using System;
using UnityEngine;
using Unity.Mathematics;
namespace NanoBrain {
///
/// A Synapse connects the ouput of a Neuron to another Neuron
///
[Serializable]
public class Synapse {
///
/// The neuron from which input is received
///
[SerializeReference]
public Neuron neuron;
///
/// The weight value to apply to the Neuron input
///
public float weight;
public bool trainable = false;
///
/// Create a new Synapse
///
/// The neuron from which input is received
/// The weight value to apply to the Neuron input
public Synapse(Neuron nucleus, float weight = 1.0f) {
this.neuron = nucleus;
this.weight = weight;
}
public virtual void BasicBackPropagation(float error, float learningRate) {
float derivative = error;
switch (neuron.activator) {
case Neuron.ActivationType.Linear:
derivative *= 1;
break;
default:
break;
}
derivative *= math.length(neuron.activation);
float deltaWeight = learningRate * derivative;
this.weight += deltaWeight;
}
}
}