Skip to main content

Module stochastic

Module stochastic 

Source
Expand description

Stochastic optimization via Sample-Average Approximation (SAA).

Given an objective f(x, xi) that depends on random parameters xi, SAA draws N scenarios and solves:

min_x (1/N) sum_{s=1}^{N} f(x, xi_s)

Chance constraints P{g(x, xi) <= 0} >= alpha are enforced via a smooth quadratic penalty relaxation.

§Example

use numra_optim::stochastic::StochasticProblem;

let result = StochasticProblem::new(1)
    .x0(&[0.0])
    .objective(|x: &[f64], p: &[f64]| (x[0] - p[0]) * (x[0] - p[0]))
    .param_normal("xi", 5.0, 1.0)
    .n_samples(200)
    .solve()
    .unwrap();

assert!((result.x[0] - 5.0).abs() < 0.5);

Author: Moussa Leblouba Date: 9 February 2026 Modified: 2 May 2026

Structs§

StochasticOptions
Options for stochastic optimization.
StochasticParam
A stochastic parameter with a sampling function.
StochasticProblem
Declarative builder for stochastic optimization problems.
StochasticResult
Result of stochastic optimization.

Functions§

param_normal
Create a normally distributed stochastic parameter.
param_sampled
Create a stochastic parameter with a custom sampling closure.
param_uniform
Create a uniformly distributed stochastic parameter.