Warning: The library still in development and is not yet ready for production use.
Note: It is important to note that a primary consideration of the concision framework is ensuring compatibility in two key areas:
autodiff: the upcoming feature enabling rust to natively support automatic differentiation.ndarray: The crate is designed around thendarraycrate, which provides a powerful N-dimensional array type for Rust
- Provide a flexible and extensible framework for building neural network models in Rust.
- Support both shallow and deep neural networks with a focus on modularity and reusability.
- Enable easy integration with other libraries and frameworks in the Rust ecosystem.
- v1:
-
ParamsBase: Design a basic structure for storing model parameters. - Traits: Create a set of traits for defining the basics of a neural network model.
ForwardandBackward: traits defining forward and backward propagationModel: A trait for defining a neural network model.Predict: A trait extending the basicForwardpass.Train: A trait for training a neural network model.
-
- v2:
- Models:
Trainer: A generic model trainer that can be used to train any model.
- Layers: Implement a standard model configuration and parameters.
LayerBase: functional wrappers for theParamsBasestructure.
- Models:
To use concision in your project, add the following to your Cargo.toml:
[dependencies.concision]
features = ["full"]
version = "0.2.x" extern crate concision as cnc;
use cnc::activate::{ReLU, Sigmoid};
use cnc::nn::{Model, ModelFeatures, DeepModelParams, StandardModelConfig};
use ndarray::{Array1, ScalarOperand};
use num::Float;
pub struct SimpleModel<T = f64> {
pub config: StandardModelConfig<T>,
pub features: ModelFeatures,
pub params: DeepModelParams<T>,
}
impl<T> SimpleModel<T> {
pub fn new(config: StandardModelConfig<T>, features: ModelFeatures) -> Self
where
T: Clone + num::Zero
{
let params = DeepModelParams::zeros(features);
SimpleModel {
config,
features,
params,
}
}
}
impl<T> cnc::Forward<Array1<T>> for SimpleModel<T>
where
T: Float + ScalarOperand,
cnc::Params<T>: cnc::Forward<Array1<T>, Output = Array1<T>>,
{
type Output = Array1<T>;
fn forward(&self, input: &Array1<T>) -> Result<Self::Output, cnc::Error>
where
T: Clone,
{
let mut output = self.params().input().forward(input)?.relu();
for layer in self.params().hidden() {
output = layer.forward(&output)?.sigmoid();
}
let res = self.params().output().forward(&output)?;
Ok(res.relu())
}
}
impl<T> Model<T> for SimpleModel<T> {
type Config = StandardModelConfig<T>;
fn config(&self) -> &StandardModelConfig<T> {
&self.config
}
fn config_mut(&mut self) -> &mut StandardModelConfig<T> {
&mut self.config
}
fn features(&self) -> ModelFeatures {
self.features
}
fn params(&self) -> &DeepModelParams<T> {
&self.params
}
fn params_mut(&mut self) -> &mut DeepModelParams<T> {
&mut self.params
}
}To use concision, you need to have the following installed:
- Rust (version 1.85 or later)
You can install the rustup toolchain using the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shAfter installing rustup, you can install the latest stable version of Rust with:
rustup install stableYou can also install the latest nightly version of Rust with:
rustup install nightlyStart by cloning the repository
git clone https://github.com/FL03/concision.gitThen, navigate to the concision directory:
cd concisionTo build the crate, you can use the cargo tool. The following command will build the crate with all features enabled:
cargo build -r --locked --workspace --features fullTo run the tests, you can use the following command:
cargo test -r --locked --workspace --features fullPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.