pub struct Matrix<T> { /* private fields */ }Expand description
The Matrix struct.
Can be instantiated with any type.
Implementations§
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn bidiagonal_decomp(
self,
) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
pub fn bidiagonal_decomp( self, ) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Converts matrix to bidiagonal form
Returns (B, U, V), where B is bidiagonal and self = U B V_T.
Note that if self has self.rows() > self.cols() the matrix will
be transposed and then reduced - this will lead to a sub-diagonal instead
of super-diagonal.
§Failures
- The matrix cannot be reduced to bidiagonal form.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn svd(self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
pub fn svd(self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Singular Value Decomposition
Computes the SVD using the Golub-Reinsch algorithm.
Returns Σ, U, V, such that self = U Σ VT. Σ is a diagonal matrix whose elements
correspond to the non-negative singular values of the matrix. The singular values are ordered in
non-increasing order. U and V have orthonormal columns, and each column represents the
left and right singular vectors for the corresponding singular value in Σ, respectively.
If self has M rows and N columns, the dimensions of the returned matrices
are as follows.
If M >= N:
Σ: N x NU: M x NV: N x N
If M < N:
Σ: M x MU: M x MV: N x M
Note: This version of the SVD is sometimes referred to as the ‘economy SVD’.
§Failures
This function may fail in some cases. The current decomposition whilst being efficient is fairly basic. Hopefully the algorithm can be made not to fail in the near future.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn upper_hessenberg(self) -> Result<Matrix<T>, Error>
pub fn upper_hessenberg(self) -> Result<Matrix<T>, Error>
Returns H, where H is the upper hessenberg form.
If the transformation matrix is also required, you should
use upper_hess_decomp.
§Examples
use rulinalg::matrix::Matrix;
let a = Matrix::new(4,4,vec![2.,0.,1.,1.,2.,0.,1.,2.,1.,2.,0.,0.,2.,0.,1.,1.]);
let h = a.upper_hessenberg();
println!("{:?}", h.expect("Could not get upper Hessenberg form.").data());§Panics
- The matrix is not square.
§Failures
- The matrix cannot be reduced to upper hessenberg form.
Sourcepub fn upper_hess_decomp(self) -> Result<(Matrix<T>, Matrix<T>), Error>
pub fn upper_hess_decomp(self) -> Result<(Matrix<T>, Matrix<T>), Error>
Returns (U,H), where H is the upper hessenberg form and U is the unitary transform matrix.
Note: The current transform matrix seems broken…
§Examples
use rulinalg::matrix::{Matrix, BaseMatrix};
let a = Matrix::new(3,3,vec![1.,2.,3.,4.,5.,6.,7.,8.,9.]);
// u is the transform, h is the upper hessenberg form.
let (u,h) = a.clone().upper_hess_decomp().expect("This matrix should decompose!");
println!("The hess : {:?}", h.data());
println!("Manual hess : {:?}", (u.transpose() * a * u).data());§Panics
- The matrix is not square.
§Failures
- The matrix cannot be reduced to upper hessenberg form.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn lup_decomp(&self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
pub fn lup_decomp(&self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Computes L, U, and P for LUP decomposition.
Returns L,U, and P respectively.
§Examples
use rulinalg::matrix::Matrix;
let a = Matrix::new(3,3, vec![1.0,2.0,0.0,
0.0,3.0,4.0,
5.0, 1.0, 2.0]);
let (l,u,p) = a.lup_decomp().expect("This matrix should decompose!");§Panics
- Matrix is not square.
§Failures
- Matrix cannot be LUP decomposed.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn eigenvalues(&self) -> Result<Vec<T>, Error>
pub fn eigenvalues(&self) -> Result<Vec<T>, Error>
Eigenvalues of a square matrix.
Returns a Vec of eigenvalues.
§Examples
use rulinalg::matrix::Matrix;
let a = Matrix::new(4,4, (1..17).map(|v| v as f64).collect::<Vec<f64>>());
let e = a.eigenvalues().expect("We should be able to compute these eigenvalues!");
println!("{:?}", e);§Panics
- The matrix is not square.
§Failures
- Eigenvalues cannot be computed.
Sourcepub fn eigendecomp(&self) -> Result<(Vec<T>, Matrix<T>), Error>
pub fn eigendecomp(&self) -> Result<(Vec<T>, Matrix<T>), Error>
Eigendecomposition of a square matrix.
Returns a Vec of eigenvalues, and a matrix with eigenvectors as the columns.
The eigenvectors are only gauranteed to be correct if the matrix is real-symmetric.
§Examples
use rulinalg::matrix::Matrix;
let a = Matrix::new(3,3,vec![3.,2.,4.,2.,0.,2.,4.,2.,3.]);
let (e, m) = a.eigendecomp().expect("We should be able to compute this eigendecomp!");
println!("{:?}", e);
println!("{:?}", m.data());§Panics
- The matrix is not square.
§Failures
- The eigen decomposition can not be computed.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn new<U>(rows: usize, cols: usize, data: U) -> Matrix<T>
pub fn new<U>(rows: usize, cols: usize, data: U) -> Matrix<T>
Constructor for Matrix struct.
Requires both the row and column dimensions.
§Examples
use rulinalg::matrix::{Matrix, BaseMatrix};
let mat = Matrix::new(2,2, vec![1.0,2.0,3.0,4.0]);
assert_eq!(mat.rows(), 2);
assert_eq!(mat.cols(), 2);§Panics
- The input data does not match the given dimensions.
Examples found in repository?
12fn generate_data(centroids: &Matrix<f64>,
13 points_per_centroid: usize,
14 noise: f64)
15 -> Matrix<f64> {
16 assert!(centroids.cols() > 0, "Centroids cannot be empty.");
17 assert!(centroids.rows() > 0, "Centroids cannot be empty.");
18 assert!(noise >= 0f64, "Noise must be non-negative.");
19 let mut raw_cluster_data = Vec::with_capacity(centroids.rows() * points_per_centroid *
20 centroids.cols());
21
22 let mut rng = thread_rng();
23 let normal_rv = Normal::new(0f64, noise);
24
25 for _ in 0..points_per_centroid {
26 // Generate points from each centroid
27 for centroid in centroids.iter_rows() {
28 // Generate a point randomly around the centroid
29 let mut point = Vec::with_capacity(centroids.cols());
30 for feature in centroid {
31 point.push(feature + normal_rv.ind_sample(&mut rng));
32 }
33
34 // Push point to raw_cluster_data
35 raw_cluster_data.extend(point);
36 }
37 }
38
39 Matrix::new(centroids.rows() * points_per_centroid,
40 centroids.cols(),
41 raw_cluster_data)
42}
43
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(¢roids, 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}More examples
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}15fn main() {
16 println!("AND gate learner sample:");
17
18 const THRESHOLD: f64 = 0.7;
19
20 const SAMPLES: usize = 10000;
21 println!("Generating {} training data and labels...", SAMPLES as u32);
22
23 let mut input_data = Vec::with_capacity(SAMPLES * 2);
24 let mut label_data = Vec::with_capacity(SAMPLES);
25
26 for _ in 0..SAMPLES {
27 // The two inputs are "signals" between 0 and 1
28 let Closed01(left) = random::<Closed01<f64>>();
29 let Closed01(right) = random::<Closed01<f64>>();
30 input_data.push(left);
31 input_data.push(right);
32 if left > THRESHOLD && right > THRESHOLD {
33 label_data.push(1.0);
34 } else {
35 label_data.push(0.0)
36 }
37 }
38
39 let inputs = Matrix::new(SAMPLES, 2, input_data);
40 let targets = Matrix::new(SAMPLES, 1, label_data);
41
42 let layers = &[2, 1];
43 let criterion = BCECriterion::new(Regularization::L2(0.));
44 let mut model = NeuralNet::new(layers, criterion, StochasticGD::default());
45
46 println!("Training...");
47 // Our train function returns a Result<(), E>
48 model.train(&inputs, &targets).unwrap();
49
50 let test_cases = vec![
51 0.0, 0.0,
52 0.0, 1.0,
53 1.0, 1.0,
54 1.0, 0.0,
55 ];
56 let expected = vec![
57 0.0,
58 0.0,
59 1.0,
60 0.0,
61 ];
62 let test_inputs = Matrix::new(test_cases.len() / 2, 2, test_cases);
63 let res = model.predict(&test_inputs).unwrap();
64
65 println!("Evaluation...");
66 let mut hits = 0;
67 let mut misses = 0;
68 // Evaluation
69 println!("Got\tExpected");
70 for (idx, prediction) in res.into_vec().iter().enumerate() {
71 println!("{:.2}\t{}", prediction, expected[idx]);
72 if (prediction - 0.5) * (expected[idx] - 0.5) > 0. {
73 hits += 1;
74 } else {
75 misses += 1;
76 }
77 }
78
79 println!("Hits: {}, Misses: {}", hits, misses);
80 let hits_f = hits as f64;
81 let total = (hits + misses) as f64;
82 println!("Accuracy: {}%", (hits_f / total) * 100.);
83}Sourcepub fn from_fn<F>(rows: usize, cols: usize, f: F) -> Matrix<T>
pub fn from_fn<F>(rows: usize, cols: usize, f: F) -> Matrix<T>
Constructor for Matrix struct that takes a function f
and constructs a new matrix such that A_ij = f(i, j),
where i is the row index and j the column index.
Requires both the row and column dimensions as well as a generating function.
§Examples
use rulinalg::matrix::{Matrix, BaseMatrix};
// Let's assume you have an array of "things" for
// which you want to generate a distance matrix:
let things: [i32; 3] = [1, 2, 3];
let distances: Matrix<f64> = Matrix::from_fn(things.len(), things.len(), |col, row| {
(things[col] - things[row]).abs().into()
});
assert_eq!(distances.rows(), 3);
assert_eq!(distances.cols(), 3);
assert_eq!(distances.data(), &vec![
0.0, 1.0, 2.0,
1.0, 0.0, 1.0,
2.0, 1.0, 0.0,
]);Sourcepub fn data(&self) -> &Vec<T>
pub fn data(&self) -> &Vec<T>
Returns a non-mutable reference to the underlying data.
Examples found in repository?
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}Sourcepub fn into_vec(self) -> Vec<T>
pub fn into_vec(self) -> Vec<T>
Consumes the Matrix and returns the Vec of data.
Examples found in repository?
15fn main() {
16 println!("AND gate learner sample:");
17
18 const THRESHOLD: f64 = 0.7;
19
20 const SAMPLES: usize = 10000;
21 println!("Generating {} training data and labels...", SAMPLES as u32);
22
23 let mut input_data = Vec::with_capacity(SAMPLES * 2);
24 let mut label_data = Vec::with_capacity(SAMPLES);
25
26 for _ in 0..SAMPLES {
27 // The two inputs are "signals" between 0 and 1
28 let Closed01(left) = random::<Closed01<f64>>();
29 let Closed01(right) = random::<Closed01<f64>>();
30 input_data.push(left);
31 input_data.push(right);
32 if left > THRESHOLD && right > THRESHOLD {
33 label_data.push(1.0);
34 } else {
35 label_data.push(0.0)
36 }
37 }
38
39 let inputs = Matrix::new(SAMPLES, 2, input_data);
40 let targets = Matrix::new(SAMPLES, 1, label_data);
41
42 let layers = &[2, 1];
43 let criterion = BCECriterion::new(Regularization::L2(0.));
44 let mut model = NeuralNet::new(layers, criterion, StochasticGD::default());
45
46 println!("Training...");
47 // Our train function returns a Result<(), E>
48 model.train(&inputs, &targets).unwrap();
49
50 let test_cases = vec![
51 0.0, 0.0,
52 0.0, 1.0,
53 1.0, 1.0,
54 1.0, 0.0,
55 ];
56 let expected = vec![
57 0.0,
58 0.0,
59 1.0,
60 0.0,
61 ];
62 let test_inputs = Matrix::new(test_cases.len() / 2, 2, test_cases);
63 let res = model.predict(&test_inputs).unwrap();
64
65 println!("Evaluation...");
66 let mut hits = 0;
67 let mut misses = 0;
68 // Evaluation
69 println!("Got\tExpected");
70 for (idx, prediction) in res.into_vec().iter().enumerate() {
71 println!("{:.2}\t{}", prediction, expected[idx]);
72 if (prediction - 0.5) * (expected[idx] - 0.5) > 0. {
73 hits += 1;
74 } else {
75 misses += 1;
76 }
77 }
78
79 println!("Hits: {}, Misses: {}", hits, misses);
80 let hits_f = hits as f64;
81 let total = (hits + misses) as f64;
82 println!("Accuracy: {}%", (hits_f / total) * 100.);
83}Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Source§impl<T> Matrix<T>where
T: Float + FromPrimitive,
impl<T> Matrix<T>where
T: Float + FromPrimitive,
Sourcepub fn mean(&self, axis: Axes) -> Vector<T>
pub fn mean(&self, axis: Axes) -> Vector<T>
The mean of the matrix along the specified axis.
- Axis Row - Arithmetic mean of rows.
- Axis Col - Arithmetic mean of columns.
Calling mean() on an empty matrix will return an empty matrix.
§Examples
use rulinalg::matrix::{Matrix, Axes};
let a = Matrix::<f64>::new(2,2, vec![1.0,2.0,3.0,4.0]);
let c = a.mean(Axes::Row);
assert_eq!(*c.data(), vec![2.0, 3.0]);
let d = a.mean(Axes::Col);
assert_eq!(*d.data(), vec![1.5, 3.5]);Sourcepub fn variance(&self, axis: Axes) -> Result<Vector<T>, Error>
pub fn variance(&self, axis: Axes) -> Result<Vector<T>, Error>
The variance of the matrix along the specified axis.
- Axis Row - Sample variance of rows.
- Axis Col - Sample variance of columns.
§Examples
use rulinalg::matrix::{Matrix, Axes};
let a = Matrix::<f32>::new(2,2,vec![1.0,2.0,3.0,4.0]);
let c = a.variance(Axes::Row).unwrap();
assert_eq!(*c.data(), vec![2.0, 2.0]);
let d = a.variance(Axes::Col).unwrap();
assert_eq!(*d.data(), vec![0.5, 0.5]);§Failures
- There are one or fewer row/columns in the working axis.
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn solve(&self, y: Vector<T>) -> Result<Vector<T>, Error>
pub fn solve(&self, y: Vector<T>) -> Result<Vector<T>, Error>
Solves the equation Ax = y.
Requires a Vector y as input.
§Examples
use rulinalg::matrix::Matrix;
use rulinalg::vector::Vector;
let a = Matrix::new(2,2, vec![2.0,3.0,1.0,2.0]);
let y = Vector::new(vec![13.0,8.0]);
let x = a.solve(y).unwrap();
assert_eq!(*x.data(), vec![2.0, 3.0]);§Panics
- The matrix column count and vector size are different.
- The matrix is not square.
§Failures
- The matrix cannot be decomposed into an LUP form to solve.
- There is no valid solution as the matrix is singular.
Sourcepub fn inverse(&self) -> Result<Matrix<T>, Error>
pub fn inverse(&self) -> Result<Matrix<T>, Error>
Computes the inverse of the matrix.
§Examples
use rulinalg::matrix::Matrix;
let a = Matrix::new(2,2, vec![2.,3.,1.,2.]);
let inv = a.inverse().expect("This matrix should have an inverse!");
let I = a * inv;
assert_eq!(*I.data(), vec![1.0,0.0,0.0,1.0]);§Panics
- The matrix is not square.
§Failures
- The matrix could not be LUP decomposed.
- The matrix has zero determinant.
Trait Implementations§
Source§impl<'a, 'b, T> Add<&'b Matrix<T>> for &'a Matrix<T>
Performs elementwise
addition
between two matrices.
impl<'a, 'b, T> Add<&'b Matrix<T>> for &'a Matrix<T>
Performs elementwise addition between two matrices.
Source§impl<'a, 'b, 'c, T> Add<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Add<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Add<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Add<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<&'a Matrix<T>> for Matrix<T>
Performs elementwise
addition
between two matrices.
impl<'a, T> Add<&'a Matrix<T>> for Matrix<T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from self.
Source§impl<'a, 'b, T> Add<&'b Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<&'b Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Add<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Add<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Add<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Add<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<&'a T> for Matrix<T>
Scalar
addition
with matrix.
impl<'a, T> Add<&'a T> for Matrix<T>
Scalar addition with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<'a, T> Add<Matrix<T>> for &'a Matrix<T>
Performs elementwise
addition
between two matrices.
impl<'a, T> Add<Matrix<T>> for &'a Matrix<T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from m.
Source§impl<'a, 'b, T> Add<Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, T> Add<Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, T> Add<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, T> Add<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Add<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, 'b, T> Add<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<'a, T> Add<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
impl<'a, T> Add<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
between Matrix and MatrixSlice.
Source§impl<T> Add<T> for Matrix<T>
Scalar
addition
with matrix.
impl<T> Add<T> for Matrix<T>
Scalar addition with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<T> Add for Matrix<T>
Performs elementwise
addition
between two matrices.
impl<T> Add for Matrix<T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from self.
Source§impl<'a, T> AddAssign<&'a Matrix<T>> for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, T> AddAssign<&'a Matrix<T>> for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: &Matrix<T>)
fn add_assign(&mut self, _rhs: &Matrix<T>)
+= operation. Read moreSource§impl<'a, 'b, T> AddAssign<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, 'b, T> AddAssign<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: &Matrix<T>)
fn add_assign(&mut self, _rhs: &Matrix<T>)
+= operation. Read moreSource§impl<'a, 'b, T> AddAssign<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, 'b, T> AddAssign<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: &MatrixSlice<'_, T>)
fn add_assign(&mut self, _rhs: &MatrixSlice<'_, T>)
+= operation. Read moreSource§impl<'a, 'b, T> AddAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, 'b, T> AddAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: &MatrixSliceMut<'_, T>)
fn add_assign(&mut self, _rhs: &MatrixSliceMut<'_, T>)
+= operation. Read moreSource§impl<'a, T> AddAssign<&'a T> for Matrix<T>
Performs
addition
assignment between a matrix and a scalar.
impl<'a, T> AddAssign<&'a T> for Matrix<T>
Performs addition assignment between a matrix and a scalar.
Source§fn add_assign(&mut self, _rhs: &T)
fn add_assign(&mut self, _rhs: &T)
+= operation. Read moreSource§impl<'a, T> AddAssign<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, T> AddAssign<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: Matrix<T>)
fn add_assign(&mut self, _rhs: Matrix<T>)
+= operation. Read moreSource§impl<'a, T> AddAssign<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, T> AddAssign<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: MatrixSlice<'_, T>)
fn add_assign(&mut self, _rhs: MatrixSlice<'_, T>)
+= operation. Read moreSource§impl<'a, T> AddAssign<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<'a, T> AddAssign<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: MatrixSliceMut<'_, T>)
fn add_assign(&mut self, _rhs: MatrixSliceMut<'_, T>)
+= operation. Read moreSource§impl<T> AddAssign<T> for Matrix<T>
Performs
addition
assignment between a matrix and a scalar.
impl<T> AddAssign<T> for Matrix<T>
Performs addition assignment between a matrix and a scalar.
Source§fn add_assign(&mut self, _rhs: T)
fn add_assign(&mut self, _rhs: T)
+= operation. Read moreSource§impl<T> AddAssign for Matrix<T>
Performs elementwise
addition
assignment between two matrices.
impl<T> AddAssign for Matrix<T>
Performs elementwise addition assignment between two matrices.
Source§fn add_assign(&mut self, _rhs: Matrix<T>)
fn add_assign(&mut self, _rhs: Matrix<T>)
+= operation. Read moreSource§impl<T> BaseMatrix<T> for Matrix<T>
impl<T> BaseMatrix<T> for Matrix<T>
Source§fn row_stride(&self) -> usize
fn row_stride(&self) -> usize
Source§fn into_matrix(self) -> Matrix<T>where
T: Copy,
fn into_matrix(self) -> Matrix<T>where
T: Copy,
Source§fn elemul(&self, m: &Matrix<T>) -> Matrix<T>
fn elemul(&self, m: &Matrix<T>) -> Matrix<T>
Source§fn elediv(&self, m: &Matrix<T>) -> Matrix<T>
fn elediv(&self, m: &Matrix<T>) -> Matrix<T>
Source§fn vcat<S>(&self, m: &S) -> Matrix<T>where
T: Copy,
S: BaseMatrix<T>,
fn vcat<S>(&self, m: &S) -> Matrix<T>where
T: Copy,
S: BaseMatrix<T>,
Source§fn as_slice(&self) -> MatrixSlice<'_, T>
fn as_slice(&self) -> MatrixSlice<'_, T>
MatrixSlice over the whole matrix. Read moreSource§unsafe fn get_unchecked(&self, index: [usize; 2]) -> &T
unsafe fn get_unchecked(&self, index: [usize; 2]) -> &T
Source§fn get_row(&self, index: usize) -> Option<&[T]>
fn get_row(&self, index: usize) -> Option<&[T]>
None if the index is out of bounds. Read moreSource§unsafe fn get_row_unchecked(&self, index: usize) -> &[T]
unsafe fn get_row_unchecked(&self, index: usize) -> &[T]
Source§fn iter<'a>(&self) -> SliceIter<'a, T>where
T: 'a,
fn iter<'a>(&self) -> SliceIter<'a, T>where
T: 'a,
Source§fn iter_diag(&self, k: DiagOffset) -> Diagonal<'_, T, Self>
fn iter_diag(&self, k: DiagOffset) -> Diagonal<'_, T, Self>
Source§fn select_rows<'a, I>(&self, rows: I) -> Matrix<T>where
T: Copy,
I: IntoIterator<Item = &'a usize>,
<I as IntoIterator>::IntoIter: ExactSizeIterator + Clone,
fn select_rows<'a, I>(&self, rows: I) -> Matrix<T>where
T: Copy,
I: IntoIterator<Item = &'a usize>,
<I as IntoIterator>::IntoIter: ExactSizeIterator + Clone,
Source§fn select_cols<'a, I>(&self, cols: I) -> Matrix<T>where
T: Copy,
I: IntoIterator<Item = &'a usize>,
<I as IntoIterator>::IntoIter: ExactSizeIterator + Clone,
fn select_cols<'a, I>(&self, cols: I) -> Matrix<T>where
T: Copy,
I: IntoIterator<Item = &'a usize>,
<I as IntoIterator>::IntoIter: ExactSizeIterator + Clone,
Source§fn select(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>where
T: Copy,
fn select(&self, rows: &[usize], cols: &[usize]) -> Matrix<T>where
T: Copy,
Source§fn hcat<S>(&self, m: &S) -> Matrix<T>where
T: Copy,
S: BaseMatrix<T>,
fn hcat<S>(&self, m: &S) -> Matrix<T>where
T: Copy,
S: BaseMatrix<T>,
Source§fn solve_u_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error>
fn solve_u_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error>
Source§fn solve_l_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error>
fn solve_l_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error>
Source§fn split_at(
&self,
mid: usize,
axis: Axes,
) -> (MatrixSlice<'_, T>, MatrixSlice<'_, T>)
fn split_at( &self, mid: usize, axis: Axes, ) -> (MatrixSlice<'_, T>, MatrixSlice<'_, T>)
MatrixSlices. Read moreSource§impl<T> BaseMatrixMut<T> for Matrix<T>
impl<T> BaseMatrixMut<T> for Matrix<T>
Source§fn as_mut_ptr(&mut self) -> *mut T
fn as_mut_ptr(&mut self) -> *mut T
Top left index of the slice.
Source§fn as_mut_slice(&mut self) -> MatrixSliceMut<'_, T>
fn as_mut_slice(&mut self) -> MatrixSliceMut<'_, T>
MatrixSliceMut over the whole matrix. Read moreSource§unsafe fn get_unchecked_mut(&mut self, index: [usize; 2]) -> &mut T
unsafe fn get_unchecked_mut(&mut self, index: [usize; 2]) -> &mut T
Source§fn iter_mut<'a>(&mut self) -> SliceIterMut<'a, T>where
T: 'a,
fn iter_mut<'a>(&mut self) -> SliceIterMut<'a, T>where
T: 'a,
Source§fn get_row_mut(&mut self, index: usize) -> Option<&mut [T]>
fn get_row_mut(&mut self, index: usize) -> Option<&mut [T]>
None if the index is out of bounds. Read moreSource§unsafe fn get_row_unchecked_mut(&mut self, index: usize) -> &mut [T]
unsafe fn get_row_unchecked_mut(&mut self, index: usize) -> &mut [T]
Source§fn iter_rows_mut(&mut self) -> RowsMut<'_, T>
fn iter_rows_mut(&mut self) -> RowsMut<'_, T>
Source§fn iter_diag_mut(&mut self, k: DiagOffset) -> DiagonalMut<'_, T, Self>
fn iter_diag_mut(&mut self, k: DiagOffset) -> DiagonalMut<'_, T, Self>
Source§fn set_to<M>(self, target: M)where
M: BaseMatrix<T>,
T: Copy,
fn set_to<M>(self, target: M)where
M: BaseMatrix<T>,
T: Copy,
Source§fn apply(self, f: &dyn Fn(T) -> T) -> Selfwhere
T: Copy,
fn apply(self, f: &dyn Fn(T) -> T) -> Selfwhere
T: Copy,
Source§fn split_at_mut(
&mut self,
mid: usize,
axis: Axes,
) -> (MatrixSliceMut<'_, T>, MatrixSliceMut<'_, T>)
fn split_at_mut( &mut self, mid: usize, axis: Axes, ) -> (MatrixSliceMut<'_, T>, MatrixSliceMut<'_, T>)
MatrixSliceMuts. Read moreSource§fn sub_slice_mut<'a>(
&mut self,
start: [usize; 2],
rows: usize,
cols: usize,
) -> MatrixSliceMut<'a, T>where
T: 'a,
fn sub_slice_mut<'a>(
&mut self,
start: [usize; 2],
rows: usize,
cols: usize,
) -> MatrixSliceMut<'a, T>where
T: 'a,
MatrixSliceMut from an existing matrix. Read moreSource§impl<'a, T> Div<&'a T> for Matrix<T>
Scalar
division
with matrix.
impl<'a, T> Div<&'a T> for Matrix<T>
Scalar division with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<T> Div<T> for Matrix<T>
Scalar
division
with matrix.
impl<T> Div<T> for Matrix<T>
Scalar division with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<'a, T> DivAssign<&'a T> for Matrix<T>
Performs
division
assignment between a matrix and a scalar.
impl<'a, T> DivAssign<&'a T> for Matrix<T>
Performs division assignment between a matrix and a scalar.
Source§fn div_assign(&mut self, _rhs: &T)
fn div_assign(&mut self, _rhs: &T)
/= operation. Read moreSource§impl<T> DivAssign<T> for Matrix<T>
Performs
division
assignment between a matrix and a scalar.
impl<T> DivAssign<T> for Matrix<T>
Performs division assignment between a matrix and a scalar.
Source§fn div_assign(&mut self, _rhs: T)
fn div_assign(&mut self, _rhs: T)
/= operation. Read moreSource§impl<'a, T> From<MatrixSlice<'a, T>> for Matrix<T>where
T: Copy,
impl<'a, T> From<MatrixSlice<'a, T>> for Matrix<T>where
T: Copy,
Source§fn from(slice: MatrixSlice<'a, T>) -> Matrix<T>
fn from(slice: MatrixSlice<'a, T>) -> Matrix<T>
Source§impl<'a, T> From<MatrixSliceMut<'a, T>> for Matrix<T>where
T: Copy,
impl<'a, T> From<MatrixSliceMut<'a, T>> for Matrix<T>where
T: Copy,
Source§fn from(slice: MatrixSliceMut<'a, T>) -> Matrix<T>
fn from(slice: MatrixSliceMut<'a, T>) -> Matrix<T>
Source§impl<'a, T> FromIterator<&'a [T]> for Matrix<T>where
T: 'a + Copy,
Creates a Matrix from an iterator over slices.
impl<'a, T> FromIterator<&'a [T]> for Matrix<T>where
T: 'a + Copy,
Creates a Matrix from an iterator over slices.
Each of the slices produced by the iterator will become a row in the matrix.
§Panics
Will panic if the iterators items do not have constant length.
§Examples
We can create a new matrix from some data.
use rulinalg::matrix::{Matrix, BaseMatrix};
let a : Matrix<f64> = vec![4f64; 16].chunks(4).collect();
assert_eq!(a.rows(), 4);
assert_eq!(a.cols(), 4);We can also do more interesting things.
use rulinalg::matrix::{Matrix, BaseMatrix};
let a = Matrix::new(4,2, (0..8).collect::<Vec<usize>>());
// Here we skip the first row and take only those
// where the first entry is less than 6.
let b = a.iter_rows()
.skip(1)
.filter(|x| x[0] < 6)
.collect::<Matrix<usize>>();
// We take the middle rows
assert_eq!(b.into_vec(), vec![2,3,4,5]);Source§impl<T> IndexMut<[usize; 2]> for Matrix<T>
Indexes mutable matrix.
impl<T> IndexMut<[usize; 2]> for Matrix<T>
Indexes mutable matrix.
Takes row index first then column.
Source§impl<T: Float> Invertible<Matrix<T>> for MinMaxScaler<T>
impl<T: Float> Invertible<Matrix<T>> for MinMaxScaler<T>
Source§impl<T: Float + FromPrimitive> Invertible<Matrix<T>> for Standardizer<T>
impl<T: Float + FromPrimitive> Invertible<Matrix<T>> for Standardizer<T>
Source§impl<'a, 'b, 'c, T> Mul<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Multiplies two matrices together.
impl<'a, 'b, 'c, T> Mul<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, 'c, T> Mul<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Multiplies two matrices together.
impl<'a, 'b, 'c, T> Mul<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<&'b Matrix<T>> for MatrixSlice<'a, T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<&'b Matrix<T>> for MatrixSlice<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, 'c, T> Mul<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, 'c, T> Mul<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<&'b MatrixSlice<'a, T>> for Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<&'b MatrixSlice<'a, T>> for Matrix<T>
Multiplies two matrices together.
Source§impl<'a, 'b, 'c, T> Mul<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, 'c, T> Mul<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Multiplies two matrices together.
Source§impl<'a, T> Mul<&'a T> for Matrix<T>
Scalar
multiplication
with matrix.
impl<'a, T> Mul<&'a T> for Matrix<T>
Scalar multiplication with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<'a, 'b, T> Mul<Matrix<T>> for &'b MatrixSlice<'a, T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<Matrix<T>> for &'b MatrixSlice<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Multiplies two matrices together.
Source§impl<'a, T> Mul<Matrix<T>> for MatrixSlice<'a, T>
Multiplies two matrices together.
impl<'a, T> Mul<Matrix<T>> for MatrixSlice<'a, T>
Multiplies two matrices together.
Source§impl<'a, T> Mul<Matrix<T>> for MatrixSliceMut<'a, T>
Multiplies two matrices together.
impl<'a, T> Mul<Matrix<T>> for MatrixSliceMut<'a, T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<MatrixSlice<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<MatrixSlice<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
Source§impl<'a, T> Mul<MatrixSlice<'a, T>> for Matrix<T>
Multiplies two matrices together.
impl<'a, T> Mul<MatrixSlice<'a, T>> for Matrix<T>
Multiplies two matrices together.
Source§impl<'a, 'b, T> Mul<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
impl<'a, 'b, T> Mul<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Multiplies two matrices together.
Source§impl<'a, T> Mul<MatrixSliceMut<'a, T>> for Matrix<T>
Multiplies two matrices together.
impl<'a, T> Mul<MatrixSliceMut<'a, T>> for Matrix<T>
Multiplies two matrices together.
Source§impl<T> Mul<T> for Matrix<T>
Scalar
multiplication
with matrix.
impl<T> Mul<T> for Matrix<T>
Scalar multiplication with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<'a, T> MulAssign<&'a T> for Matrix<T>
Performs
multiplication
assignment between a matrix and a scalar.
impl<'a, T> MulAssign<&'a T> for Matrix<T>
Performs multiplication assignment between a matrix and a scalar.
Source§fn mul_assign(&mut self, _rhs: &T)
fn mul_assign(&mut self, _rhs: &T)
*= operation. Read moreSource§impl<T> MulAssign<T> for Matrix<T>
Performs
multiplication
assignment between a matrix and a scalar.
impl<T> MulAssign<T> for Matrix<T>
Performs multiplication assignment between a matrix and a scalar.
Source§fn mul_assign(&mut self, _rhs: T)
fn mul_assign(&mut self, _rhs: T)
*= operation. Read moreSource§impl<'a, 'b, T> Sub<&'b Matrix<T>> for &'a Matrix<T>
Performs elementwise
subtraction
between two matrices.
impl<'a, 'b, T> Sub<&'b Matrix<T>> for &'a Matrix<T>
Performs elementwise subtraction between two matrices.
Source§impl<'a, 'b, 'c, T> Sub<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Sub<&'c Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Sub<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Sub<&'c Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<&'a Matrix<T>> for Matrix<T>
Performs elementwise
subtraction
between two matrices.
impl<'a, T> Sub<&'a Matrix<T>> for Matrix<T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from self.
Source§impl<'a, 'b, T> Sub<&'b Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<&'b Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Sub<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Sub<&'c MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, 'c, T> Sub<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, 'c, T> Sub<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<&'a T> for Matrix<T>
Scalar
subtraction
with matrix.
impl<'a, T> Sub<&'a T> for Matrix<T>
Scalar subtraction with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<'a, T> Sub<Matrix<T>> for &'a Matrix<T>
Performs elementwise
subtraction
between two matrices.
impl<'a, T> Sub<Matrix<T>> for &'a Matrix<T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from m.
Source§impl<'a, 'b, T> Sub<Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<Matrix<T>> for &'b MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<Matrix<T>> for &'b MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, T> Sub<Matrix<T>> for MatrixSlice<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, T> Sub<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<MatrixSlice<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, T> Sub<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, 'b, T> Sub<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, 'b, T> Sub<MatrixSliceMut<'a, T>> for &'b Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<'a, T> Sub<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
impl<'a, T> Sub<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
between Matrix and MatrixSlice.
Source§impl<T> Sub<T> for Matrix<T>
Scalar
subtraction
with matrix.
impl<T> Sub<T> for Matrix<T>
Scalar subtraction with matrix.
Will reuse the memory allocated for the existing matrix.
Source§impl<T> Sub for Matrix<T>
Performs elementwise
subtraction
between two matrices.
impl<T> Sub for Matrix<T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from self.
Source§impl<'a, T> SubAssign<&'a Matrix<T>> for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, T> SubAssign<&'a Matrix<T>> for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: &Matrix<T>)
fn sub_assign(&mut self, _rhs: &Matrix<T>)
-= operation. Read moreSource§impl<'a, 'b, T> SubAssign<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, 'b, T> SubAssign<&'b Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: &Matrix<T>)
fn sub_assign(&mut self, _rhs: &Matrix<T>)
-= operation. Read moreSource§impl<'a, 'b, T> SubAssign<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, 'b, T> SubAssign<&'b MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: &MatrixSlice<'_, T>)
fn sub_assign(&mut self, _rhs: &MatrixSlice<'_, T>)
-= operation. Read moreSource§impl<'a, 'b, T> SubAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, 'b, T> SubAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: &MatrixSliceMut<'_, T>)
fn sub_assign(&mut self, _rhs: &MatrixSliceMut<'_, T>)
-= operation. Read moreSource§impl<'a, T> SubAssign<&'a T> for Matrix<T>
Performs
subtraction
assignment between a matrix and a scalar.
impl<'a, T> SubAssign<&'a T> for Matrix<T>
Performs subtraction assignment between a matrix and a scalar.
Source§fn sub_assign(&mut self, _rhs: &T)
fn sub_assign(&mut self, _rhs: &T)
-= operation. Read moreSource§impl<'a, T> SubAssign<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, T> SubAssign<Matrix<T>> for MatrixSliceMut<'a, T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: Matrix<T>)
fn sub_assign(&mut self, _rhs: Matrix<T>)
-= operation. Read moreSource§impl<'a, T> SubAssign<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, T> SubAssign<MatrixSlice<'a, T>> for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: MatrixSlice<'_, T>)
fn sub_assign(&mut self, _rhs: MatrixSlice<'_, T>)
-= operation. Read moreSource§impl<'a, T> SubAssign<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<'a, T> SubAssign<MatrixSliceMut<'a, T>> for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: MatrixSliceMut<'_, T>)
fn sub_assign(&mut self, _rhs: MatrixSliceMut<'_, T>)
-= operation. Read moreSource§impl<T> SubAssign<T> for Matrix<T>
Performs
subtraction
assignment between a matrix and a scalar.
impl<T> SubAssign<T> for Matrix<T>
Performs subtraction assignment between a matrix and a scalar.
Source§fn sub_assign(&mut self, _rhs: T)
fn sub_assign(&mut self, _rhs: T)
-= operation. Read moreSource§impl<T> SubAssign for Matrix<T>
Performs elementwise
subtraction
assignment between two matrices.
impl<T> SubAssign for Matrix<T>
Performs elementwise subtraction assignment between two matrices.
Source§fn sub_assign(&mut self, _rhs: Matrix<T>)
fn sub_assign(&mut self, _rhs: Matrix<T>)
-= operation. Read moreSource§impl<T: Distribution> SupModel<Matrix<f64>, Matrix<f64>> for NaiveBayes<T>
Train and predict from the Naive Bayes model.
impl<T: Distribution> SupModel<Matrix<f64>, Matrix<f64>> for NaiveBayes<T>
Train and predict from the Naive Bayes model.
The input matrix must be rows made up of features. The target matrix should have indicator vectors in each row specifying the input class. e.g. [[1,0,0],[0,0,1]] shows class 1 first, then class 3.
Source§impl<'a, T, A> SupModel<Matrix<f64>, Matrix<f64>> for NeuralNet<'a, T, A>
Supervised learning for the Neural Network.
impl<'a, T, A> SupModel<Matrix<f64>, Matrix<f64>> for NeuralNet<'a, T, A>
Supervised learning for the Neural Network.
The model is trained using back propagation.
Source§impl<C: Criterion> SupModel<Matrix<f64>, Vector<f64>> for GenLinearModel<C>
Supervised model trait for the GLM.
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§impl SupModel<Matrix<f64>, Vector<f64>> for LinRegressor
impl SupModel<Matrix<f64>, Vector<f64>> for LinRegressor
Source§fn train(
&mut self,
inputs: &Matrix<f64>,
targets: &Vector<f64>,
) -> LearningResult<()>
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§impl<A> SupModel<Matrix<f64>, Vector<f64>> for LogisticRegressor<A>where
A: OptimAlgorithm<BaseLogisticRegressor>,
impl<A> SupModel<Matrix<f64>, Vector<f64>> for LogisticRegressor<A>where
A: OptimAlgorithm<BaseLogisticRegressor>,
Source§fn train(
&mut self,
inputs: &Matrix<f64>,
targets: &Vector<f64>,
) -> LearningResult<()>
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§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.
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§impl<T: Float> Transformer<Matrix<T>> for MinMaxScaler<T>
impl<T: Float> Transformer<Matrix<T>> for MinMaxScaler<T>
Source§impl<R: Rng, T> Transformer<Matrix<T>> for Shuffler<R>
The Shuffler will transform the input Matrix by shuffling
its rows in place.
impl<R: Rng, T> Transformer<Matrix<T>> for Shuffler<R>
The Shuffler will transform the input Matrix by shuffling
its rows in place.
Under the hood this uses a Fisher-Yates shuffle.