New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

perceptron-rust

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perceptron-rust

  • 0.1.3
  • PyPI
  • Socket score

Maintainers
1

Perceptron-Rust

A basic implementation of the Perceptron algorithm as a Python package, using Rust.

Installation

This package is available via PyPI, meaning you can use pip to install it.

pip install perceptron-rust

Usage

Install the Perceptron-rust package, then import it under the name perceptron-rust. A short example:

from perceptron_rust import Perceptron

dimensions = 2
samples = [
    ([ 1, 1],-1),
    ([-1, 1], 1),
    ([ 1,-1],-1),
    ([-1,-1], 1)
]

p = Perceptron(dimensions, samples)
p.train(iterations=10)

Have a look at the example file example.py for a more complex example.

Training Data format

Training data has to be provided in annotated sets. The data exists as a list, and each element is a tuple. Data, then the label. The data is a list of numbers (with the same dimension as you initialized the Perceptron with), and the label is either a 1 or -1. E.g.:

data = [
    ([1, 0, 0], -1),
    ([0, 1, 0],  1),
    ([0, 0, 1], -1),
]

Methods available

p.add_samples(data)

Appends samples to the currently stored set. Make sure they follow the data format described above.

p.clear_samples()

Removes all samples already stored. (If some training has occurred, this will finalize the training.)

p.replace_samples(samples)

Clears all existing samples and adds the provided samples. Make sure these follow the data format described above.

p.train(iterations, should_normalize=True)

Trains for number of iterations provided. Calling this method multiple times will train it in steps. Once training has started, you cannot change the samples any more. You can normalize the output, but this will finalize the model. It cannot be trained further after this.

Properties (read-only)

dimensions - The dimensions of the data expected by the machine.
model - The calculated model. Will be a null-vector until training.
state - One of "State", "Trained" or "Finished", indicating the current state of the machine.
data - All the data fed into the machine so far.

Development

This package is developed using Maturin. There are other alternatives available. If you are in doubt, please reach out.

The steps are roughly as follows:

  1. Install Maturin
  2. Create a virtual environment for Python, and activate it.
  3. Run maturin develop to automatically build and install the package.
  4. Start Python (perceptron will be available for import).

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc