Utilities for encoding agent states into vectors for ML models

Constructors

Properties

MAX_NEIGHBORS: 10 = 10
PROPERTY_KEYS: string[] = ...

Methods

  • Decode action tensor back to AgentAction interface

    Parameters

    • actionTensor: Tensor<Rank>

      Output tensor from ML model

    Returns any

    Decoded agent action

  • Create a batch of state encodings for efficient processing

    Parameters

    Returns Tensor<Rank>

    Batched tensor for all states

  • Encode neighboring agents into fixed-size representation

    Parameters

    • neighbors: Agent[]

      Array of neighboring agents

    Returns number[]

    Fixed-size array representing neighbor information

  • Encode position into normalized coordinates

    Parameters

    Returns number[]

    Array of normalized x, y coordinates

  • Encode agent properties into fixed-size vector

    Parameters

    • props: Record<string, number>

      Agent properties map

    Returns number[]

    Array of property values, normalized to [0, 1]

  • Encode relative position between agents

    Parameters

    • neighborPos: Position

      Position of the neighbor

    • referencePos: Position = ...

      Reference position (default origin)

    Returns number[]

    Normalized relative position [-1, 1]

  • Encode complete agent state into a fixed-size vector

    Parameters

    Returns Tensor<Rank>

    Tensorflow tensor representing the state

  • Calculate the total size of the encoded state vector

    Returns number

    Number of features in encoded state

  • Validate that state contains required fields for encoding

    Parameters

    Returns boolean

    True if state is valid for encoding