An open API service indexing awesome lists of open source software.

https://github.com/brunos3d/perceptron-even-odd-classifier

Interactive visualization of a perceptron neural network that classifies numbers as even or odd using JavaScript and D3.js.
https://github.com/brunos3d/perceptron-even-odd-classifier

ai bias even example input math neural-network neuron odd output perceptron sample study train

Last synced: 4 months ago
JSON representation

Interactive visualization of a perceptron neural network that classifies numbers as even or odd using JavaScript and D3.js.

Awesome Lists containing this project

README

          

# ๐Ÿง  Perceptron Visualizer: Even or Odd Classifier

This project is an interactive JavaScript visualization of a perceptron neural network that learns to classify numbers as **even or odd**. It provides a live, browser-based interface with visualization powered by D3.js.

---

## ๐Ÿš€ Features

- ๐Ÿ” Input a number and test if it's classified as even or odd
- ๐Ÿง  Visual graph of the neural network structure (input โ†’ neuron โ†’ output)
- โš™๏ธ Train automatically until reaching a target accuracy
- โน๏ธ Stop training at any time
- ๐Ÿ“Š Live display of weights, bias, epoch count, and accuracy

---

## ๐Ÿ“š How It Works

This project uses a **single-layer perceptron** โ€” the simplest form of a neural network โ€” to classify numbers.

### ๐Ÿงฎ Perceptron Equation

The perceptron calculates the output `y` from input `x` using:

```
y = f(w * x + b)
```

Where:
- `x` is the input (in this case, `x = n % 2`)
- `w` is the weight
- `b` is the bias
- `f(z)` is the activation function:
```
f(z) = {
1, if z >= 0.5
0, otherwise
}
```

The output `y` will be:
- `1` for odd numbers
- `0` for even numbers

### ๐Ÿ” Training Rule

Each epoch updates weights using the perceptron learning rule:

```
error = expected - predicted
w = w + learningRate * error * x
b = b + learningRate * error
```

This update process is repeated until the accuracy reaches a user-defined threshold.

---

## ๐ŸŽจ Visualization

D3.js is used to render a simple visual of the perceptron network:
- **Input Node**
- **Single Neuron**
- **Output Node**

These are connected with lines and display live updates of current weights and bias.

---

## ๐Ÿงช Usage

1. Open `index.html` in your browser.
2. Enter a minimum accuracy (default: 90%).
3. Click **Train Perceptron**.
4. The network will train until the desired accuracy is reached.
5. Use **Test Number** to verify the classification of any integer.
6. Click **Stop Training** to manually halt training.

---

## ๐Ÿ›  Tech Stack

- **HTML5**
- **JavaScript (Vanilla)**
- **D3.js v7**

No build tools or dependencies required โ€” just open the HTML file in your browser.

---

## ๐Ÿง  Educational Purpose

This project is meant as a learning tool to demonstrate:
- How perceptrons work
- Binary classification
- Live training feedback
- Basic D3.js visualizations

---

## ๐Ÿ“„ License

MIT โ€” Free to use, modify, and share.