51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace NanoBrain {
|
|
|
|
/// <summary>
|
|
/// The NanoBrain Unity Componnent
|
|
/// </summary>
|
|
/// This implements the top-level NanoBrain Cluster
|
|
public class NanoBrain : MonoBehaviour {
|
|
/// <summary>
|
|
/// The Cluster prefab from which the cluster is created
|
|
/// </summary>
|
|
public ClusterPrefab defaultBrain;
|
|
|
|
[NonSerialized]
|
|
private Cluster brainInstance;
|
|
/// <summary>
|
|
/// The cluster isntance
|
|
/// </summary>
|
|
public Cluster brain {
|
|
get {
|
|
if (brainInstance == null && defaultBrain != null) {
|
|
brainInstance = new Cluster(defaultBrain) {
|
|
name = defaultBrain.name + " (Instance)"
|
|
};
|
|
}
|
|
return brainInstance;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update the weight for all Synapses coming from the Neuron with the given name
|
|
/// </summary>
|
|
/// <param name="brain">The cluster in which the synapses are updated</param>
|
|
/// <param name="name">The name of the Neuron for which the weights are updated</param>
|
|
/// <param name="weight">The new Synapse weight</param>
|
|
public static void UpdateWeight(Cluster brain, string name, float weight) {
|
|
Nucleus root = brain.defaultOutput;
|
|
foreach (Synapse synapse in root.synapses) {
|
|
if (synapse.neuron.name == name) {
|
|
if (synapse.weight != weight) {
|
|
synapse.weight = weight;
|
|
// Debug.Log($"Updated weight for {name}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |