Skip to main content

StateDerivatives

Struct StateDerivatives 

Source
pub struct StateDerivatives<const N: usize> {
    pub grad: [f64; N],
    pub hessian: [f64; N],
    pub hessian_full: [[f64; N]; N],
    pub fwd: [f64; N],
    pub bwd: [f64; N],
}
Expand description

Derivatives of the value function at a state.

  • grad[i] is the centered first derivative dV/dx_i.
  • hessian[i] is the diagonal second derivative d^2V/dx_i^2.
  • hessian_full[i][j] is the symmetric mixed second derivative d^2V/dx_i dx_j; its diagonal hessian_full[i][i] equals hessian[i].
  • fwd[i] is the forward difference (V(x + h_i e_i) - V(x)) / h_i.
  • bwd[i] is the backward difference (V(x) - V(x - h_i e_i)) / h_i.

Continuous controls consume grad/hessian (and hessian_full when their noise is correlated across coordinates); jump controls (e.g. market making on a discrete inventory) consume fwd/bwd. The diagonal hessian and the full matrix are kept consistent: constructors that take only a diagonal fill hessian_full with zeros off the diagonal.

Fields§

§grad: [f64; N]§hessian: [f64; N]§hessian_full: [[f64; N]; N]§fwd: [f64; N]§bwd: [f64; N]

Implementations§

Source§

impl<const N: usize> StateDerivatives<N>

Source

pub fn new(grad: [f64; N], hessian: [f64; N]) -> Self

Construct a derivative bundle from first and diagonal second derivatives, with zero directional differences and zero off-diagonal Hessian.

§Examples
use solver::models::control::StateDerivatives;
let d = StateDerivatives::new([0.1], [-0.02]);
assert_eq!(d.grad, [0.1]);
assert_eq!(d.hessian, [-0.02]);
assert_eq!(d.fwd, [0.0]);
assert_eq!(d.hessian_full, [[-0.02]]);
Source

pub fn with_directional( grad: [f64; N], hessian: [f64; N], fwd: [f64; N], bwd: [f64; N], ) -> Self

Construct a derivative bundle from all four components, with zero off-diagonal Hessian.

Source

pub fn with_full_hessian( grad: [f64; N], hessian_full: [[f64; N]; N], fwd: [f64; N], bwd: [f64; N], ) -> Self

Construct a derivative bundle with an explicit full symmetric Hessian.

hessian_full[i][j] must equal hessian_full[j][i]; the diagonal is taken from hessian_full[i][i] and the hessian diagonal is kept in sync.

§Examples
use solver::models::control::StateDerivatives;
let d = StateDerivatives::<2>::with_full_hessian(
    [1.0, 2.0],
    [[0.5, 0.25], [0.25, -0.5]],
    [3.0, 4.0],
    [5.0, 6.0],
);
assert_eq!(d.hessian, [0.5, -0.5]);
assert_eq!(d.hessian_full[0][1], 0.25);
assert_eq!(d.hessian_full[1][0], 0.25);

Trait Implementations§

Source§

impl<const N: usize> Clone for StateDerivatives<N>

Source§

fn clone(&self) -> StateDerivatives<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for StateDerivatives<N>

Source§

impl<const N: usize> Debug for StateDerivatives<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for StateDerivatives<N>
where [f64; N]: Freeze, [[f64; N]; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for StateDerivatives<N>
where [f64; N]: RefUnwindSafe, [[f64; N]; N]: RefUnwindSafe,

§

impl<const N: usize> Send for StateDerivatives<N>
where [f64; N]: Send, [[f64; N]; N]: Send,

§

impl<const N: usize> Sync for StateDerivatives<N>
where [f64; N]: Sync, [[f64; N]; N]: Sync,

§

impl<const N: usize> Unpin for StateDerivatives<N>
where [f64; N]: Unpin, [[f64; N]; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for StateDerivatives<N>
where [f64; N]: UnsafeUnpin, [[f64; N]; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for StateDerivatives<N>
where [f64; N]: UnwindSafe, [[f64; N]; N]: UnwindSafe,

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

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

§

fn vzip(self) -> V