| Crates.io | octopus |
| lib.rs | octopus |
| version | 0.1.0 |
| created_at | 2025-06-22 10:24:59.94992+00 |
| updated_at | 2025-06-22 10:24:59.94992+00 |
| description | A fast, flexible framework for multi-armed bandit strategies in Rust. |
| homepage | https://github.com/NewBornRustacean/octopus |
| repository | https://github.com/NewBornRustacean/octopus |
| max_upload_size | |
| id | 1721516 |
| size | 57,999 |
A generic, multi-threaded, and ergonomic Rust crate for Multi-Armed Bandit (MAB) algorithms—designed for engineers who need extensibility, custom reward modeling, and a clear path to contextual bandits.
Epsilon-Greedy, UCB1, Thompson SamplingLinUCB, etc.// Action: Represents an arm/action in the bandit problem
pub trait Action: Clone + Eq + Hash + Send + Sync + 'static {
type ValueType;
fn id(&self) -> usize;
fn name(&self) -> String { ... }
fn value(&self) -> Self::ValueType;
}
// Reward: Represents the reward signal
pub trait Reward: Clone + Send + Sync + 'static {
fn value(&self) -> f64;
}
// Context: Represents contextual information (for contextual bandits)
pub trait Context: Clone + Send + Sync + 'static {
type DimType: ndarray::Dimension;
fn to_ndarray(&self) -> ndarray::Array<f64, Self::DimType>;
}
// BanditPolicy: Core trait for all bandit algorithms
pub trait BanditPolicy<A, R, C>: Send + Sync + 'static
where
A: Action,
R: Reward,
C: Context,
{
fn choose_action(&self, context: &C) -> A;
fn update(&mut self, context: &C, action: &A, reward: &R);
fn reset(&mut self);
}
// Environment: Simulated environment for running experiments
pub trait Environment<A, R, C>: Send + Sync + 'static { ... }
epsilon_greedy::EpsilonGreedyPolicyepsilon: f64, initial actionsSimulator struct orchestrates the interaction between a bandit policy and an environment.SimulationResults.Example:
use octopus::algorithms::epsilon_greedy::EpsilonGreedyPolicy;
use octopus::simulation::simulator::Simulator;
use octopus::traits::entities::{Action, Reward, Context, DummyContext};
// Define your own Action, Reward, and Environment types implementing the required traits
// ...
let actions = vec![/* your actions here */];
let mut policy = EpsilonGreedyPolicy::new(0.1, &actions).unwrap();
let environment = /* your environment here */;
let mut simulator = Simulator::new(policy, environment);
let results = simulator.run(1000, &actions);
println!("Cumulative reward: {}", results.cumulative_reward);
rayon and thread-safe primitives (Mutex).ndarray for context featuresrayon for parallelismthiserrorserde for serializationUCB1, LinUCB etc.