Vector

Struct Vector 

Source
pub struct Vector<T> { /* private fields */ }
Expand description

The Vector struct.

Can be instantiated with any type.

Implementations§

Source§

impl<T> Vector<T>

Source

pub fn new<U>(data: U) -> Vector<T>
where U: Into<Vec<T>>,

Constructor for Vector struct.

Requires the vector data.

§Examples
use rulinalg::vector::Vector;

let vec = Vector::new(vec![1.0,2.0,3.0,4.0]);
Examples found in repository?
examples/svm-sign_learner.rs (lines 26-29)
17fn main() {
18    println!("Sign learner sample:");
19
20    println!("Training...");
21    // Training data
22    let inputs = Matrix::new(11, 1, vec![
23                             -0.1, -2., -9., -101., -666.7,
24                             0., 0.1, 1., 11., 99., 456.7
25                             ]);
26    let targets = Vector::new(vec![
27                              -1., -1., -1., -1., -1.,
28                              1., 1., 1., 1., 1., 1.
29                              ]);
30
31    // Trainee
32    let mut svm_mod = SVM::new(HyperTan::new(100., 0.), 0.3);
33    // Our train function returns a Result<(), E>
34    svm_mod.train(&inputs, &targets).unwrap();
35
36    println!("Evaluation...");
37    let mut hits = 0;
38    let mut misses = 0;
39    // Evaluation
40    //   Note: We could pass all input values at once to the `predict` method!
41    //         Here, we use a loop just to count and print logs.
42    for n in (-1000..1000).filter(|&x| x % 100 == 0) {
43        let nf = n as f64;
44        let input = Matrix::new(1, 1, vec![nf]);
45        let out = svm_mod.predict(&input).unwrap();
46        let res = if out[0] * nf > 0. {
47            hits += 1;
48            true
49        } else if nf == 0. {
50            hits += 1;
51            true
52        } else {
53            misses += 1;
54            false
55        };
56
57        println!("{} -> {}: {}", Matrix::data(&input)[0], out[0], res);
58    }
59
60    println!("Performance report:");
61    println!("Hits: {}, Misses: {}", hits, misses);
62    let hits_f = hits as f64;
63    let total = (hits + misses) as f64;
64    println!("Accuracy: {}", (hits_f / total) * 100.);
65}
Source

pub fn size(&self) -> usize

Returns the size of the Vector.

Source

pub fn data(&self) -> &Vec<T>

Returns a non-mutable reference to the underlying data.

Examples found in repository?
examples/k-means_generating_cluster.rs (line 72)
44fn main() {
45    println!("K-Means clustering example:");
46
47    const SAMPLES_PER_CENTROID: usize = 2000;
48
49    println!("Generating {0} samples from each centroids:",
50             SAMPLES_PER_CENTROID);
51    // Choose two cluster centers, at (-0.5, -0.5) and (0, 0.5).
52    let centroids = Matrix::new(2, 2, vec![-0.5, -0.5, 0.0, 0.5]);
53    println!("{}", centroids);
54
55    // Generate some data randomly around the centroids
56    let samples = generate_data(&centroids, SAMPLES_PER_CENTROID, 0.4);
57
58    // Create a new model with 2 clusters
59    let mut model = KMeansClassifier::new(2);
60
61    // Train the model
62    println!("Training the model...");
63    // Our train function returns a Result<(), E>
64    model.train(&samples).unwrap();
65
66    let centroids = model.centroids().as_ref().unwrap();
67    println!("Model Centroids:\n{:.3}", centroids);
68
69    // Predict the classes and partition into
70    println!("Classifying the samples...");
71    let classes = model.predict(&samples).unwrap();
72    let (first, second): (Vec<usize>, Vec<usize>) = classes.data().iter().partition(|&x| *x == 0);
73
74    println!("Samples closest to first centroid: {}", first.len());
75    println!("Samples closest to second centroid: {}", second.len());
76}
Source

pub fn mut_data(&mut self) -> &mut [T]

Returns a mutable slice of the underlying data.

Source

pub fn into_vec(self) -> Vec<T>

Consumes the Vector and returns the Vec of data.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the Vector’s data.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutable references to the Vector’s data.

Source§

impl<T> Vector<T>
where T: Copy,

Source

pub fn apply(self, f: &dyn Fn(T) -> T) -> Vector<T>

