Skip to content

Commit

Permalink
master
Browse files Browse the repository at this point in the history
  • Loading branch information
Devarth123 committed Jun 11, 2022
1 parent 7d001fc commit 0106e0b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 74 deletions.
61 changes: 30 additions & 31 deletions src/ml/f32/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,46 @@ use std::fs;
pub fn breaker(not_formated_string: &str) -> Vec<String> {
// print!("{not_formated_string}");
let mut formated_string: Vec<String> = Vec::new();
let mut push_str = String::new();
for i in not_formated_string.chars(){
if i == '\n'{
formated_string.push(push_str.clone());
}else{
push_str.push(i);
let mut push_str = String::new();
for i in not_formated_string.chars() {
if i == '\n' {
formated_string.push(push_str.clone());
} else {
push_str.push(i);
}
}
formated_string
}

pub fn count_new_lines(string: &str) -> u16{
pub fn count_new_lines(string: &str) -> u16 {
let mut new_lines = 0;
for i in string.chars(){
if i == '\n'{
new_lines+=1;
for i in string.chars() {
if i == '\n' {
new_lines += 1;
}
}
new_lines
}
pub fn read_csv(path_of_the_file: &str, how_many_lines_do_want: u8) -> Vec<Vec<f32>>{
let data: String = fs::read_to_string(&path_of_the_file).unwrap();
let data = breaker(&data);
let mut str_to_f32: Vec<Vec<f32>> = Vec::new();
for i in data{
let mut push_vec: Vec<f32> = vec![];
for j in i.chars() {
if j != ','{
// let push_element: f32 = j
// .to_string()
// .parse()
// .expect("The methmod is not working at line 36\n {}");
push_vec.push(j
.to_string()
.parse::<f32>()
.expect("the method is not working at line 40"));
}
pub fn read_csv(path_of_the_file: &str, how_many_lines_do_want: u8) -> Vec<Vec<f32>> {
let data: String = fs::read_to_string(&path_of_the_file).unwrap();
let data = breaker(&data);
let mut str_to_f32: Vec<Vec<f32>> = Vec::new();
for i in data {
let mut push_vec: Vec<f32> = vec![];
for j in i.chars() {
if j != ',' {
// let push_element: f32 = j
// .to_string()
// .parse()
// .expect("The methmod is not working at line 36\n {}");
push_vec.push(
j.to_string()
.parse::<f32>()
.expect("the method is not working at line 40"),
);
}
}
str_to_f32.push(push_vec);
}
str_to_f32.push(push_vec);
}
str_to_f32
}


2 changes: 1 addition & 1 deletion src/ml/f64.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod matrix;
pub mod img;
pub mod nn;
pub mod read;
pub mod activation;
pub mod gernerate;

4 changes: 3 additions & 1 deletion src/ml/f64/gernerate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extern crate rand;

use rand::Rng;
use std::collections::HashMap;

pub fn storing_labels<'a>(formated_data: &'a Vec<f32>, labels: &mut HashMap<u16, &'a [f32]>) {
labels.insert(formated_data[0] as u16, &formated_data[1..]);
}



pub fn gernerate_imgs<'a>(
labels: HashMap<u16, &'a Vec<Vec<f32>>>,
range: &u32,
Expand Down
8 changes: 8 additions & 0 deletions src/ml/f64/img.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::ml::f64::matrix;

pub struct Img {
label: u8,
matrix: matrix::MatrixStruct,
}


10 changes: 9 additions & 1 deletion src/ml/f64/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub struct MatrixStruct{
pub rows: u16,
pub columns: u16,
pub columns: u16,
pub matrix: Vec<Vec<f64>>,
}
pub fn matrix_create<'a>(row: &'a u16, column: &'a u16) -> MatrixStruct{
Expand All @@ -11,6 +11,14 @@ pub fn matrix_create<'a>(row: &'a u16, column: &'a u16) -> MatrixStruct{
matrix: vec,
}
}
pub fn matrix_display(m: &MatrixStruct){
for i in 0..m.rows as usize{
for j in 0..m.columns as usize{
print!("{}", m.matrix[i][j]);
}
println!();
}
}
pub fn positive(f: &f64) -> f64{
if *f<0.0{
return *f * -1_f64;
Expand Down
118 changes: 78 additions & 40 deletions src/ml/f64/read.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,87 @@
use crate::ml::f64::img;
use crate::ml::f64::matrix;
use std::fs;

pub fn breaker(not_formated_string: &str) -> Vec<String> {
// print!("{not_formated_string}");
let mut formated_string: Vec<String> = Vec::new();
let mut push_str = String::new();
for i in not_formated_string.chars(){
if i == '\n'{
formated_string.push(push_str.clone());
}else{
push_str.push(i);
}
}
formated_string
}

pub fn count_new_lines(string: &str) -> u16{
// pub fn breaker(not_formated_string: &str) -> Vec<String> {
// // print!("{not_formated_string}");
// let mut formated_string: Vec<String> = Vec::new();
// let mut push_str = String::new();
// for i in not_formated_string.chars() {
// if i == '\n' {
// formated_string.push(push_str.clone());
// } else {
// push_str.push(i);
// }
// }
// formated_string
// }
//
pub fn count_new_lines(string: &str) -> u16 {
let mut new_lines = 0;
for i in string.chars(){
if i == '\n'{
new_lines+=1;
for i in string.chars() {
if i == '\n' {
new_lines += 1;
}
}
new_lines
}
pub fn read_csv(path_of_the_file: &str, how_many_lines_do_want: u8) -> Vec<Vec<f32>>{
let data: String = fs::read_to_string(&path_of_the_file).unwrap();
let data = breaker(&data);
let mut str_to_f32: Vec<Vec<f32>> = Vec::new();
for i in data{
let mut push_vec: Vec<f32> = vec![];
for j in i.chars() {
if j != ','{
// let push_element: f32 = j
// .to_string()
// .parse()
// .expect("The methmod is not working at line 36\n {}");
push_vec.push(j
.to_string()
.parse::<f32>()
.expect("the method is not working at line 40"));
}
// pub fn matrix_fit(unformated_data: &Vec<f64>) -> matrix::MatrixStruct{
//
// }
// pub fn matrix_fit(unformated_data: &Vec<f64>) -> matrix::MatrixStruct{
// let mut matrix = matrix::matrix_create(&28, &28);
// for i in 0..28{
// let mut multiplier = 0;
// for j in 0..28{
// matrix.matrix[i][j] = unformated_data[j+multiplier];
// }
// multiplier += 28;
// }
// matrix
// }
// pub fn read_csv(path_of_the_file: &str, how_many_lines_do_want: &u8) -> Vec<Vec<f64>> {
// let data = breaker(&fs::read_to_string(&path_of_the_file).unwrap());
// let mut counter = 0;
// let mut str_to_f32: Vec<Vec<f64>> = Vec::new();
// for i in &data {
// let mut push_vec: Vec<f64> = vec![0.0; 28];
// for j in i.chars() {
// match j {
// j if j != ',' => push_vec.push(
// j.to_string()
// .parse::<f64>()
// .expect("the method at line 64 is not working as expected"),
// ),
// '\n' => counter += 1,
// _ => (),
// }
// if counter == *how_many_lines_do_want {
// break;
// }
// }
// str_to_f32.push(push_vec);
// }
// str_to_f32
// }
pub fn line(line_no: &u16, lines: &std::str::Lines) -> String{
let mut str = "";
for i in 0..*line_no{
if i == line_no -1 {
str = lines.next().unwrap();
}else {
lines.next();
}
}
str.to_string()
}
pub fn read_csv(path_of_the_file: &str, lines: &u8) -> matrix::MatrixStruct {
let imgs: Vec<Vec<img::Img>> = Vec::with_capacity(*lines as usize);
static MAXCHAR: u16 = 10000;
let lines: String = (fs::read_to_string(path_of_the_file).unwrap()).lines();
let mut i: u16 = 0;
while i < *lines {
let j = 0;
x
i += 1;
}
str_to_f32.push(push_vec);
}
str_to_f32
}


0 comments on commit 0106e0b

Please sign in to comment.