explicit_observer
RL4CRN.env2agent_interface.explicit_observer
Explicit observer.
This module defines ExplicitObserver, an observer that constructs an
explicit, vector-based representation of an IOCRN state. The representation is
based on:
- which reactions are currently present (multi-hot over reaction IDs),
- the current reaction parameters placed into a fixed parameter vector,
- optionally, a multi-hot encoding of which input channels control which controllable parameters.
The observer is intended for use in the env2agent interface, where an environment state (IOCRN) is mapped to an observation suitable for subsequent tensorization and policy evaluation.
ExplicitObserver
Bases: AbstractObserver
Observer producing an explicit IOCRN representation as numpy arrays.
| PARAMETER | DESCRIPTION |
|---|---|
reaction_library
|
Reaction library used to define the observation space. The observer assumes the library provides:
|
allow_input_observation
|
If True, the observation additionally includes an
input-control multi-hot encoding (see
DEFAULT:
|
Notes
This observer stores the most recent IOCRN passed to observe in
self.iocrn and uses it internally when constructing the encodings.
observe(iocrn)
Construct an explicit observation for the given IOCRN.
The returned observation is a tuple of numpy arrays:
reaction_multihot: multi-hot encoding indicating which reactions from the library are present in the IOCRN. Shape(M,), whereM = len(reaction_library).params_cross_multihot: parameter vector containing the current reaction parameters placed into a fixed global layout defined byreaction_library.parameter_lookup_table. Shape(P,), whereP = reaction_library.get_num_parameters().- optionally,
inputs_multihot(only ifallow_input_observation=True): concatenated multi-hot vectors describing which controllable parameters are controlled by each input channel. Shape(num_inputs * C,), whereC = reaction_library.get_num_controllable_parameters().
| PARAMETER | DESCRIPTION |
|---|---|
iocrn
|
IOCRN-like object providing at least:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Tuple of numpy arrays:
|
reactions_to_multihot()
Encode present reactions as a multi-hot vector.
Uses self.iocrn.gather_reaction_IDs() to obtain the set of reaction IDs
present in the IOCRN and sets the corresponding entries to 1.
| RETURNS | DESCRIPTION |
|---|---|
|
Numpy array of shape |
params_cross_multihot()
Place reaction parameters into a fixed global parameter vector.
For each reaction in self.iocrn.reactions, parameters are copied into a
global vector at offsets determined by
reaction_library.parameter_lookup_table[reaction.ID].
| RETURNS | DESCRIPTION |
|---|---|
|
Numpy array of shape |
inputs_to_multihot()
Encode which inputs control which controllable reaction parameters.
For each input channel i in the IOCRN, this method creates a multi-hot
vector over the global controllable-parameter layout of the reaction
library. A position is set to 1 if the corresponding controllable
parameter is controlled by input i, based on matching
reaction.input_channels[j] to self.iocrn.input_labels[i].
The per-input vectors are concatenated into a single vector.
| RETURNS | DESCRIPTION |
|---|---|
|
Numpy array of shape
|