Improvements
This commit is contained in:
parent
09a75aa22e
commit
6c30009564
@ -827,7 +827,7 @@ namespace NanoBrain {
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateNuclei();
|
||||
//UpdateNuclei();
|
||||
}
|
||||
|
||||
public override void UpdateStateIsolated() {
|
||||
@ -835,10 +835,10 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
// Don't think this does anything anymore...
|
||||
public override void UpdateNuclei() {
|
||||
foreach (Nucleus nucleus in this.nuclei)
|
||||
nucleus.UpdateNuclei();
|
||||
}
|
||||
// public override void UpdateNuclei() {
|
||||
// foreach (Nucleus nucleus in this.nuclei)
|
||||
// nucleus.UpdateNuclei();
|
||||
// }
|
||||
|
||||
#endregion Update
|
||||
|
||||
|
||||
@ -117,8 +117,6 @@ namespace NanoBrain {
|
||||
Sum,
|
||||
/// Multiply the weighted values
|
||||
Product,
|
||||
/// Take the maximum of all the weighted values
|
||||
Max,
|
||||
}
|
||||
/// <summary>
|
||||
/// The type of combinator used for this Neuron
|
||||
@ -377,20 +375,14 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
public override void UpdateStateIsolated() {
|
||||
CheckSleepingSynapses();
|
||||
var result = Combinator();
|
||||
this.outputValue = Activator(result);
|
||||
this.outputValue = ApplyActivator(result);
|
||||
this.lastUpdate = Time.time;
|
||||
// Debug.Log($"Update Neuron {this.name}");
|
||||
}
|
||||
|
||||
protected void CheckSleepingSynapses() {
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
foreach (Synapse synapse in this.synapses)
|
||||
synapse.neuron.SleepCheck();
|
||||
// if (synapse.isSleeping) {
|
||||
// synapse.neuron.outputValue = Vector3.zero;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
#region Combinator
|
||||
@ -400,42 +392,27 @@ namespace NanoBrain {
|
||||
protected Func<float3> Combinator => combinator switch {
|
||||
CombinatorType.Sum => CombinatorSum,
|
||||
CombinatorType.Product => CombinatorProduct,
|
||||
CombinatorType.Max => CombinatorMax,
|
||||
_ => CombinatorSum
|
||||
};
|
||||
|
||||
public float3 CombinatorSum() {
|
||||
float3 sum = this.bias;
|
||||
foreach (Synapse synapse in this.synapses)
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
synapse.neuron.SleepCheck();
|
||||
sum += synapse.weight * synapse.neuron.outputValue;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public float3 CombinatorProduct() {
|
||||
float3 product = this.bias;
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
synapse.neuron.SleepCheck();
|
||||
product *= synapse.weight * synapse.neuron.outputValue;
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
public float3 CombinatorMax() {
|
||||
float3 max = this.bias;
|
||||
float maxLength = length(max);
|
||||
|
||||
//Applying the weight factors
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
float3 input = synapse.weight * synapse.neuron.outputValue;
|
||||
|
||||
float inputLength = length(input);
|
||||
if (inputLength > maxLength) {
|
||||
max = input;
|
||||
maxLength = inputLength;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
protected Func<Vector3> Combinator => combinator switch {
|
||||
@ -484,6 +461,20 @@ namespace NanoBrain {
|
||||
|
||||
#if UNITY_MATHEMATICS
|
||||
|
||||
// This does not allocate memory and seems faster than the solution below
|
||||
float3 ApplyActivator(float3 x) {
|
||||
switch (curvePreset) {
|
||||
case ActivationType.Linear: return ActivatorLinear(x);
|
||||
case ActivationType.Sqrt: return ActivatorSqrt(x);
|
||||
case ActivationType.Power: return ActivatorPower(x);
|
||||
case ActivationType.Reciprocal: return ActivatorReciprocal(x);
|
||||
case ActivationType.Tanh: return ActivatorTanh(x);
|
||||
case ActivationType.Binary: return ActivatorBinary(x);
|
||||
case ActivationType.Normalized: return ActivatorNormalized(x);
|
||||
default: return ActivatorCustom(x);
|
||||
}
|
||||
}
|
||||
|
||||
public Func<float3, float3> Activator => this.curvePreset switch {
|
||||
ActivationType.Linear => ActivatorLinear,
|
||||
ActivationType.Sqrt => ActivatorSqrt,
|
||||
|
||||
@ -193,8 +193,6 @@ namespace CreatureControl {
|
||||
float angle = Vector3.Angle(Vector3.forward, smellDirection);
|
||||
|
||||
if (angle < smellAngle && smellDirection.magnitude > 0.01) {
|
||||
// float intensity = pheromone.StrengthAt(distance);
|
||||
// Vector3 smell = smellDirection.normalized * intensity;
|
||||
Vector3 smell = Vector3.zero;
|
||||
|
||||
int id = thing.GetInstanceID();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user