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;
|
sum /= n;
|
||||||
|
|
||||||
// Activation function
|
// Activation function
|
||||||
Vector3 result;
|
float3 result = Vector3.zero;
|
||||||
switch (this.curvePreset) {
|
switch (this.curvePreset) {
|
||||||
case CurvePresets.Linear:
|
case CurvePresets.Linear:
|
||||||
result = sum;
|
result = sum;
|
||||||
@ -354,9 +354,12 @@ public class Neuron : INucleus {
|
|||||||
case CurvePresets.Power:
|
case CurvePresets.Power:
|
||||||
result = normalize(sum) * System.MathF.Pow(length(sum), 2);
|
result = normalize(sum) * System.MathF.Pow(length(sum), 2);
|
||||||
break;
|
break;
|
||||||
case CurvePresets.Reciprocal:
|
case CurvePresets.Reciprocal: {
|
||||||
result = normalize(sum) * (1 / length(sum));
|
float magnitude = length(sum);
|
||||||
break;
|
if (magnitude > 0)
|
||||||
|
result = normalize(sum) * (1 / magnitude);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
float activatedValue = this.curve.Evaluate(length(sum));
|
float activatedValue = this.curve.Evaluate(length(sum));
|
||||||
result = normalize(sum) * activatedValue;
|
result = normalize(sum) * activatedValue;
|
||||||
|
|||||||
@ -3,22 +3,22 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class NanoBrainComponent : MonoBehaviour {
|
public class NanoBrainComponent : MonoBehaviour {
|
||||||
public ClusterPrefab defaultBrain;
|
public ClusterPrefab defaultBrain;
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private Cluster brainInstance;
|
private Cluster brainInstance;
|
||||||
public Cluster brain {
|
public Cluster brain {
|
||||||
get {
|
get {
|
||||||
if (brainInstance == null && defaultBrain != null) {
|
if (brainInstance == null && defaultBrain != null) {
|
||||||
brainInstance = new Cluster(defaultBrain); //Instantiate(defaultBrain);
|
brainInstance = new Cluster(defaultBrain) {
|
||||||
brainInstance.name = defaultBrain.name + " (Instance)";
|
name = defaultBrain.name + " (Instance)"
|
||||||
|
};
|
||||||
SwarmControl sc = FindFirstObjectByType<SwarmControl>();
|
}
|
||||||
if (sc != null) {
|
SwarmControl sc = FindFirstObjectByType<SwarmControl>();
|
||||||
UpdateWeight(brainInstance, "Avoidance", sc.avoidanceForce);
|
if (sc != null) {
|
||||||
UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
|
UpdateWeight(brainInstance, "Containment", sc.containmentForce);
|
||||||
UpdateWeight(brainInstance, "Separation", sc.separationForce);
|
UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce);
|
||||||
UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
|
UpdateWeight(brainInstance, "Separation", sc.separationForce);
|
||||||
}
|
UpdateWeight(brainInstance, "Alignment", sc.alignmentForce);
|
||||||
}
|
}
|
||||||
return brainInstance;
|
return brainInstance;
|
||||||
}
|
}
|
||||||
@ -28,7 +28,10 @@ public class NanoBrainComponent : MonoBehaviour {
|
|||||||
INucleus root = brain.output;
|
INucleus root = brain.output;
|
||||||
foreach (Synapse synapse in root.synapses) {
|
foreach (Synapse synapse in root.synapses) {
|
||||||
if (synapse.nucleus.name == name) {
|
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