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 derivativedV/dx_i.hessian[i]is the diagonal second derivatived^2V/dx_i^2.hessian_full[i][j]is the symmetric mixed second derivatived^2V/dx_i dx_j; its diagonalhessian_full[i][i]equalshessian[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>
impl<const N: usize> StateDerivatives<N>
Sourcepub fn new(grad: [f64; N], hessian: [f64; N]) -> Self
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]]);Sourcepub fn with_directional(
grad: [f64; N],
hessian: [f64; N],
fwd: [f64; N],
bwd: [f64; N],
) -> Self
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.
Sourcepub fn with_full_hessian(
grad: [f64; N],
hessian_full: [[f64; N]; N],
fwd: [f64; N],
bwd: [f64; N],
) -> Self
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>
impl<const N: usize> Clone for StateDerivatives<N>
Source§fn clone(&self) -> StateDerivatives<N>
fn clone(&self) -> StateDerivatives<N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<const N: usize> Copy for StateDerivatives<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for StateDerivatives<N>
impl<const N: usize> RefUnwindSafe for StateDerivatives<N>
impl<const N: usize> Send for StateDerivatives<N>
impl<const N: usize> Sync for StateDerivatives<N>
impl<const N: usize> Unpin for StateDerivatives<N>
impl<const N: usize> UnsafeUnpin for StateDerivatives<N>
impl<const N: usize> UnwindSafe for StateDerivatives<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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