Skip to content

Commit

Permalink
add first example
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxHalford committed Oct 7, 2023
1 parent e8d646c commit 72e1660
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 72 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ opt-level = 0
[profile.release]
opt-level = 3

[[bench]]
[[example]]
name = "credit_card"
harness = false
path = "examples/anomaly_detection/credit_card.rs"
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>🦀 LightRiver • fast online machine learning</h1>
<h1>🦀 LightRiver • fast and simple online machine learning</h1>

<p>

Expand All @@ -25,12 +25,34 @@
<img src="https://github.com/online-ml/light-river/assets/8095957/fc8ea218-62f9-4643-b25d-f9265ef962f8" width="25%" align="right" />
</div>

LightRiver is an online machine learning library written in Rust. It is meant to be used in high-throughput environments, as well as TinyML systems.
Reed is an online machine learning library written in Rust. It is meant to be used in high-throughput environments, as well as TinyML systems.

This library is complementary to [River](https://github.com/online-ml/river/). The latter provides a wide array of online methods, but is not ideal when it comes to performance. The idea is to take the algorithms that work best in River, and implement them in a way that is more performant. As such, LightRiver is not meant to be a general purpose library. It is meant to be a fast online machine learning library that provides a few algorithms that are known to work well in online settings. This is a akin to the way [scikit-learn](https://scikit-learn.org/) and [LightGBM](https://lightgbm.readthedocs.io/en/stable/) are complementary to each other.

## 🧑‍💻 Usage

### 🚨 Anomaly detection

```sh
cargo run --release --example credit_card
```

### 📈 Regression

🏗️ We plan to implement Aggregated Mondrian Forests.

### 📊 Classification

🏗️ We plan to implement Aggregated Mondrian Forests.

### 🛒 Recsys

🏗️ [Vowpal Wabbit](https://vowpalwabbit.org/) is very good at recsys via contextual bandits. We don't plan to compete with it. Eventually we want to research a tree-based contextual bandit.

## 🚀 Performance

TODO: add a `benches` directory

## 📝 License

LightRiver is free and open-source software licensed under the [3-clause BSD license](LICENSE).
68 changes: 0 additions & 68 deletions benches/credit_card.rs

This file was deleted.

25 changes: 25 additions & 0 deletions examples/anomaly_detection/credit_card.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use light_river::anomaly::half_space_tree::HalfSpaceTree;
use light_river::datasets::credit_card::CreditCard;
use std::time::Instant;

fn main() {
let now = Instant::now();

// PARAMETERS
let window_size: u32 = 1000;
let n_trees: u32 = 50;
let height: u32 = 6;

// INITIALIZATION
let mut hst = HalfSpaceTree::new(window_size, n_trees, height, None);

// LOOP
let transactions = CreditCard::load_credit_card_transactions().unwrap();
for transaction in transactions {
let observation = transaction.unwrap().get_observation();
let _ = hst.update(&observation, true, true);
}

let elapsed_time = now.elapsed();
println!("Took {}ms", elapsed_time.as_millis());
}
2 changes: 2 additions & 0 deletions src/anomaly/half_space_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use std::mem;
use crate::common::Observation;

// Return the index of a node's left child node.
#[inline]
fn left_child(node: u32) -> u32 {
node * 2 + 1
}

// Return the index of a node's right child node.
#[inline]
fn right_child(node: u32) -> u32 {
node * 2 + 2
}
Expand Down

0 comments on commit 72e1660

Please sign in to comment.