Crates.io | concision-kan |
lib.rs | concision-kan |
version | 0.2.7 |
created_at | 2024-05-10 20:18:04.996122+00 |
updated_at | 2025-07-03 04:12:38.077323+00 |
description | this crate implements the kan model using the concision framework |
homepage | https://github.com/FL03/concision/wiki |
repository | https://github.com/FL03/concision.git |
max_upload_size | |
id | 1236300 |
size | 48,449 |
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 the ndarray
crate, which provides a powerful N-dimensional array type for RustParamsBase
: Design a basic structure for storing model parameters.Forward
and Backward
: traits defining forward and backward propagationModel
: A trait for defining a neural network model.Predict
: A trait extending the basic Forward
pass.Train
: A trait for training a neural network model.Trainer
: A generic model trainer that can be used to train any model.LayerBase
: functional wrappers for the ParamsBase
structure.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:
You can install the rustup
toolchain using the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After installing rustup
, you can install the latest stable version of Rust with:
rustup install stable
You can also install the latest nightly version of Rust with:
rustup install nightly
Start by cloning the repository
git clone https://github.com/FL03/concision.git
Then, navigate to the concision
directory:
cd concision
cargo
toolTo 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 full
To run the tests, you can use the following command:
cargo test -r --locked --workspace --features full
Pull 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.