Module Fehu.Space
Observation and action spaces.
Spaces define valid observations and actions for reinforcement learning environments. They specify shapes, constraints, and provide methods to validate, sample, and serialize values.
Each space type corresponds to a common RL scenario: discrete choices, continuous vectors, binary indicators, composite structures, and variable-length sequences.
Structural description
type spec = | Discrete of {}(*Integer choices in [
*)start;start + n - 1].| Box of {}(*Continuous vector bounded per dimension.
*)| Multi_binary of {}(*Binary vector of length
*)n.| Multi_discrete of {}(*Multiple discrete axes with per-axis cardinalities.
*)| Tuple of spec list(*Fixed-length heterogeneous sequence.
*)| Dict of (string * spec) list(*Named fields with different types.
*)| Sequence of {min_length : int;max_length : int option;base : spec;
}(*Variable-length homogeneous sequence.
*)| Text of {}(*Character strings from a fixed alphabet.
*)
Structural description of a space. Two spaces are compatible when their specs are equal.
equal_spec a b is true iff a and b describe structurally identical spaces.
Spaces
The type for spaces over values of type 'a. A space is self-contained: all bounds, constraints, and serialization logic are stored in the value itself.
Operations
val shape : 'a t -> int array optionshape s is the dimensionality of s, if defined. None for scalar or variable-length spaces.
val contains : 'a t -> 'a -> boolcontains s v is true iff v is valid in s.
val sample : 'a t -> 'asample s is a uniformly sampled value from s.
Random keys are drawn from the implicit RNG scope.
unpack s v is Ok x if v can be converted to a valid element of s, or Error msg otherwise.
boundary_values s is a list of representative edge-case values for s. Includes lower/upper bounds or canonical sentinels when known. The empty list when no boundary values apply.
Space types
module Discrete : sig ... endmodule Box : sig ... endmodule Multi_binary : sig ... endmodule Multi_discrete : sig ... endmodule Tuple : sig ... endmodule Dict : sig ... endmodule Sequence : sig ... endmodule Text : sig ... end