diff --git a/Editor/ClusterEditor.cs b/Editor/ClusterEditor.cs
index fe182c8..d5aaf06 100644
--- a/Editor/ClusterEditor.cs
+++ b/Editor/ClusterEditor.cs
@@ -57,7 +57,7 @@ namespace NanoBrain.Unity {
versionProp.intValue++;
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
- Debug.Log($"{name} Prefab changed, version {versionProp.intValue}");
+ // Debug.Log($"{name} Prefab changed, version {versionProp.intValue}");
}
}
diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs
index 18332e1..e93b7e4 100644
--- a/Runtime/Scripts/Core/Cluster.cs
+++ b/Runtime/Scripts/Core/Cluster.cs
@@ -157,7 +157,7 @@ namespace NanoBrain {
// Could not find the neuron in the cloned cluster
continue;
- clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight);
+ clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight, prefabSynapse.trainable);
//Debug.Log($"Add synapse {clonedCluster.name}.{clonedSender.name} -> {clonedNeuron.name} [{clonedSender.receivers.Count}]");
}
else {
@@ -168,7 +168,7 @@ namespace NanoBrain {
continue;
// Copy the receivers which will also create the synapse
- clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight);
+ clonedSender.AddReceiver(clonedNeuron, prefabSynapse.weight, prefabSynapse.trainable);
// Debug.Log($"Add synapse {clonedSender.name} -> {clonedNeuron.name}");
}
}
diff --git a/Runtime/Scripts/Core/Neuron.cs b/Runtime/Scripts/Core/Neuron.cs
index b5ebda2..9a9ccef 100644
--- a/Runtime/Scripts/Core/Neuron.cs
+++ b/Runtime/Scripts/Core/Neuron.cs
@@ -63,8 +63,10 @@ namespace NanoBrain {
/// The weight applied to the input. Default value = 1
/// The created Synapse
/// This will add a new input to this nucleus with the given weight.
- public Synapse AddSynapse(Neuron sendingNucleus, float weight = 1) {
- Synapse synapse = new(sendingNucleus, weight);
+ public Synapse AddSynapse(Neuron sendingNucleus, float weight = 1, bool trainable = false) {
+ Synapse synapse = new(sendingNucleus, weight) {
+ trainable = trainable
+ };
this.synapses.Add(synapse);
return synapse;
}
@@ -627,11 +629,11 @@ namespace NanoBrain {
///
/// The receiver to add
/// The weight to use for the synapse to his neuron
- public virtual void AddReceiver(Nucleus receiverToAdd, float weight = 1) {
+ public virtual void AddReceiver(Nucleus receiverToAdd, float weight = 1, bool trainable = false) {
if (receiverToAdd is not Neuron receiverNeuron)
return;
this._receivers.Add(receiverNeuron);
- receiverNeuron.AddSynapse(this, weight);
+ receiverNeuron.AddSynapse(this, weight, trainable);
//Debug.Log($"Add synapse {this.clusterPrefab.name}.{this.name} -> {receiverToAdd.name} --- [{this.receivers.Count}]");
}
@@ -762,25 +764,26 @@ namespace NanoBrain {
this.bias -= stepSize;
foreach (Synapse synapse in this.synapses) {
- // derivative for the weight?
- float3 deltaSynapse = derivative; // dSSR/dActivator
+ synapse.BackPropagation(length(derivative), learningRate);
+ // // derivative for the weight?
+ // float3 deltaSynapse = derivative; // dSSR/dActivator
- // derivative for the activator
- // dActivator/dCombinator
- switch (activator) {
- case ActivationType.Linear:
- //deltaSynapse *= 1;
- break;
- default:
- break;
- }
+ // // derivative for the activator
+ // // dActivator/dCombinator
+ // switch (activator) {
+ // case ActivationType.Linear:
+ // //deltaSynapse *= 1;
+ // break;
+ // default:
+ // break;
+ // }
- // derivative for the previous activation
- // dCombinator/dWeight
- deltaSynapse *= synapse.neuron.activation;
+ // // derivative for the previous activation
+ // // dCombinator/dWeight
+ // deltaSynapse *= synapse.neuron.activation;
- float deltaWeight = length(deltaSynapse);
- synapse.weight += learningRate * deltaWeight;
+ // float deltaWeight = length(deltaSynapse);
+ // synapse.weight += learningRate * deltaWeight;
BackPropagation2(derivative * synapse.weight, learningRate);
}
diff --git a/Runtime/Scripts/Core/Synapse.cs b/Runtime/Scripts/Core/Synapse.cs
index 5cca04a..22ee378 100644
--- a/Runtime/Scripts/Core/Synapse.cs
+++ b/Runtime/Scripts/Core/Synapse.cs
@@ -13,6 +13,7 @@ namespace NanoBrain {
/// The neuron from which input is received
///
[SerializeReference]
+ [HideInInspector]
public Neuron neuron;
///
@@ -32,7 +33,7 @@ namespace NanoBrain {
this.weight = weight;
}
- public virtual void BasicBackPropagation(float error, float learningRate) {
+ public virtual void BackPropagation(float error, float learningRate) {
float derivative = error;
switch (neuron.activator) {
case Neuron.ActivationType.Linear: