SPSA

Struct SPSA 

Source
pub struct SPSA { /* private fields */ }
Expand description

SPSA (Simultaneous Perturbation Stochastic Approximation) optimizer.

A gradient-free method that estimates gradients using random perturbations. Particularly effective for noisy objective functions (e.g., hardware execution).

§Mathematical Description

$$g_k \approx \frac{f(\theta + c_k \Delta_k) - f(\theta - c_k \Delta_k)}{2 c_k} \Delta_k^{-1}$$

where $\Delta_k$ is a random perturbation vector with ±1 entries.

Implementations§

Source§

impl SPSA

Source

pub fn new() -> Self

Create a new SPSA optimizer.

Source

pub fn with_a(self, a: f64) -> Self

Set the a parameter (step size numerator).

Source

pub fn with_c(self, c: f64) -> Self

Set the c parameter (perturbation size).

Source

pub fn with_a_const(self, a_const: f64) -> Self

Set the stability constant A.

Source

pub fn estimate_gradient<F: ObjectiveFunction>( &self, objective: &F, params: &[f64], iteration: usize, ) -> Vec<f64>

Estimate gradient using simultaneous perturbation.

Trait Implementations§

Source§

impl Default for SPSA

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Optimizer for SPSA

Source§

fn step( &self, params: &mut [f64], gradients: &[f64], iteration: usize, ) -> Result<(), OptimizerError>

Perform a single optimization step. Read more
Source§

fn name(&self) -> &str

Get the optimizer name.
Source§

fn reset(&mut self)

Reset internal state (for optimizers with momentum).
Source§

fn current_learning_rate(&self, _iteration: usize) -> f64

Get current learning rate (may be adaptive).

Auto Trait Implementations§

§

impl Freeze for SPSA

§

impl RefUnwindSafe for SPSA

§

impl Send for SPSA

§

impl Sync for SPSA

§

impl Unpin for SPSA

§

impl UnwindSafe for SPSA

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V