larvaworld.lib.model.modules.sensor
Classes
Base sensor module for agent sensory processing. |
|
Olfactory sensor module for odor detection and chemotaxis. |
|
Tactile sensor module for contact detection. |
|
Wind sensor module for air flow detection. |
|
Temperature sensor module for thermal gradient detection. |
|
Olfactory Sensory Neuron (OSN) olfactor with Brian2 neural simulation. |
Module Contents
- class larvaworld.lib.model.modules.sensor.Sensor(brain: Any | None = None, **kwargs: Any)
Bases:
larvaworld.lib.model.modules.basic.EffectorBase sensor module for agent sensory processing.
Abstract base class providing sensory input processing with gain control, temporal dynamics (decay), and optional memory integration. Supports multiple perception modes (log, linear, null) for sensory transduction.
- Attributes:
output_range: Valid output range for sensor activation (-1 to 1) perception: Sensory transduction mode (‘log’, ‘linear’, or ‘null’) decay_coef: Linear decay coefficient for sensory activation brute_force: If True, apply direct locomotor modulation (bypass normal output) gain_dict: Dictionary mapping stimulus IDs to gain coefficients brain: Parent brain instance (for locomotor access) X: Current sensory input values per stimulus ID dX: Perceived sensory changes per stimulus ID gain: Current gain coefficients per stimulus ID
- Args:
- brain: Parent brain instance (polymorphic: Brain or subclasses).
Provides access to locomotor for brute_force modulation
**kwargs: Additional keyword arguments passed to parent Effector
- Example:
>>> sensor = Sensor(brain=my_brain, decay_coef=0.1, perception='log') >>> sensor.step(input={'odor1': 0.5, 'odor2': 0.3})
- output_range
- perception
- decay_coef
- brute_force
- gain_dict
- brain = None
- exp_decay_coef
- X
- dX
- gain
- compute_dif(input: Any) None
- update_gain_via_memory(mem: Any | None = None, **kwargs: Any) None
- update() None
- affect_locomotion(L: Any) None
- get_dX() dict[str, float]
- get_X_values(t: float, N: int) list[float]
- get_gain() dict[str, float]
- set_gain(value: float, gain_id: str) None
- reset_gain(gain_id: str) None
- reset_all_gains() None
- compute_single_dx(cur: float, prev: float) float
- compute_dX(input: dict[str, float]) None
- add_novel_gain(id: str, con: float = 0.0, gain: float = 0.0) None
- property gain_ids: list[str]
- class larvaworld.lib.model.modules.sensor.Olfactor(**kwargs: Any)
Bases:
SensorOlfactory sensor module for odor detection and chemotaxis.
Extends base Sensor with olfaction-specific locomotor modulation. When negative gradients detected and stride completes, probabilistically triggers locomotor interruption (reorientation behavior).
- Attributes:
Inherits all Sensor attributes Provides odor concentration and change properties for first/second odors
- Example:
>>> olfactor = Olfactor(brain=my_brain, decay_coef=0.15, perception='log') >>> olfactor.step(input={'odor_A': 0.6, 'odor_B': 0.2}) >>> print(f"First odor: {olfactor.first_odor_concentration}")
- affect_locomotion(L: Any) None
- property first_odor_concentration: float
- property second_odor_concentration: float
- property first_odor_concentration_change: float
- property second_odor_concentration_change: float
- class larvaworld.lib.model.modules.sensor.Toucher(**kwargs: Any)
Bases:
SensorTactile sensor module for contact detection.
Extends base Sensor with touch-specific locomotor modulation. Triggers locomotion on contact detection (+1) and interrupts on contact loss (-1). Uses multiple sensor points around body contour.
- Attributes:
initial_gain: Initial tactile sensitivity coefficient (default: 40.0) touch_sensors: List of sensor location indices around body contour
- Example:
>>> toucher = Toucher(brain=my_brain, initial_gain=40.0, touch_sensors=[0, 5, 10]) >>> toucher.step(input={'sensor_0': 1, 'sensor_5': 0})
- initial_gain
- touch_sensors
- affect_locomotion(L: Any) None
- class larvaworld.lib.model.modules.sensor.Windsensor(weights: Any, **kwargs: Any)
Bases:
SensorWind sensor module for air flow detection.
Extends base Sensor for wind stimulus processing with fixed gain and null perception mode (direct transduction without adaptation).
- Attributes:
gain_dict: Fixed gain for wind sensor (default: 1.0) perception: Fixed to ‘null’ mode (direct input) weights: Wind response weight coefficients (polymorphic structure)
- Example:
>>> windsensor = Windsensor(weights=wind_weights, brain=my_brain) >>> windsensor.step(input={'windsensor': 0.7})
- gain_dict
- perception
- weights
- class larvaworld.lib.model.modules.sensor.Thermosensor(**kwargs: Any)
Bases:
SensorTemperature sensor module for thermal gradient detection.
Extends base Sensor for thermotaxis with separate warm/cool sensory channels. Provides dual-channel temperature perception for thermal navigation behaviors.
- Attributes:
gain_dict: Gains for warm and cool sensors (default: both 1.0) Properties for warm/cool sensor inputs, perceptions, and gains
- Example:
>>> thermosensor = Thermosensor(brain=my_brain, decay_coef=0.1) >>> thermosensor.step(input={'warm': 0.4, 'cool': 0.6}) >>> print(f"Warm gain: {thermosensor.warm_gain}")
- gain_dict
- property warm_sensor_input: float
- property warm_sensor_perception: float
- property cool_sensor_input: float
- property cool_sensor_perception: float
- property cool_gain: float
- property warm_gain: float
- class larvaworld.lib.model.modules.sensor.OSNOlfactor(response_key: str = 'OSN_rate', server_host: str = 'localhost', server_port: int = 5795, remote_dt: int = 100, remote_warmup: int = 500, **kwargs: Any)
Bases:
OlfactorOlfactory Sensory Neuron (OSN) olfactor with Brian2 neural simulation.
Extends Olfactor with biologically realistic OSN dynamics via remote Brian2 server. Converts odor concentrations to neural spike rates through detailed OSN model, then applies sigmoid normalization.
- Attributes:
brianInterface: Remote Brian2 model interface for OSN simulation brian_warmup: Warmup steps for neural model initialization response_key: Key for extracting response from Brian2 model (default: ‘OSN_rate’) remote_dt: Time step for remote Brian2 simulation (ms) agent_id: Unique agent identifier for Brian2 tracking sim_id: Unique simulation identifier for Brian2 tracking
- Args:
response_key: Brian2 response parameter to extract (default: ‘OSN_rate’) server_host: Brian2 server hostname (default: ‘localhost’) server_port: Brian2 server port (default: 5795) remote_dt: Brian2 simulation time step in ms (default: 100) remote_warmup: Brian2 warmup steps before data collection (default: 500) **kwargs: Additional keyword arguments passed to parent Olfactor
- Example:
>>> osn_olfactor = OSNOlfactor( ... brain=my_brain, ... server_host='localhost', ... server_port=5795, ... remote_dt=100 ... ) >>> osn_olfactor.step(input={'odor_A': 0.8})
- brianInterface
- brian_warmup = 500
- response_key = 'OSN_rate'
- remote_dt = 100
- agent_id = ''
- sim_id = ''
- normalized_sigmoid(a: float, b: float, x: float) float
Returns array of a horizontal mirrored normalized sigmoid function output between 0 and 1 Function parameters a = center; b = width
- update() None