Applies a function to each element in the vector.

§Examples
use rulinalg::vector::Vector;
fn add_two(a: f64) -> f64 {
    a + 2f64
}

let a = Vector::new(vec![0.;4]);

let b = a.apply(&add_two);

assert_eq!(b.into_vec(), vec![2.0; 4]);
Source§

impl<T> Vector<T>
where T: Copy + PartialOrd,

Source

pub fn argmax(&self) -> (usize, T)

Find the argmax of the Vector.

Returns the index of the largest value in the vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,0.0,5.0]);
let b = a.argmax();
assert_eq!(b.0, 3);
assert_eq!(b.1, 5.0);
Source

pub fn argmin(&self) -> (usize, T)

Find the argmin of the Vector.

Returns the index of the smallest value in the vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,0.0,5.0]);
let b = a.argmin();
assert_eq!(b.0, 2);
assert_eq!(b.1, 0.0);
Source

pub fn select(&self, idxs: &[usize]) -> Vector<T>

Select elements from the Vector and form a new Vector from them.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,3.0,4.0,5.0]);

let a_lower = a.select(&[2,3,4]);

// Prints [3,4,5]
println!("{:?}", a_lower.data());
Source§

impl<T> Vector<T>
where T: Clone + Zero,

Source

pub fn zeros(size: usize) -> Vector<T>

Constructs Vector of all zeros.

Requires the size of the vector.

§Examples
use rulinalg::vector::Vector;

let vec = Vector::<f64>::zeros(10);
Source§

impl<T> Vector<T>
where T: Clone + One,

Source

pub fn ones(size: usize) -> Vector<T>

Constructs Vector of all ones.

Requires the size of the vector.

§Examples
use rulinalg::vector::Vector;

let vec = Vector::<f64>::ones(10);
Source§

impl<T> Vector<T>
where T: Zero<Output = T> + Mul<Output = T> + Add + Copy,

Source

pub fn dot(&self, v: &Vector<T>) -> T

Compute dot product with specified Vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,3.0,4.0]);
let b = Vector::new(vec![2.0; 4]);

let c = a.dot(&b);
assert_eq!(c, 20.0);
Source§

impl<T> Vector<T>
where T: Copy + Zero<Output = T> + Add,

Source

pub fn sum(&self) -> T

The sum of the vector.

Returns the sum of all elements in the vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,3.0,4.0]);

let c = a.sum();
assert_eq!(c, 10.0);
Source§

impl<T> Vector<T>
where T: Copy + Mul<Output = T>,

Source

pub fn elemul(&self, v: &Vector<T>) -> Vector<T>

The elementwise product of two vectors.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,3.0,4.0]);
let b = Vector::new(vec![1.0,2.0,3.0,4.0]);

let c = &a.elemul(&b);
assert_eq!(*c.data(), vec![1.0, 4.0, 9.0, 16.0]);
Source§

impl<T> Vector<T>
where T: Copy + Div<Output = T>,

Source

pub fn elediv(&self, v: &Vector<T>) -> Vector<T>

The elementwise division of two vectors.

§Examples
use rulinalg::vector::Vector;

let a = Vector::new(vec![1.0,2.0,3.0,4.0]);
let b = Vector::new(vec![1.0,2.0,3.0,4.0]);

let c = &a.elediv(&b);
assert_eq!(*c.data(), vec![1.0; 4]);
Source§

impl<T> Vector<T>
where T: Float + FromPrimitive,

Source

pub fn mean(&self) -> T

The mean of the vector.

Returns the arithmetic mean of the vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::<f32>::new(vec![1.0,2.0,3.0,4.0]);

let c = a.mean();
assert_eq!(c, 2.5);
Source

pub fn variance(&self) -> T

The variance of the vector.

Returns the unbiased sample variance of the vector.

§Examples
use rulinalg::vector::Vector;

let a = Vector::<f32>::new(vec![1.0,2.0,3.0,4.0]);

let c = a.variance();
assert_eq!(c, 5.0/3.0);

Trait Implementations§

Source§

impl<'a, 'b, T> Add<&'b T> for &'a Vector<T>
where T: Copy + Add<Output = T>,

Adds scalar to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, f: &T) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<&'a T> for Vector<T>
where T: Copy + Add<Output = T>,

Adds scalar to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, f: &T) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, 'b, T> Add<&'b Vector<T>> for &'a Vector<T>
where T: Copy + Add<Output = T>,

