StochasticApproximationRootFinder

class StochasticApproximationRootFinder(func: FunctionIfc, interval: Interval, initialPoint: Double = (interval.lowerLimit + interval.upperLimit) / 2.0, scaleFactor: Double = DEFAULT_SCALE_FACTOR, alpha: Double = DEFAULT_ALPHA, maxIterations: Int = DEFAULT_MAX_ITER, desiredPrecision: Double = DEFAULT_PRECISION, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider) : BoundedIterativeProcess<SAStep> , SAStepEmitterIfc, SALifeCycleEmitterIfc(source)

Implements the Robbins-Monroe stochastic approximation root-finding algorithm with Kesten acceleration and an exponentially weighted stopping criterion.

Algorithm

x_{n+1} = xn - scaleFactor * an * f(xn)
an <- 1 / (1/a_{n-1} + 1) [when sign of f(x) changes — Kesten acceleration]
rsc = alpha * rsc + (1 - alpha) * f(x)
stoppingCriteria = |scaleFactor * an * rsc|

Convergence declared when stoppingCriteria < desiredPrecision.

Boundary bounce

Overshoot draws x ~ Uniform from the sub-interval lowerLimit, currentX or currentX, upperLimit using rnStream. If currentX already sits at the violated boundary (degenerate case), the process hard-stops and emits DEGENERATE_BOUNCE.

Observability

  • stepEmitter Emitter — per-iteration snapshots, frequency-gated.

  • lifeCycleEmitter Emitter — unconditional at each lifecycle transition. No SAStep is allocated when nothing is listening and saveSteps is false.

Parameters

func

Function with a sign-change root within interval.

interval

Bracketing search interval.

initialPoint

Starting candidate root. Defaults to interval midpoint.

scaleFactor

Robbins-Monroe step scaling constant. Must be > 0.

alpha

RSC smoothing parameter. Must be in 0.0, 1.0.

maxIterations

Iteration budget. Default: DEFAULT_MAX_ITER.

desiredPrecision

Convergence threshold. Default: DEFAULT_PRECISION.

streamNum

Stream number from streamProvider. 0 = next available, matching the ExponentialRV convention.

streamProvider

Random number stream provider. Default: KSLRandom.DefaultRNStreamProvider.

Constructors

Link copied to clipboard
constructor(func: FunctionIfc, interval: Interval, initialPoint: Double = (interval.lowerLimit + interval.upperLimit) / 2.0, scaleFactor: Double = DEFAULT_SCALE_FACTOR, alpha: Double = DEFAULT_ALPHA, maxIterations: Int = DEFAULT_MAX_ITER, desiredPrecision: Double = DEFAULT_PRECISION, streamNum: Int = 0, streamProvider: RNStreamProviderIfc = KSLRandom.DefaultRNStreamProvider)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Controlled random number stream for all boundary bounce draws. streamNum = 0 requests the next available stream from the provider, matching the convention of ExponentialRV and other KSL random variates.

Link copied to clipboard

When true, every SAStep is appended to the internal list accessible via steps. Independent of stepEmitter — set before calling run.

Link copied to clipboard
Link copied to clipboard

Controls how frequently stepEmitter fires. Value of N emits every Nth step. Does not affect saveSteps accumulation. Validated > 0 on assignment.

Link copied to clipboard

All SAStep instances from the most recent run. Defensive copy.

Link copied to clipboard

Current stopping criterion: |scaleFactor * rmSeries * rsc|. Convergence declared by checkStoppingCondition when this <desiredPrecision.

Functions

Link copied to clipboard
protected open override fun checkStoppingCondition()

Emits CONVERGED and calls stop() when stoppingCriteria < desiredPrecision. Called by IterativeProcess.stoppingConditionCheck() after each step.

Link copied to clipboard
protected open override fun endIterations()

Emits EXHAUSTED when the process ends because all iterations were consumed without convergence. Delegates to super.endIterations() to complete the state-machine transition. Convergence and bounce statuses are emitted at their own sites and do not need re-emission here.

Link copied to clipboard
protected open override fun initializeIterations()

Resets all SA state for a fresh run. super.initializeIterations() resets IterativeProcess bookkeeping and calls setCurrentX(initialPoint), seeding currentX and currentFOfX, before this method reads them.

Link copied to clipboard
protected open override fun nextStep(): SAStep?

Called by IterativeProcess machinery for the Observable notification path. Algorithm state is already advanced by runStep() before this is called; nextStep() here is a pure snapshot factory.

Link copied to clipboard
protected open override fun runStep()

Advances algorithm state, then constructs and routes a snapshot only when a consumer actually needs it.

Link copied to clipboard
open override fun toString(): String