Skip to content

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:

  • __len__() giving the number of reactions in the library
  • get_num_parameters() returning the size of the global parameter vector
  • parameter_lookup_table mapping reaction.ID to the parameter offset
  • get_num_controllable_parameters() returning the size of the global controllable-parameter vector
  • controllable_parameter_lookup_table mapping reaction.ID to the controllable-parameter offset

allow_input_observation

If True, the observation additionally includes an input-control multi-hot encoding (see inputs_to_multihot).

DEFAULT: False

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,), where M = len(reaction_library).
  • params_cross_multihot: parameter vector containing the current reaction parameters placed into a fixed global layout defined by reaction_library.parameter_lookup_table. Shape (P,), where P = reaction_library.get_num_parameters().
  • optionally, inputs_multihot (only if allow_input_observation=True): concatenated multi-hot vectors describing which controllable parameters are controlled by each input channel. Shape (num_inputs * C,), where C = reaction_library.get_num_controllable_parameters().
PARAMETER DESCRIPTION
iocrn

IOCRN-like object providing at least:

  • gather_reaction_IDs() returning reaction IDs present in the IOCRN
  • reactions: iterable of reaction objects with fields:

    • ID
    • num_parameters
    • params
    • get_num_controllable_parameters()
    • input_channels
    • num_inputs
    • input_labels

RETURNS DESCRIPTION

Tuple of numpy arrays:

  • (reaction_multihot, params_cross_multihot) if input observation is disabled.
  • (reaction_multihot, params_cross_multihot, inputs_multihot) if input observation is enabled.

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 (len(reaction_library),) with entries in {0, 1}.

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 (reaction_library.get_num_parameters(),) where entries corresponding to active reaction parameters contain their numeric values and all other entries are zero.

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 (self.iocrn.num_inputs * reaction_library.get_num_controllable_parameters(),) with entries in {0, 1}.