agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
72 lines • 2.75 kB
TypeScript
import * as tf from '@tensorflow/tfjs';
import { Position } from '../types/core';
import { Agent } from '../core/agents/Agent';
import { MLAgentState, EnvironmentContext } from './interfaces';
/**
* Utilities for encoding agent states into vectors for ML models
*/
export declare class StateEncoder {
private static readonly MAX_NEIGHBORS;
private static readonly PROPERTY_KEYS;
/**
* Encode complete agent state into a fixed-size vector
* @param state Agent state to encode
* @returns Tensorflow tensor representing the state
*/
static encodeState(state: MLAgentState): tf.Tensor;
/**
* Encode position into normalized coordinates
* @param pos Position to encode
* @returns Array of normalized x, y coordinates
*/
static encodePosition(pos: Position): number[];
/**
* Encode agent properties into fixed-size vector
* @param props Agent properties map
* @returns Array of property values, normalized to [0, 1]
*/
static encodeProperties(props: Record<string, number>): number[];
/**
* Encode environmental context
* @param env Environment context
* @returns Array of environmental features
*/
static encodeEnvironment(env: EnvironmentContext): number[];
/**
* Encode neighboring agents into fixed-size representation
* @param neighbors Array of neighboring agents
* @returns Fixed-size array representing neighbor information
*/
static encodeNeighbors(neighbors: Agent[]): number[];
/**
* Encode relative position between agents
* @param neighborPos Position of the neighbor
* @param referencePos Reference position (default origin)
* @returns Normalized relative position [-1, 1]
*/
static encodeRelativePosition(neighborPos: Position, referencePos?: Position): number[];
/**
* Calculate the total size of the encoded state vector
* @returns Number of features in encoded state
*/
static getStateVectorSize(): number;
/**
* Decode action tensor back to AgentAction interface
* @param actionTensor Output tensor from ML model
* @returns Decoded agent action
*/
static decodeAction(actionTensor: tf.Tensor): any;
/**
* Create a batch of state encodings for efficient processing
* @param states Array of agent states
* @returns Batched tensor for all states
*/
static encodeBatch(states: MLAgentState[]): tf.Tensor;
/**
* Validate that state contains required fields for encoding
* @param state State to validate
* @returns True if state is valid for encoding
*/
static validateState(state: MLAgentState): boolean;
}
//# sourceMappingURL=StateEncoder.d.ts.map