Adds vector to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, v: &Vector<T>) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<&'a Vector<T>> for Vector<T>
where T: Copy + Add<Output = T>,

Adds vector to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, v: &Vector<T>) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<T> for &'a Vector<T>
where T: Copy + Add<Output = T>,

Adds scalar to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, f: T) -> Vector<T>

Performs the + operation. Read more
Source§

impl<T> Add<T> for Vector<T>
where T: Copy + Add<Output = T>,

Adds scalar to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, f: T) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, T> Add<Vector<T>> for &'a Vector<T>
where T: Copy + Add<Output = T>,

Adds vector to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, v: Vector<T>) -> Vector<T>

Performs the + operation. Read more
Source§

impl<T> Add for Vector<T>
where T: Copy + Add<Output = T>,

Adds vector to vector.

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, v: Vector<T>) -> Vector<T>

Performs the + operation. Read more
Source§

impl<'a, T> AddAssign<&'a T> for Vector<T>
where T: Copy + Add<Output = T>,

Performs addition assignment between a vector and a scalar.

Source§

fn add_assign(&mut self, _rhs: &T)

Performs the += operation. Read more
Source§

impl<'a, T> AddAssign<&'a Vector<T>> for Vector<T>
where T: Copy + Add<Output = T>,

Performs elementwise addition assignment between two vectors.

Source§

fn add_assign(&mut self, _rhs: &Vector<T>)

Performs the += operation. Read more
Source§

impl<T> AddAssign<T> for Vector<T>
where T: Copy + Add<Output = T>,

Performs addition assignment between a vector and a scalar.

Source§

fn add_assign(&mut self, _rhs: T)

Performs the += operation. Read more
Source§

impl<T> AddAssign for Vector<T>
where T: Copy + Add<Output = T>,

Performs elementwise addition assignment between two vectors.

Source§

fn add_assign(&mut self, _rhs: Vector<T>)

Performs the += operation. Read more
Source§

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

Source§

fn clone(&self) -> Vector<T>

Clones the Vector.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl CostFunc<Vector<f64>> for CrossEntropyError

Source§

fn cost(outputs: &Vector<f64>, targets: &Vector<f64>) -> f64

The cost function.
Source§

fn grad_cost(outputs: &Vector<f64>, targets: &Vector<f64>) -> Vector<f64>

The gradient of the cost function.
Source§

impl CostFunc<Vector<f64>> for MeanSqError

Source§

fn cost(outputs: &Vector<f64>, targets: &Vector<f64>) -> f64

The cost function.
Source§

fn grad_cost(outputs: &Vector<f64>, targets: &Vector<f64>) -> Vector<f64>

The gradient of the cost function.
Source§

impl<T> Debug for Vector<T>
where T: Debug,

Source§

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

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

impl<T> Display for Vector<T>
where T: Display,

Source§

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

Displays the Vector.

Source§

impl<'a, 'b, T> Div<&'b T> for &'a Vector<T>
where T: Copy + Zero + PartialEq + Div<Output = T>,

Divides vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the / operator.
Source§

fn div(self, f: &T) -> Vector<T>

Performs the / operation. Read more
Source§

impl<'a, T> Div<&'a T> for Vector<T>
where T: Copy + Zero + PartialEq + Div<Output = T>,

Divides vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the / operator.
Source§

fn div(self, f: &T) -> Vector<T>

Performs the / operation. Read more
Source§

impl<'a, T> Div<T> for &'a Vector<T>
where T: Copy + Zero + PartialEq + Div<Output = T>,

Divides vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the / operator.
Source§

fn div(self, f: T) -> Vector<T>

Performs the / operation. Read more
Source§

impl<T> Div<T> for Vector<T>
where T: Copy + Zero + PartialEq + Div<Output = T>,

Divides vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the / operator.
Source§

fn div(self, f: T) -> Vector<T>

Performs the / operation. Read more
Source§

impl<'a, T> DivAssign<&'a T> for Vector<T>
where T: Copy + Div<Output = T>,

Performs division assignment between a vector and a scalar.

Source§

fn div_assign(&mut self, _rhs: &T)

Performs the /= operation. Read more
Source§

impl<T> DivAssign<T> for Vector<T>
where T: Copy + Div<Output = T>,

