Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellShibilski-Unkel committed Nov 26, 2024
1 parent 7f468d2 commit cf1d37f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
9 changes: 9 additions & 0 deletions Cargo.toml
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]
24 changes: 24 additions & 0 deletions README.md
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>
```
9 changes: 9 additions & 0 deletions src/example.rs
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));
}
39 changes: 39 additions & 0 deletions src/rustml.rs
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
}
}

0 comments on commit cf1d37f

Please sign in to comment.