Struct yata::methods::Momentum

source ·
pub struct Momentum { /* private fields */ }
Expand description

Momentum calculates difference between current value and n-th value back, where n = length

§Parameters

Has a single parameter length: PeriodType

length should be > 0

§Input type

Input type is ValueType

§Output type

Output type is ValueType

§Examples

use yata::prelude::*;
use yata::methods::Momentum;

let mut change = Momentum::new(3, &1.0).unwrap(); // a.k.a. Change => let mut change = Change::new(3);
change.next(&1.0);
change.next(&2.0);
assert_eq!(change.next(&3.0), 2.0);
assert_eq!(change.next(&4.0), 3.0);
assert_eq!(change.next(&2.0), 0.0);

§At length=1 Momentum is the same as Derivative with length=1

use yata::prelude::*;
use yata::methods::Momentum;
use yata::methods::Derivative;

let mut change = Momentum::new(1, &1.0).unwrap();
let mut derivative = Derivative::new(1, &1.0).unwrap();
change.next(&1.0); derivative.next(&1.0);
change.next(&2.0); derivative.next(&2.0);
assert_eq!(change.next(&3.0), derivative.next(&3.0));
assert_eq!(change.next(&4.0), derivative.next(&4.0));
assert_eq!(change.next(&2.0), derivative.next(&2.0));

§Performance

O(1)

§See Also

Rate of Change, Derivative

Trait Implementations§

source§

impl Clone for Momentum

source§

fn clone(&self) -> Momentum

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 Debug for Momentum

source§

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

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

impl<'de> Deserialize<'de> for Momentum

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 Method for Momentum

§

type Params = u8

Method parameters
§

type Input = f64

Input value type
§

type Output = <Momentum as Method>::Input

Output value type
source§

fn new(length: Self::Params, value: &Self::Input) -> Result<Self, Error>

Static method for creating an instance of the method with given parameters and initial value (simply first input value)
source§

fn next(&mut self, value: &Self::Input) -> Self::Output

Generates next output value based on the given input value
source§

fn with_history( parameters: Self::Params, initial_value: &Self::Input ) -> Result<WithHistory<Self, Self::Output>, Error>
where Self: Sized, Self::Output: Debug + Clone,

Creates an instance of the method with given parameters and initial value, wrapped by historical data holder
source§

fn with_last_value( parameters: Self::Params, initial_value: &Self::Input ) -> Result<WithLastValue<Self, Self::Output>, Error>
where Self: Sized, Self::Output: Debug + Clone,

Creates an instance of the method with given parameters and initial value, wrapped by last produced value holder
source§

fn name(&self) -> &str

Returns a name of the method
source§

fn memsize(&self) -> (usize, usize)
where Self: Sized,

👎Deprecated
Returns memory size of the method (size, align)
source§

fn over<S>(&mut self, inputs: S) -> Vec<Self::Output>
where S: Sequence<Self::Input>, Self::Input: Sized, Self: Sized,

Iterates the Method over the given inputs slice and returns Vec of output values. Read more
source§

fn apply<T, S>(&mut self, sequence: &mut S)
where S: Sequence<T> + AsMut<[T]> + ?Sized, Self: Method<Input = T, Output = T> + Sized,

Applies method to the sequence in-place.
source§

fn new_over<S>( parameters: Self::Params, inputs: S ) -> Result<Vec<Self::Output>, Error>
where S: Sequence<Self::Input>, Self::Input: Sized, Self: Sized,

Creates new Method instance and iterates it over the given inputs slice and returns Vec of output values. Read more
source§

fn new_apply<T, S>( parameters: Self::Params, sequence: &mut S ) -> Result<(), Error>
where S: Sequence<T> + AsMut<[T]>, Self: Method<Input = T, Output = T> + Sized,

Creates new Method instance and applies it to the sequence.
source§

fn into_fn<'a>( self ) -> Box<dyn FnMut(&'a <Self as Method>::Input) -> <Self as Method>::Output>
where Self: Sized + 'static, Self::Input: 'static,

Creates a function from the Method instance
source§

fn new_fn( params: Self::Params, initial_value: &Self::Input ) -> Result<Box<dyn FnMut(&'_ <Self as Method>::Input) -> <Self as Method>::Output>, Error>
where Self: Sized + 'static,

Creates new function based on the method
source§

impl Serialize for Momentum

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§

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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,