Skip to main content

FeatureVectorBuilder

Struct FeatureVectorBuilder 

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

Builder for FeatureVector.

§Example

use fin_primitives::ml::{FeatureVectorBuilder, Normalization};

let fv = FeatureVectorBuilder::new(Normalization::ZScore)
    .add("rsi", 55.3).unwrap()
    .add("adx", 28.1).unwrap()
    .add("hurst", 0.6).unwrap()
    .build();

assert_eq!(fv.len(), 3);
let normalized: Vec<f64> = fv.into();
assert_eq!(normalized.len(), 3);

Implementations§

Source§

impl FeatureVectorBuilder

Source

pub fn new(normalization: Normalization) -> Self

Creates a new builder with the specified normalization mode.

Source

pub fn add(self, name: impl Into<String>, value: f64) -> Result<Self, FinError>

Adds a named feature with a raw f64 value.

§Errors

Returns FinError::InvalidInput if:

  • name is empty or contains only whitespace.
  • A feature with the same name already exists.
Source

pub fn add_all(self, features: &[(&str, f64)]) -> Result<Self, FinError>

Adds multiple features from a slice of (name, value) pairs.

§Errors

Propagates errors from Self::add.

Source

pub fn build(self) -> FeatureVector

Finalizes the builder and returns a FeatureVector.

Trait Implementations§

Source§

impl Debug for FeatureVectorBuilder

Source§

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

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

impl Default for FeatureVectorBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.