neuroid value as Vector3
This commit is contained in:
parent
5dbb5654a1
commit
cd74c312dc
@ -81,21 +81,24 @@ public class Neuroid : Nucleus {
|
|||||||
if (synapse.nucleus.isSleeping)
|
if (synapse.nucleus.isSleeping)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Spherical outputValue = synapse.nucleus.outputValue;
|
Vector3 outputValue = synapse.nucleus.outputValue;
|
||||||
float weight = synapse.weight;
|
float weight = synapse.weight;
|
||||||
float activatedValue = curve.Evaluate(outputValue.magnitude);
|
float activatedValue = curve.Evaluate(outputValue.magnitude);
|
||||||
float magnitude = weight * activatedValue;
|
float magnitude = weight * activatedValue;
|
||||||
Spherical sVector = new(magnitude, outputValue.direction);
|
//Spherical sVector = new(magnitude, outputValue.direction);
|
||||||
|
|
||||||
sum += sVector.ToVector3();
|
sum += magnitude * outputValue.normalized;//sVector.ToVector3();
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spherical result;
|
//Spherical result;
|
||||||
|
Vector3 result;
|
||||||
if (average)
|
if (average)
|
||||||
result = Spherical.FromVector3(sum / n);
|
//result = Spherical.FromVector3(sum / n);
|
||||||
|
result = sum / n;
|
||||||
else
|
else
|
||||||
result = Spherical.FromVector3(sum);
|
//result = Spherical.FromVector3(sum);
|
||||||
|
result = sum;
|
||||||
|
|
||||||
UpdateResult(result);
|
UpdateResult(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,8 +64,8 @@ public class Nucleus {
|
|||||||
|
|
||||||
public NanoBrainObj brain { get; set; }
|
public NanoBrainObj brain { get; set; }
|
||||||
|
|
||||||
private Spherical _outputValue;
|
private Vector3 _outputValue;
|
||||||
public Spherical outputValue //{ get; set; }
|
public Vector3 outputValue //{ get; set; }
|
||||||
{
|
{
|
||||||
get { return _outputValue; }
|
get { return _outputValue; }
|
||||||
set {
|
set {
|
||||||
@ -83,7 +83,7 @@ public class Nucleus {
|
|||||||
this.stale++;
|
this.stale++;
|
||||||
this.isSleeping = this.stale > 2;
|
this.isSleeping = this.stale > 2;
|
||||||
if (isSleeping)
|
if (isSleeping)
|
||||||
_outputValue = Spherical.zero;
|
_outputValue = Vector3.zero;
|
||||||
}
|
}
|
||||||
[System.NonSerialized]
|
[System.NonSerialized]
|
||||||
public int layerIx;
|
public int layerIx;
|
||||||
@ -153,7 +153,7 @@ public class Nucleus {
|
|||||||
|
|
||||||
public virtual void UpdateState() { }
|
public virtual void UpdateState() { }
|
||||||
|
|
||||||
public void UpdateResult(Spherical result) {
|
public void UpdateResult(Vector3 result) {
|
||||||
// float d = Spherical.Distance(result, this.outputValue);
|
// float d = Spherical.Distance(result, this.outputValue);
|
||||||
// if (d < 0.1f) {
|
// if (d < 0.1f) {
|
||||||
// //Debug.Log($"insignificant update: {d}");
|
// //Debug.Log($"insignificant update: {d}");
|
||||||
|
|||||||
@ -68,14 +68,14 @@ public class Perceptoid : Neuroid {
|
|||||||
|
|
||||||
this.thingType = thingType;
|
this.thingType = thingType;
|
||||||
this.receptor.thingType = thingType;
|
this.receptor.thingType = thingType;
|
||||||
this.receptor.localPosition = Spherical.zero;
|
this.receptor.localPosition = Vector3.zero;
|
||||||
|
|
||||||
this.outputValue = Spherical.zero;
|
this.outputValue = Vector3.zero;
|
||||||
this.receivers = new();
|
this.receivers = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateState() {
|
public override void UpdateState() {
|
||||||
Spherical result = this.receptor.localPosition;
|
Vector3 result = this.receptor.localPosition;
|
||||||
UpdateResult(result);
|
UpdateResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class Receptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public Spherical localPosition;
|
public Vector3 localPosition;
|
||||||
public float distanceResolution = 0.1f;
|
public float distanceResolution = 0.1f;
|
||||||
public float directionResolution = 5;
|
public float directionResolution = 5;
|
||||||
|
|
||||||
@ -38,10 +38,10 @@ public class Receptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ProcessStimulus(int thingId, Vector3 newLocalPositionVector) {
|
public virtual void ProcessStimulus(int thingId, Vector3 newLocalPositionVector) {
|
||||||
Spherical newLocalPosition = Spherical.FromVector3(newLocalPositionVector);
|
//Spherical newLocalPosition = Spherical.FromVector3(newLocalPositionVector);
|
||||||
|
|
||||||
Spherical previousLocalPosition = this.localPosition;
|
Vector3 previousLocalPosition = this.localPosition;
|
||||||
this.localPosition = newLocalPosition;
|
this.localPosition = newLocalPositionVector;
|
||||||
|
|
||||||
Perceptoid selectedPerceptoid = null;
|
Perceptoid selectedPerceptoid = null;
|
||||||
foreach (Perceptoid perceptoid in this.perceptei) {
|
foreach (Perceptoid perceptoid in this.perceptei) {
|
||||||
|
|||||||
@ -339,7 +339,7 @@ public class GraphBoardView : VisualElement {
|
|||||||
currentNucleus.name = EditorGUILayout.TextField(currentNucleus.name);
|
currentNucleus.name = EditorGUILayout.TextField(currentNucleus.name);
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
EditorGUILayout.LabelField("Output Value", GUILayout.Width(100));
|
EditorGUILayout.LabelField("Output Value", GUILayout.Width(100));
|
||||||
EditorGUILayout.Vector3Field(GUIContent.none, currentNucleus.outputValue.ToVector3());
|
EditorGUILayout.Vector3Field(GUIContent.none, currentNucleus.outputValue);
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
if (currentNucleus.synapses.Count > 0) {
|
if (currentNucleus.synapses.Count > 0) {
|
||||||
EditorGUILayout.LabelField("Synapses");
|
EditorGUILayout.LabelField("Synapses");
|
||||||
@ -358,7 +358,7 @@ public class GraphBoardView : VisualElement {
|
|||||||
// currentNucleus.synapses[nucleus] = EditorGUILayout.FloatField(weight, GUILayout.Width(40));
|
// currentNucleus.synapses[nucleus] = EditorGUILayout.FloatField(weight, GUILayout.Width(40));
|
||||||
synapse.weight = EditorGUILayout.FloatField(synapse.weight, GUILayout.Width(40));
|
synapse.weight = EditorGUILayout.FloatField(synapse.weight, GUILayout.Width(40));
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
EditorGUILayout.Vector3Field(GUIContent.none, synapse.nucleus.outputValue.ToVector3(), GUILayout.Width(180));
|
EditorGUILayout.Vector3Field(GUIContent.none, synapse.nucleus.outputValue, GUILayout.Width(180));
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
EditorGUI.EndDisabledGroup();
|
EditorGUI.EndDisabledGroup();
|
||||||
|
|||||||
@ -457,7 +457,7 @@ public class NanoBrainInspector : Editor {
|
|||||||
DisconnectNucleus(this.currentNucleus);
|
DisconnectNucleus(this.currentNucleus);
|
||||||
|
|
||||||
if (this.gameObject != null) {
|
if (this.gameObject != null) {
|
||||||
Vector3 worldVector = this.gameObject.transform.TransformVector(this.currentNucleus.outputValue.ToVector3());
|
Vector3 worldVector = this.gameObject.transform.TransformVector(this.currentNucleus.outputValue);
|
||||||
Debug.DrawRay(this.gameObject.transform.position, worldVector, Color.yellow);
|
Debug.DrawRay(this.gameObject.transform.position, worldVector, Color.yellow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -44,15 +44,15 @@ public class Boid : MonoBehaviour {
|
|||||||
if (neighbour == null || neighbour == this)
|
if (neighbour == null || neighbour == this)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Vector3 localPosition = this.transform.InverseTransformPoint(neighbour.transform.position);
|
int thingId = neighbour.GetInstanceID();
|
||||||
//localPosition = localPosition.normalized * (localPosition.magnitude - sc.separationDistance);
|
|
||||||
//Debug.DrawRay(this.transform.position, this.transform.TransformDirection(localPosition), Color.magenta);
|
Vector3 localPosition = this.transform.InverseTransformPoint(neighbour.transform.position);
|
||||||
|
if (localPosition.sqrMagnitude > 0)
|
||||||
|
boidReceptor?.ProcessStimulus(thingId, localPosition);
|
||||||
|
|
||||||
Vector3 localVelocity = this.transform.InverseTransformVector(neighbour.velocity);
|
Vector3 localVelocity = this.transform.InverseTransformVector(neighbour.velocity);
|
||||||
|
if (localVelocity.sqrMagnitude > 0)
|
||||||
int thingId = neighbour.GetInstanceID();
|
boidVelocityReceptor?.ProcessStimulus(thingId, localVelocity);
|
||||||
boidReceptor?.ProcessStimulus(thingId, localPosition);
|
|
||||||
boidVelocityReceptor?.ProcessStimulus(thingId, localVelocity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +64,7 @@ public class Boid : MonoBehaviour {
|
|||||||
boundaryReceptor.ProcessStimulus(777, desiredLocalSpace);
|
boundaryReceptor.ProcessStimulus(777, desiredLocalSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 worldForce = this.transform.TransformDirection(nanoBrain.root.outputValue);
|
||||||
Vector3 worldForce = this.transform.TransformDirection(nanoBrain.root.outputValue.ToVector3());
|
|
||||||
|
|
||||||
this.velocity = (1 - sc.inertia) * (worldForce * Time.deltaTime) + sc.inertia * velocity;
|
this.velocity = (1 - sc.inertia) * (worldForce * Time.deltaTime) + sc.inertia * velocity;
|
||||||
if (this.velocity.magnitude > 0)
|
if (this.velocity.magnitude > 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user