[][src]Struct ml_rust_cuda::learning::instance::Instance

pub struct Instance { /* fields omitted */ }

Implementations

impl Instance[src]

pub fn new(instances: Vec<f32>) -> Self[src]

pub fn from_vector(feature_vec: Vector) -> Self[src]

pub fn normalize(&mut self)[src]

Mutates the feature vector of the instance such that all features are normalized to have a zero mean and unit standard deviation.

Examples

use ml_rust_cuda::{
  learning::Instance,
  math::f32_eq
};

let mut x = Instance::new(vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]);
x.normalize();

println!("{}", x);

pub fn distance(lhs1: &Instance, lhs2: &Instance, p: f32) -> f32[src]

Returns the Lp-distance between two instances (i.e. the p-norm of the difference between the two vectors representing those instances).

Arguments

  • p - A positive 32-bit float.

Examples

use ml_rust_cuda::{
  learning::Instance,
  math::f32_eq
};

let x1 = Instance::new(vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]);
let x2 = Instance::new(vec![3_f32, 8_f32, 1_f32, 2_f32, 3_f32, 1_f32]);

let dist_1 = Instance::distance(&x1, &x2, 1_f32);
let dist_2 = Instance::distance(&x1, &x2, 2_f32);
let dist_3 = Instance::distance(&x1, &x2, 3_f32);

assert!(f32_eq(dist_1, 19_f32));
assert!(f32_eq(dist_2, 97_f32.sqrt()));
assert!(f32_eq(dist_3, 589_f32.cbrt()));

Panics

Panics if p is less than or equal to 0, or if the number of attributes in both instances is not equal.

Trait Implementations

impl Clone for Instance[src]

impl Debug for Instance[src]

impl Display for Instance[src]

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

See Vector.

impl PartialEq<Instance> for Instance[src]

fn eq(&self, other: &Self) -> bool[src]

See Vector.

Auto Trait Implementations

impl RefUnwindSafe for Instance

impl Send for Instance

impl Sync for Instance

impl Unpin for Instance

impl UnwindSafe for Instance

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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