argmin::core

Struct OpWrapper

Source
pub struct OpWrapper<O: ArgminOp> {
    pub op: Option<O>,
    pub cost_func_count: u64,
    pub grad_func_count: u64,
    pub hessian_func_count: u64,
    pub jacobian_func_count: u64,
    pub modify_func_count: u64,
}
Expand description

This wraps an operator and keeps track of how often the cost, gradient and Hessian have been computed and how often the modify function has been called. Usually, this is an implementation detail unless a solver is needed within another solver (such as a line search within a gradient descent method), then it may be necessary to wrap the operator in an OpWrapper.

Fields§

§op: Option<O>

Operator

§cost_func_count: u64

Number of cost function evaluations

§grad_func_count: u64

Number of gradient function evaluations

§hessian_func_count: u64

Number of Hessian function evaluations

§jacobian_func_count: u64

Number of Jacobian function evaluations

§modify_func_count: u64

Number of modify function evaluations

Implementations§

Source§

impl<O: ArgminOp> OpWrapper<O>

Source

pub fn new(op: O) -> Self

Constructor

Source

pub fn new_from_wrapper(op: &mut OpWrapper<O>) -> Self

Construct struct from other OpWrapper. Takes the operator from op (replaces it with None) and crates a new OpWrapper

Source

pub fn apply(&mut self, param: &O::Param) -> Result<O::Output, Error>

Calls the apply method of op and increments cost_func_count.

Source

pub fn gradient(&mut self, param: &O::Param) -> Result<O::Param, Error>

Calls the gradient method of op and increments gradient_func_count.

Source

pub fn hessian(&mut self, param: &O::Param) -> Result<O::Hessian, Error>

Calls the hessian method of op and increments hessian_func_count.

Source

pub fn jacobian(&mut self, param: &O::Param) -> Result<O::Jacobian, Error>

Calls the jacobian method of op and increments jacobian_func_count.

Source

pub fn modify( &mut self, param: &O::Param, extent: O::Float, ) -> Result<O::Param, Error>

Calls the modify method of op and increments modify_func_count.

Source

pub fn take_op(&mut self) -> Option<O>

Moves the operator out of the struct and replaces it with None

Source

pub fn consume_op(&mut self, other: OpWrapper<O>)

Consumes an operator by increasing the function call counts of self by the ones in other.

Source

pub fn consume_func_counts<O2: ArgminOp>(&mut self, other: OpWrapper<O2>)

Adds function evaluation counts of another operator.

Source

pub fn reset(self) -> Self

Reset the cost function counts to zero.

Source

pub fn get_op(self) -> O

Returns the operator op by taking ownership of self.

Trait Implementations§

Source§

impl<O: ArgminOp> ArgminOp for OpWrapper<O>

The OpWrapper should behave just like any other ArgminOp

Source§

type Param = <O as ArgminOp>::Param

Type of the parameter vector
Source§

type Output = <O as ArgminOp>::Output

Output of the operator
Source§

type Hessian = <O as ArgminOp>::Hessian

Type of Hessian
Source§

type Jacobian = <O as ArgminOp>::Jacobian

Type of Jacobian
Source§

type Float = <O as ArgminOp>::Float

Precision of floats
Source§

fn apply(&self, param: &Self::Param) -> Result<Self::Output, Error>

Applies the operator/cost function to parameters
Source§

fn gradient(&self, param: &Self::Param) -> Result<Self::Param, Error>

Computes the gradient at the given parameters
Source§

fn hessian(&self, param: &Self::Param) -> Result<Self::Hessian, Error>

Computes the Hessian at the given parameters
Source§

fn jacobian(&self, param: &Self::Param) -> Result<Self::Jacobian, Error>

Computes the Hessian at the given parameters
Source§

fn modify( &self, param: &Self::Param, extent: Self::Float, ) -> Result<Self::Param, Error>

Modifies a parameter vector. Comes with a variable that indicates the “degree” of the modification.
Source§

impl<O: Clone + ArgminOp> Clone for OpWrapper<O>

Source§

fn clone(&self) -> OpWrapper<O>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<O: Debug + ArgminOp> Debug for OpWrapper<O>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<O: Default + ArgminOp> Default for OpWrapper<O>

Source§

fn default() -> OpWrapper<O>

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

impl<'de, O> Deserialize<'de> for OpWrapper<O>
where O: Deserialize<'de> + ArgminOp,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<O> Serialize for OpWrapper<O>
where O: Serialize + ArgminOp,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<O> Freeze for OpWrapper<O>
where O: Freeze,

§

impl<O> RefUnwindSafe for OpWrapper<O>
where O: RefUnwindSafe,

§

impl<O> Send for OpWrapper<O>
where O: Send,

§

impl<O> Sync for OpWrapper<O>
where O: Sync,

§

impl<O> Unpin for OpWrapper<O>
where O: Unpin,

§

impl<O> UnwindSafe for OpWrapper<O>
where O: 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
Source§

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

Source§

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

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,