3 releases

0.0.3 Jan 28, 2024
0.0.2 Oct 28, 2023
0.0.1 May 29, 2023

#147 in Machine learning

Download history 39/week @ 2024-02-26 43/week @ 2024-04-01 109/week @ 2024-04-22

152 downloads per month

MIT/Apache and GPL-2.0 licenses

52KB
1.5K SLoC

wisard - A library for WiSARD nets in Rust

License

Summary

WiSARD (Wilkie, Stonham, Aleksander Recognition Device) is an alternative, weightless type of neural network known for its high-speed pattern recognition capabilities and simplicity. This project is a Rust implementation of WiSARD nets, providing a lightweight, efficient, and user-friendly library for building, training, and evaluating models.

This implementation aims to harness the language's performance, safety, and concurrency features, to make it ideal for both research and production-grade applications. We aim to provide a flexible and extensible foundation for developing pattern recognition systems that can be deployed in various domains such as image recognition and signal processing.

Please note that this is a work in progress and it is not yet ready to be used in production environments.

Features

  • Fast and efficient implementation of WiSARD nets.
  • Relevant sample encoding functions for data preprocessing.
  • Customizable build-time and run-time parameters for controlling the model behavior.
  • Support for various data types, including binary, categorical, and continuous inputs.

Installation

To use WiSARD in your Rust project, add the following line to your Cargo.toml file:

[dependencies]
wisard = "0.0.1"

For additional installation options and guidance, please refer to the crate documentation.

Usage

Here's a simple example demonstrating how to create and train a basic WiSARD model using the wisard crate:

use std::collections::HashSet;

use bitvec::prelude::*;
use wisard::model::BinaryWisard;

fn main() {
    // The size of the input (in bits)
    let input_size = 8;
    
    // The size of the address (in bits)
    let addr_size = 2;
    
    // The set of labels used by the samples
    let labels = HashSet::from_iter(vec!["cold", "hot"].into_iter());

    // Create a new WiSARD model
    let mut model = BinaryWisard::new(input_size, addr_size, labels);

    // Provide some sample data
    let samples = vec![
        (bitvec![1, 1, 1, 0, 0, 0, 0, 0], "cold"),
        (bitvec![1, 1, 1, 1, 0, 0, 0, 0], "cold"),
        (bitvec![0, 0, 0, 0, 1, 1, 1, 1], "hot"),
        (bitvec![0, 0, 0, 0, 0, 1, 1, 1], "hot"),
    ];

    // Instantiate the samples
    let samples = samples
        .into_iter()
        .map(|(v, l)| Sample::from_raw_parts(v, addr_size, l))
        .collect::<Vec<_>>();

    // Train the model using each provided sample
    for sample in encoded_samples.iter() {
        model.fit(sample);
    }

    // Display the model predictions
    for sample in encoded_samples.iter() {
        let input = sample.raw_bits();
        let true = sample.label();
        let pred = model.predict(sample);
        println!("Input: {input:?}, True: {true:?}, Pred: {pred:?}");
    }
}

For more detailed examples and usage instructions, please consult the documentation.

Contribution

Contributions to the wisard project are welcome! If you find a bug or have suggestions for improvements, please open an Issue. Pull requests for new features, bug fixes, and documentation enhancements are also appreciated.

License

wisard is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details. Opening a pull request is assumed to signal agreement with these licensing terms.

Dependencies

~2–2.7MB
~59K SLoC