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