Performs division assignment between a vector and a scalar.

Source§

fn div_assign(&mut self, _rhs: T)

Performs the /= operation. Read more
Source§

impl<'a, T> From<&'a [T]> for Vector<T>
where T: Clone,

Source§

fn from(slice: &'a [T]) -> Vector<T>

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Vector<T>

Source§

fn from(vec: Vec<T>) -> Vector<T>

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for Matrix<T>

Source§

fn from(vector: Vector<T>) -> Matrix<T>

Converts to this type from the input type.
Source§

impl<T> Hash for Vector<T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Index<usize> for Vector<T>

Indexes vector.

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Vector<T>

Indexes mutable vector.

Source§

fn index_mut(&mut self, idx: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> Into<Vec<T>> for Vector<T>

Source§

fn into(self) -> Vec<T>

Converts this type into the (usually inferred) input type.
Source§

impl<'a, T> IntoIterator for &'a Vector<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Vector<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Vector<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Vector<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> Metric<T> for Vector<T>
where T: Float,

Source§

fn norm(&self) -> T

Compute euclidean norm for vector.

§Examples
use rulinalg::vector::Vector;
use rulinalg::Metric;

let a = Vector::new(vec![3.0,4.0]);
let c = a.norm();

assert_eq!(c, 5.0);
Source§

impl<'a, 'b, T> Mul<&'b T> for &'a Vector<T>
where T: Copy + Mul<Output = T>,

Multiplies vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, f: &T) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<&'a T> for Vector<T>
where T: Copy + Mul<Output = T>,

Multiplies vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, f: &T) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, 'b, T> Mul<&'b Vector<T>> for &'a Matrix<T>
where T: Zero<Output = T> + Mul<Output = T> + Add + Copy,

Multiplies matrix by vector.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, v: &Vector<T>) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<&'a Vector<T>> for Matrix<T>
where T: Zero<Output = T> + Mul<Output = T> + Add + Copy,

Multiplies matrix by vector.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, m: &Vector<T>) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<T> for &'a Vector<T>
where T: Copy + Mul<Output = T>,

Multiplies vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, f: T) -> Vector<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Vector<T>
where T: Copy + Mul<Output = T>,

Multiplies vector by scalar.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, f: T) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, T> Mul<Vector<T>> for &'a Matrix<T>
where T: Zero<Output = T> + Mul<Output = T> + Add + Copy,

Multiplies matrix by vector.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, m: Vector<T>) -> Vector<T>

Performs the * operation. Read more
Source§

impl<T> Mul<Vector<T>> for Matrix<T>
where T: Zero<Output = T> + Mul<Output = T> + Add + Copy,

Multiplies matrix by vector.

Source§

type Output = Vector<T>

The resulting type after applying the * operator.
Source§

fn mul(self, m: Vector<T>) -> Vector<T>

Performs the * operation. Read more
Source§

impl<'a, T> MulAssign<&'a T> for Vector<T>
where T: Copy + Mul<Output = T>,

Performs multiplication assignment between a vector and a scalar.

Source§

fn mul_assign(&mut self, _rhs: &T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign<T> for Vector<T>
where T: Copy + Mul<Output = T>,

Performs multiplication assignment between a vector and a scalar.

Source§

fn mul_assign(&mut self, _rhs: T)

Performs the *= operation. Read more
Source§

impl<'a, T> Neg for &'a Vector<T>
where T: Neg<Output = T> + Copy,

Gets negative of vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector<T>

Performs the unary - operation. Read more
Source§

impl<T> Neg for Vector<T>
where T: Neg<Output = T> + Copy,

Gets negative of vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector<T>

Performs the unary - operation. Read more
Source§

impl<T> PartialEq for Vector<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Vector<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, 'b, T> Sub<&'b T> for &'a Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts scalar from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, f: &T) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<&'a T> for Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts scalar from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, f: &T) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, 'b, T> Sub<&'b Vector<T>> for &'a Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts vector from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, v: &Vector<T>) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<&'a Vector<T>> for Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts vector from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, v: &Vector<T>) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<T> for &'a Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts scalar from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, f: T) -> Vector<T>

Performs the - operation. Read more
Source§

impl<T> Sub<T> for Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts scalar from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, f: T) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, T> Sub<Vector<T>> for &'a Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts vector from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, v: Vector<T>) -> Vector<T>

