lc_silo_behavior behaviour (faber_neuroevolution v1.2.4)

View Source

Common behavior module for Liquid Conglomerate Silos.

All 13 silos implement this common pattern derived from task_silo.erl: gen_server behavior L0/L1/L2 hierarchical control levels Evaluation-centric tracking (total_evaluations as primary dimension) Velocity-based stagnation detection Cross-silo signal integration via lc_cross_silo ETS tables for persistent collections (where needed)

Implementing a New Silo

1. Create module with -behaviour(lc_silo_behavior) 2. Include lc_silos.hrl for common records 3. Implement required callbacks: init_silo/1: Initialize silo-specific state collect_sensors/1: Gather L0 sensor values apply_actuators/2: Apply L0 actuator outputs compute_reward/1: Compute reward for LC learning

Summary

Functions

Apply asymmetric EMA smoothing for fast escalation, slow de-escalation.

Clamp a value to a specified range.

Compute stagnation severity from velocity.

Compute improvement velocity from checkpoints.

Apply exponential moving average smoothing.

Normalize a value to [0,1] range given min/max bounds.

Callbacks

apply_actuators/2

-callback apply_actuators(Actuators :: map(), SiloState :: map()) -> {ok, NewSiloState :: map()}.

collect_sensors/1

-callback collect_sensors(SiloState :: map()) -> Sensors :: map().

compute_reward/1

-callback compute_reward(SiloState :: map()) -> Reward :: float().

emit_cross_silo_signals/1

(optional)
-callback emit_cross_silo_signals(SiloState :: map()) -> ok.

emit_silo_events/2

(optional)
-callback emit_silo_events(EventType :: atom(), SiloState :: map()) -> ok.

get_silo_type/0

-callback get_silo_type() -> atom().

get_time_constant/0

-callback get_time_constant() -> float().

handle_cross_silo_signals/2

(optional)
-callback handle_cross_silo_signals(Signals :: map(), SiloState :: map()) -> {ok, NewSiloState :: map()}.

init_silo/1

-callback init_silo(Config :: map()) -> {ok, SiloState :: map()} | {error, Reason :: term()}.

Functions

asymmetric_ema_smooth(NewValue, PreviousValue, BaseMomentum, EscalationFactor, DeescalationOffset)

-spec asymmetric_ema_smooth(NewValue :: float(),
                            PreviousValue :: float(),
                            BaseMomentum :: float(),
                            EscalationFactor :: float(),
                            DeescalationOffset :: float()) ->
                               float().

Apply asymmetric EMA smoothing for fast escalation, slow de-escalation.

When escalating (new value higher): use low momentum (fast response) When de-escalating (new value lower): use high momentum (slow recovery)

This prevents oscillation while ensuring responsive intervention.

clamp(Value, Min, Max)

-spec clamp(Value :: number(), Min :: number(), Max :: number()) -> number().

Clamp a value to a specified range.

compute_stagnation_severity(AvgVelocity, VelocityThreshold)

-spec compute_stagnation_severity(AvgVelocity :: float(), VelocityThreshold :: float()) -> float().

Compute stagnation severity from velocity.

Severity = clamp((threshold - avg_velocity) / threshold, 0.0, 1.0)

Returns 0.0 = healthy, 1.0 = critical stagnation.

compute_velocity(CurrentFitness, CurrentEvals, PrevFitness, PrevEvals)

-spec compute_velocity(CurrentFitness :: float(),
                       CurrentEvals :: non_neg_integer(),
                       PrevFitness :: float(),
                       PrevEvals :: non_neg_integer()) ->
                          float().

Compute improvement velocity from checkpoints.

Velocity = (delta_fitness / delta_evaluations) * 1000

Returns velocity in fitness improvement per 1000 evaluations.

ema_smooth(NewValue, PreviousValue, Momentum)

-spec ema_smooth(NewValue :: float(), PreviousValue :: float(), Momentum :: float()) -> float().

Apply exponential moving average smoothing.

SmoothedValue = Momentum * PreviousValue + (1 - Momentum) * NewValue

Higher momentum = smoother but slower response.

normalize(Value, Min, Max)

-spec normalize(Value :: number(), Min :: number(), Max :: number()) -> float().

Normalize a value to [0,1] range given min/max bounds.