Boid training first steps
This commit is contained in:
parent
90f8065a39
commit
a229ee21f0
@ -25,7 +25,7 @@ namespace NanoBrain.Unity {
|
||||
return height;
|
||||
|
||||
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
||||
if (//prefabProp.objectReferenceValue != null &&
|
||||
if (prefabProp.objectReferenceValue != null &&
|
||||
Cluster_Drawer.currentClusterView.isOpen) {
|
||||
height = graphHeight;
|
||||
}
|
||||
|
||||
@ -99,7 +99,6 @@ namespace NanoBrain {
|
||||
ClonePrefab();
|
||||
|
||||
if (instanceCount > 1) {
|
||||
Debug.Log($" InstanceCount = {instanceCount}");
|
||||
List<Cluster> siblings = new() { this };
|
||||
for (int instanceIx = 1; instanceIx < instanceCount; instanceIx++) {
|
||||
// Create another sibling
|
||||
@ -474,27 +473,27 @@ namespace NanoBrain {
|
||||
return allInstances;
|
||||
}
|
||||
|
||||
public void Backpropagation(Func<Cluster, float> Observer, float target, float learningRate) {
|
||||
foreach (Nucleus nucleus in this.instances[0].nuclei) {
|
||||
if (nucleus is not Neuron neuron)
|
||||
continue;
|
||||
// public void Backpropagation(Func<Cluster, float> Observer, float target, float learningRate) {
|
||||
// foreach (Nucleus nucleus in this.instances[0].nuclei) {
|
||||
// if (nucleus is not Neuron neuron)
|
||||
// continue;
|
||||
|
||||
foreach (Synapse synapse in neuron.synapses) {
|
||||
List<Neuron> allSynapseNeurons = GetAllInstances(synapse.neuron);
|
||||
// foreach (Synapse synapse in neuron.synapses) {
|
||||
// List<Neuron> allSynapseNeurons = GetAllInstances(synapse.neuron);
|
||||
|
||||
Vector3 dSSRdW = Vector3.zero;
|
||||
for (int clusterIx = 0; clusterIx < this.instances.Length; clusterIx++) {
|
||||
Cluster clusterInstance = this.instances[clusterIx];
|
||||
Neuron neuronInstance = allSynapseNeurons[clusterIx];
|
||||
// Vector3 dSSRdW = Vector3.zero;
|
||||
// for (int clusterIx = 0; clusterIx < this.instances.Length; clusterIx++) {
|
||||
// Cluster clusterInstance = this.instances[clusterIx];
|
||||
// Neuron neuronInstance = allSynapseNeurons[clusterIx];
|
||||
|
||||
// Simple case, without receivers...
|
||||
dSSRdW += (Vector3)(-2 * (Observer(clusterInstance) - target) * neuronInstance.activation);
|
||||
}
|
||||
synapse.weight += learningRate * dSSRdW.magnitude;
|
||||
}
|
||||
}
|
||||
// // Simple case, without receivers...
|
||||
// dSSRdW += (Vector3)(-2 * (Observer(clusterInstance) - target) * neuronInstance.activation);
|
||||
// }
|
||||
// synapse.weight += learningRate * dSSRdW.magnitude;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
#endregion ClusterArray
|
||||
|
||||
@ -867,13 +866,13 @@ namespace NanoBrain {
|
||||
ClusterData data = new(this); //this.ToJSON();
|
||||
string json = JsonUtility.ToJson(data, prettyPrint: true);
|
||||
|
||||
Debug.Log($"Exporting json to {path}");
|
||||
System.IO.File.WriteAllText(path, json);
|
||||
// Debug.Log($"Exporting json to {path}");
|
||||
File.WriteAllText(path, json);
|
||||
}
|
||||
|
||||
public static ClusterData Import(string path) {
|
||||
string json = File.ReadAllText(path);
|
||||
Debug.Log($"Importing json from {path}");
|
||||
// Debug.Log($"Importing json from {path}");
|
||||
return JsonUtility.FromJson<ClusterData>(json);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user