-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f468d2
commit cf1d37f
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cargo-features = ["edition2024"] | ||
|
||
[package] | ||
name = "RustML" | ||
version = "1.0.0" | ||
edition = "2024" | ||
authors = ["Mitchell Shibilski-Unkel"] | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# RustML | ||
Open-source AI Library for Rust | ||
|
||
## About | ||
`RustML` is an AI/machine learning library built for the `Rust` programming language. It's desgined to work similarly to `Python` libraries, such as PyTorch & Tensorflow. | ||
|
||
## Current Functions & Features | ||
- Sigmod function | ||
```rust | ||
Sigmod(x: i32) -> i32 | ||
``` | ||
|
||
- ReLU function | ||
```rust | ||
ReLU(x: i32) -> i32 | ||
``` | ||
|
||
- Softmax function | ||
```rust | ||
Softmax(x: &[i32]) -> f64 | ||
``` | ||
|
||
- RNN algoritm | ||
```rust | ||
RNN(x: &[i32], y: &[i32], weights: &[i32], bias: i32) -> Vec<i32> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod rustml; | ||
|
||
fn main() { | ||
let RML = rustml::RustML; | ||
let test: [i32; 4] = [1, 2, 3, 4]; | ||
let testy: [i32; 4] = [5, 6, 7, 8]; | ||
let testw: [i32; 4] = [55, 66, 77, 88]; | ||
println!("{:?}", RML.RNN(&test, &testy, &testw, 1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
pub struct RustML; | ||
impl RustML { | ||
fn sum(x: &[i32]) -> i32 { | ||
x.iter().sum() | ||
} | ||
|
||
fn exp(x: i32) -> i32 { | ||
f64::exp(x as f64) as i32 | ||
} | ||
|
||
pub fn Sigmod(x: i32) -> i32 { | ||
1 / (1 + Self::exp(-x)) | ||
} | ||
|
||
pub fn Softmax(x: &[i32]) -> f64 { | ||
// Apply exp to each element and then sum the results | ||
let exp_x: Vec<i32> = x.iter().map(|&v| Self::exp(v)).collect(); | ||
let sum_exp_x = Self::sum(&exp_x); | ||
|
||
// Return the Softmax result as a float (f64) to avoid integer division | ||
exp_x.iter().map(|&v| v as f64 / sum_exp_x as f64).sum() | ||
} | ||
|
||
pub fn ReLU(x: i32) -> i32 { | ||
std::cmp::max(0, x) | ||
} | ||
|
||
pub fn RNN(&self, x: &[i32], y: &[i32], weights: &[i32], bias: i32) -> Vec<i32> { | ||
let mut yt: Vec<i32> = Vec::new(); | ||
|
||
// ht (hidden state) calculation using Sigmoid | ||
for i in 0..x.len() { | ||
let temp_value: i32 = (x[i] * weights[i]) + y[i] + bias; | ||
yt.push(Self::Sigmod(temp_value)); | ||
} | ||
|
||
yt | ||
} | ||
} |