Matrix

Struct Matrix 

Source
pub struct Matrix {
    pub data: Vec<f64>,
    pub width: usize,
    pub height: usize,
    pub transposed: bool,
}

Fields§

§data: Vec<f64>§width: usize§height: usize§transposed: bool

Implementations§

Source§

impl Matrix

Source

pub fn init_zero(height: usize, width: usize) -> Matrix

Source

pub fn init(height: usize, width: usize, data: Vec<f64>) -> Matrix

Source

pub fn init_rand(height: usize, width: usize) -> Matrix

Source

pub fn get(&self, row: usize, column: usize) -> f64

Examples found in repository?
examples/mnist.rs (line 62)
61fn _print_a_number(labels: Matrix, images: Matrix, v: usize) {
62    println!("{}", labels.get(0, v));
63
64    for i in 0..28 * 28 {
65        if images.get(v, i) > 0.5 && images.get(v, i) < 1.0 {
66            if i % 28 == 0 {
67                print!("\n");
68            }
69
70            if images.get(v, i) > 0.5 && images.get(v, i) < 0.75 {
71                print!("-");
72            } else {
73                print!("*");
74            }
75        } else {
76            if i % 28 == 0 {
77                print!("\n");
78            }
79            print!("_");
80        }
81    }
82}
Source

pub fn get_1d(&self, index: usize) -> f64

Source

pub fn get_row(&self, row: usize) -> Vec<f64>

Source

pub fn set(&mut self, value: f64, row: usize, column: usize)

Source

pub fn set_1d(&mut self, value: f64, index: usize)

Source

pub fn set_row(&mut self, new_row: &Vec<f64>, row: usize)

Source

pub fn dot(&self, m: &Matrix) -> Matrix

Source

pub fn add_1d_matrix_to_all_rows(&self, m: &Matrix) -> Matrix

Source

pub fn max(&self) -> f64

Source

pub fn min(&self) -> f64

Source

pub fn normalize(&mut self)

Examples found in repository?
examples/mnist.rs (line 20)
14pub fn testing() {
15    println!("extracting mnist data...");
16    let labels: Matrix = extract_labels("t10k-labels.idx1-ubyte");
17    let mut images: Matrix = extract_images("t10k-images.idx3-ubyte");
18    println!("extraction done");
19
20    images.normalize();
21    println!("number of images {}", images.height);
22    println!("number of pixels in each image {}", images.width);
23
24    println!("loading pre-trained model...");
25    let mut model: Model = load_model("mnist_128x128".to_string()).unwrap();
26
27    println!("evaluating...");
28    let score = model.evaluate(&images, false);
29    let acc = model.accuracy(&score, &labels);
30
31    println!("acc : {}", acc);
32}
33
34pub fn training() {
35    println!("extracting mnist data...");
36    let labels: Matrix = extract_labels("train-labels.idx1-ubyte");
37    let mut images: Matrix = extract_images("train-images.idx3-ubyte");
38    println!("extraction done");
39
40    images.normalize();
41    println!("number of images {}", images.height);
42    println!("number of pixels in each image {}", images.width);
43
44    ModelBuilder::new()
45        .add_layer(Layer::init(28 * 28, 128, true))
46        .add_layer(Layer::init(128, 128, true))
47        .add_layer(Layer::init(128, 10, false))
48        .optimizer(Optimizer::Adam {
49            learning_step: 0.001,
50            beta1: 0.9,
51            beta2: 0.999,
52        })
53        .l2_reg(0.001)
54        .checkpoint(Checkpoint::ValAcc {
55            save_path: "mnist_128x128".to_string(),
56        })
57        .verbose(10, false)
58        .build_and_train(&images, &labels, 128, 10, 2000);
59}
Source

pub fn transpose_inplace(&mut self)

Source

pub fn t(&self) -> Matrix

Source

pub fn is_equal(&self, m: &Matrix, precision: i32) -> bool

Source

pub fn exp_inplace(&mut self)

Source

pub fn sqrt_inplace(&mut self)

Source

pub fn exp(&self) -> Matrix

Source

pub fn pow_inplace(&mut self, a: i32)

Source

pub fn pow(&self, a: i32) -> Matrix

Source

pub fn sum(&self) -> f64

Source

pub fn sum_rows(&self) -> Matrix

Source

pub fn add_inplace(&mut self, a: f64)

Source

pub fn div_inplace(&mut self, a: f64)

Source

pub fn div(&self, a: f64) -> Matrix

Source

pub fn mult_inplace(&mut self, a: f64)

Source

pub fn mult(&self, a: f64) -> Matrix

Source

pub fn add_two_matrices(&self, m: &Matrix) -> Matrix

Source

pub fn add_two_matrices_inplace(&mut self, m: &Matrix)

Source

pub fn div_two_matrices_inplace(&mut self, m: &Matrix)

Source

pub fn pop_last_row(&mut self)

Source

pub fn compute_d_relu_inplace(&mut self, z_minus_1: &Matrix)

Source

pub fn display(&self)

Source

pub fn convert_to_csv(&self) -> String

Trait Implementations§

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnwindSafe for Matrix

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, 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.
Source§

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

Source§

fn vzip(self) -> V