This project implements a simple perceptron-based AI in Sinclair ZX Spectrum BASIC. The program allows you to train perceptrons on basic logic gates (AND, OR, NOT) using fundamental machine learning concepts such as weights, bias, and learning rate. The goal is to demonstrate how a perceptron learns through training iterations, updating its weights based on training data, and evaluating predictions.
- Train a perceptron to solve basic logic gates: OR, AND, NOT.
- Implemented in ZX Spectrum BASIC, showcasing the early days of computing and machine learning concepts.
- Adjustable hyperparameters such as learning rate, epochs, and bias.
- Training is done in a simple loop, where weights are adjusted based on error feedback.
-
Run the Program:
- Load the BASIC code into your ZX Spectrum emulator or real ZX Spectrum.
- After execution, you'll be prompted to select a logic gate (OR, AND, NOT) to train.
-
Training the Perceptron:
- The perceptron will go through multiple epochs, adjusting weights and biases as it learns from the training data.
- After training, the model will make predictions based on input data and output the results.
-
Test with Different Logic Gates:
- You can train and evaluate the perceptron with different gates using the provided datasets.
- Learning Rate: Determines how quickly the model adjusts its weights during training. It is set to 0.1 by default.
- Epochs: The total number of times the training dataset is processed. The default is set to 30.
- Bias: A parameter that helps improve model accuracy by allowing the function to shift away from the origin.
- The program starts by asking you to choose a logic gate (OR, AND, or NOT).
- It initializes random weights and the bias.
- The perceptron is trained using the selected gate's training data, adjusting its weights over several epochs.
- Once training is complete, the model evaluates predictions for new input data.
The code is heavily documented with detailed comments throughout. Specific callouts to the syntax of the Sinclair ZX Spectrum BASIC language are provided, marked with the prefix "Learn Sinclair ZX Spectrum BASIC". These comments explain important language features such as:
- Variable naming conventions
- Array indexing (starting at 1)
- Specific nuances of BASIC on the ZX Spectrum
- How to structure subroutines and handle global variables
This documentation makes it easier to understand the unique characteristics of Sinclair ZX Spectrum BASIC and serves as a helpful guide for anyone learning or revisiting this vintage language.
- Blog Post on Running a Perceptron on an 8-bit computer - My original post covering this program, which contains a brief explanation of how the perceptron algorithm works.
- YouTube Video: Running a Perceptron on an 8-bit computer - A step-by-step video guide on running the program on a great ZX Spectrum emulator.
This project is licensed under the MIT License - see the LICENSE file for details.
- Author: Andre Lessa
- Website: LessaWorld.com