Resetup swarming
This commit is contained in:
parent
91c4500b0a
commit
aab6f59934
11
Neuron.cs
11
Neuron.cs
@ -343,7 +343,7 @@ public class Neuron : INucleus {
|
||||
sum /= n;
|
||||
|
||||
// Activation function
|
||||
Vector3 result;
|
||||
float3 result = Vector3.zero;
|
||||
switch (this.curvePreset) {
|
||||
case CurvePresets.Linear:
|
||||
result = sum;
|
||||
@ -354,9 +354,12 @@ public class Neuron : INucleus {
|
||||
case CurvePresets.Power:
|
||||
result = normalize(sum) * System.MathF.Pow(length(sum), 2);
|
||||
break;
|
||||
case CurvePresets.Reciprocal:
|
||||
result = normalize(sum) * (1 / length(sum));
|
||||
break;
|
||||
case CurvePresets.Reciprocal: {
|
||||
float magnitude = length(sum);
|
||||
if (magnitude > 0)
|
||||
result = normalize(sum) * (1 / magnitude);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
float activatedValue = this.curve.Evaluate(length(sum));
|
||||
result = normalize(sum) * activatedValue;
|
||||
|
||||
@ -3,22 +3,22 @@ using UnityEngine;
|
||||
|
||||
public class NanoBrainComponent : MonoBehaviour {
|
||||
public ClusterPrefab defaultBrain;
|
||||
|
||||
|
||||
[NonSerialized]
|
||||
private Cluster brainInstance;
|
||||
public Cluster brain {
|
||||
get {
|
||||
if (brainInstance == null && defaultBrain != null) {
|
||||
brainInstance = new Cluster(defaultBrain); //Instantiate(defaultBrain);
|
||||
brainInstance.name = defaultBrain.name + " (Instance)";
|
||||
|
||||
SwarmControl sc = FindFirstObjectByType<SwarmControl>();
|
||||
if (sc != null) {
|
||||
UpdateWeight(brainInstance, "Avoidance", sc.avoidanceForce);
|
||||
UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
|
||||
UpdateWeight(brainInstance, "Separation", sc.separationForce);
|
||||
UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
|
||||
}
|
||||
brainInstance = new Cluster(defaultBrain) {
|
||||
name = defaultBrain.name + " (Instance)"
|
||||
};
|
||||
}
|
||||
SwarmControl sc = FindFirstObjectByType<SwarmControl>();
|
||||
if (sc != null) {
|
||||
UpdateWeight(brainInstance, "Containment", sc.containmentForce);
|
||||
UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
|
||||
UpdateWeight(brainInstance, "Separation", sc.separationForce);
|
||||
UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
|
||||
}
|
||||
return brainInstance;
|
||||
}
|
||||
@ -28,7 +28,10 @@ public class NanoBrainComponent : MonoBehaviour {
|
||||
INucleus root = brain.output;
|
||||
foreach (Synapse synapse in root.synapses) {
|
||||
if (synapse.nucleus.name == name) {
|
||||
synapse.weight = weight;
|
||||
if (synapse.weight != weight) {
|
||||
synapse.weight = weight;
|
||||
// Debug.Log($"Updated weight for {name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user