/** * Agentic QE v3 - Prioritized Experience Replay Buffer * ADR-034: RL-based swarm topology optimization * * Implements prioritized experience replay for stable RL training: * - Priority based on TD error (higher error = more learning potential) * - Proportional prioritization with importance sampling * - Circular buffer with configurable capacity */ import type { Experience, IReplayBuffer } from './types'; /** * Prioritized Experience Replay Buffer * * Features: * - Priority based on TD error magnitude * - Proportional prioritization with sum tree * - Importance sampling weights for bias correction */ export declare class PrioritizedReplayBuffer implements IReplayBuffer { /** Experience storage */ private buffer; /** Sum tree for priority sampling */ private sumTree; /** Buffer capacity */ private readonly capacity; /** Current number of experiences */ private count; /** Write position */ private writeIdx; /** Priority exponent (alpha): how much to use priorities */ private readonly alpha; /** Importance sampling exponent (beta): bias correction */ private beta; /** Beta annealing rate */ private readonly betaAnnealing; /** Small constant to ensure non-zero priority */ private readonly priorityEpsilon; /** Maximum priority seen */ private maxPriority; constructor(capacity: number, options?: { alpha?: number; beta?: number; betaAnnealing?: number; }); /** * Get buffer length */ get length(): number; /** * Add experience to buffer * * New experiences get max priority to ensure they're sampled at least once */ push(experience: Experience): void; /** * Convert TD error to priority value */ private getPriorityFromTdError; /** * Sample experiences using proportional prioritization * * @param batchSize - Number of experiences to sample * @returns Array of experiences with importance sampling weights */ sample(batchSize: number): Experience[]; /** * Sample with importance sampling weights for bias correction */ sampleWithWeights(batchSize: number): { experiences: Experience[]; weights: number[]; indices: number[]; }; /** * Update priorities for sampled experiences * * Called after computing new TD errors during training */ updatePriorities(indices: number[], priorities: number[]): void; /** * Clear all experiences */ clear(): void; /** * Get current beta value */ getBeta(): number; /** * Get buffer statistics */ getStats(): { count: number; capacity: number; totalPriority: number; maxPriority: number; beta: number; }; } /** * Simple uniform sampling replay buffer * * Use when prioritized replay is not needed */ export declare class UniformReplayBuffer implements IReplayBuffer { private buffer; private readonly capacity; constructor(capacity: number); get length(): number; push(experience: Experience): void; sample(batchSize: number): Experience[]; updatePriorities(_indices: number[], _priorities: number[]): void; clear(): void; } /** * Create a prioritized replay buffer */ export declare function createPrioritizedReplayBuffer(capacity: number, options?: { alpha?: number; beta?: number; betaAnnealing?: number; }): PrioritizedReplayBuffer; /** * Create a uniform replay buffer */ export declare function createUniformReplayBuffer(capacity: number): UniformReplayBuffer; //# sourceMappingURL=replay-buffer.d.ts.map