Skip to main content

EventFeedbackConfig

The EventFeedbackConfig dataclass defines parameters for event-triggered feedback stimulation. Each in-game event (enemy kills, damage, armor pickup, etc.) can have its own feedback configuration that dynamically scales stimulation parameters based on TD error magnitude.

Core Parameters

channels
List[int]
required
List of channel indices to stimulate when this event occurs. Each event should use a unique set of channels to provide distinct feedback signals.
base_frequency
float
required
Base stimulation frequency in Hertz (Hz). This is the baseline frequency before any TD error scaling is applied.
base_amplitude
float
required
Base stimulation amplitude in microamps (μA). This is the baseline amplitude before any TD error scaling is applied.
base_pulses
int
required
Base number of pulses to deliver for this event. This is the baseline pulse count before any TD error scaling is applied.
info_key
str
required
Key name used to identify this event in the game info dictionary. Used to trigger the appropriate feedback when events occur.

TD Error Configuration

td_sign
str
default:"positive"
Which TD error signals trigger this feedback:
  • positive: Only trigger on positive TD errors (better than expected)
  • negative: Only trigger on negative TD errors (worse than expected)
  • absolute: Trigger on any TD error magnitude

Frequency Scaling

freq_gain
float
default:"0.9"
Gain multiplier for TD error to frequency scaling. Higher values make frequency more sensitive to TD error magnitude.
freq_max_scale
float
default:"2.0"
Maximum scaling factor for frequency. Final frequency = base_frequency * scale, where scale is clamped to [1.0, freq_max_scale].

Amplitude Scaling

amp_gain
float
default:"0.35"
Gain multiplier for TD error to amplitude scaling. Higher values make amplitude more sensitive to TD error magnitude.
amp_max_scale
float
default:"1.5"
Maximum scaling factor for amplitude. Final amplitude = base_amplitude * scale, where scale is clamped to [1.0, amp_max_scale].

Pulse Count Scaling

pulse_gain
float
default:"0.5"
Gain multiplier for TD error to pulse count scaling. Higher values make pulse count more sensitive to TD error magnitude.
pulse_max_scale
float
default:"2.0"
Maximum scaling factor for pulse count. Final pulses = base_pulses * scale, where scale is clamped to [1.0, pulse_max_scale].

Exponential Moving Average

ema_beta
float
default:"0.99"
Beta parameter for exponential moving average of TD errors. Used to track baseline TD error magnitude for normalization. Higher values (closer to 1.0) result in slower adaptation.

Unpredictable Stimulation

Some events (like taking damage) can optionally include unpredictable background stimulation to enhance learning through temporal contrast.
unpredictable
bool
default:"true"
Whether to add unpredictable background stimulation for this event
unpredictable_frequency
float
default:"5.0"
Frequency (Hz) for unpredictable background stimulation
unpredictable_duration_sec
float
default:"1.0"
Duration in seconds for each unpredictable stimulation burst
unpredictable_rest_sec
float
default:"1.0"
Rest period in seconds between unpredictable stimulation bursts
unpredictable_channels
Optional[List[int]]
default:"None"
Specific channels to use for unpredictable stimulation. If None, uses the same channels as the main event feedback.
unpredictable_amplitude
Optional[float]
default:"None"
Amplitude (μA) for unpredictable stimulation. If None, uses the base_amplitude value.

Default Event Configurations

The PPOConfig.event_feedback_settings dictionary contains these default event configurations:

Usage Example

from ppo_doom import EventFeedbackConfig, PPOConfig

# Create a custom event feedback configuration
custom_event = EventFeedbackConfig(
    channels=[1, 2, 3],
    base_frequency=25.0,
    base_amplitude=2.0,
    base_pulses=40,
    info_key='event_custom',
    td_sign='positive',
    freq_gain=0.3,
    freq_max_scale=2.0,
    amp_gain=0.2,
    amp_max_scale=1.5
)

# Add to PPOConfig
config = PPOConfig(
    event_feedback_settings={
        'custom_event': custom_event
    }
)

# Or modify existing event settings
config = PPOConfig()
config.event_feedback_settings['enemy_kill'].base_frequency = 30.0
config.event_feedback_settings['enemy_kill'].freq_gain = 0.4

TD Error Scaling Formula

The actual stimulation parameters are computed dynamically based on TD error magnitude:
# Normalize TD error by exponential moving average
td_normalized = abs(td_error) / (td_ema + epsilon)

# Compute scaling factors (clamped to [1.0, max_scale])
freq_scale = min(1.0 + freq_gain * td_normalized, freq_max_scale)
amp_scale = min(1.0 + amp_gain * td_normalized, amp_max_scale)
pulse_scale = min(1.0 + pulse_gain * td_normalized, pulse_max_scale)

# Apply scaling
final_frequency = base_frequency * freq_scale
final_amplitude = base_amplitude * amp_scale
final_pulses = int(base_pulses * pulse_scale)
This allows the feedback intensity to adapt based on how surprising the event is to the current policy.