Performs the - operation. Read more
Source§

impl<T> Sub for Vector<T>
where T: Copy + Sub<Output = T>,

Subtracts vector from vector.

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, v: Vector<T>) -> Vector<T>

Performs the - operation. Read more
Source§

impl<'a, T> SubAssign<&'a T> for Vector<T>
where T: Copy + Sub<Output = T>,

Performs subtraction assignment between a vector and a scalar.

Source§

fn sub_assign(&mut self, _rhs: &T)

Performs the -= operation. Read more
Source§

impl<'a, T> SubAssign<&'a Vector<T>> for Vector<T>
where T: Copy + Sub<Output = T>,

Performs elementwise subtraction assignment between two vectors.

Source§

fn sub_assign(&mut self, _rhs: &Vector<T>)

Performs the -= operation. Read more
Source§

impl<T> SubAssign<T> for Vector<T>
where T: Copy + Sub<Output = T>,

Performs subtraction assignment between a vector and a scalar.

Source§

fn sub_assign(&mut self, _rhs: T)

Performs the -= operation. Read more
Source§

impl<T> SubAssign for Vector<T>
where T: Copy + Sub<Output = T>,

Performs elementwise subtraction assignment between two vectors.

Source§

fn sub_assign(&mut self, _rhs: Vector<T>)

Performs the -= operation. Read more
Source§

impl<T: Kernel, U: MeanFunc> SupModel<Matrix<f64>, Vector<f64>> for GaussianProcess<T, U>

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output from inputs.

Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the model using data and outputs.

Source§

impl<C: Criterion> SupModel<Matrix<f64>, Vector<f64>> for GenLinearModel<C>

Supervised model trait for the GLM.

Predictions are made from the model by computing g^-1(Xb).

The model is trained using Iteratively Re-weighted Least Squares.

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output from inputs.

Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the model using inputs and targets.

Source§

impl SupModel<Matrix<f64>, Vector<f64>> for LinRegressor

Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the linear regression model.

Takes training data and output values as input.

§Examples
use rusty_machine::learning::lin_reg::LinRegressor;
use rusty_machine::linalg::Matrix;
use rusty_machine::linalg::Vector;
use rusty_machine::learning::SupModel;

let mut lin_mod = LinRegressor::default();
let inputs = Matrix::new(3,1, vec![2.0, 3.0, 4.0]);
let targets = Vector::new(vec![5.0, 6.0, 7.0]);

lin_mod.train(&inputs, &targets).unwrap();
Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output value from input data.

Model must be trained before prediction can be made.

Source§

impl<A> SupModel<Matrix<f64>, Vector<f64>> for LogisticRegressor<A>

Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the logistic regression model.

Takes training data and output values as input.

§Examples
use rusty_machine::learning::logistic_reg::LogisticRegressor;
use rusty_machine::linalg::Matrix;
use rusty_machine::linalg::Vector;
use rusty_machine::learning::SupModel;

let mut logistic_mod = LogisticRegressor::default();
let inputs = Matrix::new(3,2, vec![1.0, 2.0, 1.0, 3.0, 1.0, 4.0]);
let targets = Vector::new(vec![5.0, 6.0, 7.0]);

logistic_mod.train(&inputs, &targets).unwrap();
Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output value from input data.

Model must be trained before prediction can be made.

Source§

impl<K: Kernel> SupModel<Matrix<f64>, Vector<f64>> for SVM<K>

Train the model using the Pegasos algorithm and predict the model output from new data.

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output from inputs.
Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the model using inputs and targets.
Source§

impl UnSupModel<Matrix<f64>, Vector<Option<usize>>> for DBSCAN

Source§

fn train(&mut self, inputs: &Matrix<f64>) -> LearningResult<()>

Train the classifier using input data.

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<Option<usize>>>

Predict output from inputs.
Source§

impl<InitAlg: Initializer> UnSupModel<Matrix<f64>, Vector<usize>> for KMeansClassifier<InitAlg>

Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<usize>>

Predict classes from data.

Model must be trained.

Source§

fn train(&mut self, inputs: &Matrix<f64>) -> LearningResult<()>

Train the classifier using input data.

Source§

impl<T> Eq for Vector<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Vector<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector<T>
where T: Send,

§

impl<T> Sync for Vector<T>
where T: Sync,

§

impl<T> Unpin for Vector<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector<T>
where T: 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.