diff --git a/Makefile b/Makefile index 8363697..1cb1f8a 100644 --- a/Makefile +++ b/Makefile @@ -51,5 +51,6 @@ debug: build run: build @$(TARGET) -video: - ffmpeg -y -i $(DUMP_DIR)/weights-%d.ppm -vf scale=320:-1 -filter:v "setpts=PTS/15,fps=30" docs/training.mp4 +assets: + @ffmpeg -y -i $(DUMP_DIR)/weights-%d.ppm -vf scale=320:-1 -filter:v "setpts=PTS/15,fps=30" docs/training.mp4 + @convert model.ppm docs/model.png diff --git a/README.md b/README.md index 0159f81..d5c19af 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,29 @@ Implementation of a single-layer perceptron in x86 assembly. I was inspired by the very simple perceptron algorithm described in [Veritasium's video on analog computers](https://youtu.be/GVsUOuSjvcg?t=221). I've also never written any x86 floating point code before, so why not now. +## Results + +500 samples, 3000 train passes, 90% success model + +TODO: picture of model +TODO: link to video of training + +## Perceptron Summary + +A perceptron is a simple mathematical model attempting to mimic how a biological neuron works. +A neuron fires or activates when the dot product of inputs and weights is larger than the specified bias. + +Frank Rosenblatt built the first implementation of a perceptron as a specialized machine in 1958. +Read more about the history of the perceptron [here](https://en.wikipedia.org/wiki/Perceptron#History). + +A single-layer perceptron is the simplest neural network you can make. + ## Run Locally -- dependencies: `apt install nasm feh` +- dependencies: `apt install nasm ffmpeg imagemagick` - build: `make` - build and run: `make run` -- run: `./bin/perceptron` - -ffmpeg -y -i dump/weights-%d.ppm test.mp4 -500 samples, 3000 train passes, 90% success model +- build assets: `make assets` ## References @@ -22,7 +36,7 @@ ffmpeg -y -i dump/weights-%d.ppm test.mp4 - [Perceptron Wikipedia](https://en.wikipedia.org/wiki/Perceptron) - [Compiler Explorer](https://godbolt.org/) - [Veritasium - Future Computers Will Be Radically Different](https://www.youtube.com/watch?v=GVsUOuSjvcg) -- [Linear Congruential Generator](https://en.wikipedia.org/wiki/Linear_congruential_generator) +- [Linear Congruential Generator (Easy random numbers in ASM)](https://en.wikipedia.org/wiki/Linear_congruential_generator) - PPM files - https://manpages.ubuntu.com/manpages/bionic/man5/ppm.5.html - https://people.cs.clemson.edu/~dhouse/courses/405/notes/ppm-files.pdf diff --git a/docs/model.png b/docs/model.png new file mode 100644 index 0000000..99b17ae Binary files /dev/null and b/docs/model.png differ diff --git a/docs/training.mp4 b/docs/training.mp4 new file mode 100644 index 0000000..8a12647 Binary files /dev/null and b/docs/training.mp4 differ diff --git a/inc/config.inc b/inc/config.inc index dd58457..e6166c6 100644 --- a/inc/config.inc +++ b/inc/config.inc @@ -1,10 +1,10 @@ LAYER_LEN: equ 20 ; height/width of layer (square) SAMPLE_SIZE: equ 100 ; sample size for training model - TRAIN_PASSES: equ 2000 ; number of training passes to perform + TRAIN_PASSES: equ 3000 ; number of training passes to perform BIAS: equ __float32__(25.0) ; bias to increase model classification accuracy TRAIN_SEED: equ 0xBEEF ; seed for training model VERIFY_SEED: equ 0xDEAD ; seed for verifying model - DUMP_MAX: equ 50 ; max dump files to generate (debug) - ; 0xC0FFEE for no limit, used to create GIF (SLOW!) \ No newline at end of file + DUMP_MAX: equ 100 ; max dump files to generate (debug) + ; set to 0xC0FFEE for no limit, used to create GIF (SLOW!) \ No newline at end of file diff --git a/model.ppm b/model.ppm index 54cd3c8..912a5fa 100644 --- a/model.ppm +++ b/model.ppm @@ -1,22 +1,22 @@ P3 20 20 255 -164 91 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 164 91 0 196 59 0 228 27 0 4 251 0 228 27 0 228 27 0 228 27 0 228 27 0 228 27 0 196 59 0 164 91 0 164 91 0 132 122 0 132 122 0 -164 91 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 164 91 0 196 59 0 4 251 0 36 219 0 36 219 0 36 219 0 36 219 0 36 219 0 36 219 0 4 251 0 228 27 0 228 27 0 164 91 0 132 122 0 -164 91 0 164 91 0 164 91 0 228 27 0 4 251 0 4 251 0 4 251 0 4 251 0 68 187 0 68 187 0 100 155 0 100 155 0 132 123 0 100 155 0 68 187 0 100 155 0 100 155 0 100 155 0 196 59 0 132 122 0 -196 59 0 196 59 0 196 59 0 4 251 0 68 187 0 68 187 0 68 187 0 68 187 0 164 91 0 164 91 0 228 27 0 196 59 0 228 27 0 132 123 0 68 187 0 100 155 0 100 155 0 100 155 0 196 59 0 132 122 0 -228 27 0 228 27 0 228 27 0 228 27 0 36 219 0 68 187 0 68 187 0 132 123 0 196 59 0 196 59 0 4 251 0 196 59 0 228 27 0 100 155 0 4 251 0 36 219 0 36 219 0 36 219 0 164 91 0 132 122 0 -4 251 0 36 219 0 36 219 0 68 187 0 164 91 0 196 59 0 228 27 0 36 219 0 36 219 0 4 251 0 68 187 0 4 251 0 36 219 0 164 91 0 68 187 0 68 187 0 4 251 0 4 251 0 164 91 0 132 122 0 -228 27 0 228 27 0 4 251 0 36 219 0 100 155 0 132 123 0 196 59 0 4 251 0 4 251 0 228 27 0 4 251 0 228 27 0 36 219 0 196 59 0 100 155 0 132 123 0 36 219 0 36 219 0 196 59 0 132 122 0 -196 59 0 196 59 0 4 251 0 36 219 0 100 155 0 164 91 0 228 27 0 36 219 0 36 219 0 164 91 0 196 59 0 164 91 0 68 187 0 228 27 0 164 91 0 196 59 0 164 91 0 68 187 0 36 219 0 132 122 0 -228 27 0 228 27 0 4 251 0 36 219 0 100 155 0 164 91 0 228 27 0 36 219 0 68 187 0 196 59 0 196 59 0 164 91 0 68 187 0 228 27 0 164 91 0 228 27 0 164 91 0 36 219 0 36 219 0 132 122 0 -4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 132 123 0 164 91 0 196 59 0 228 27 0 100 155 0 68 187 0 68 187 0 228 27 0 164 91 0 100 155 0 228 27 0 164 91 0 68 187 0 68 187 0 132 122 0 -36 219 0 4 251 0 100 155 0 132 123 0 164 91 0 228 27 0 36 219 0 68 187 0 68 187 0 196 59 0 196 59 0 164 91 0 36 219 0 228 27 0 164 91 0 36 219 0 164 91 0 68 187 0 68 187 0 132 122 0 -36 219 0 228 27 0 68 187 0 100 155 0 100 155 0 132 123 0 196 59 0 4 251 0 4 251 0 164 91 0 164 91 0 132 123 0 4 251 0 228 27 0 196 59 0 196 59 0 132 123 0 36 219 0 36 219 0 164 91 0 -68 187 0 4 251 0 100 155 0 132 123 0 100 155 0 100 155 0 164 91 0 228 27 0 228 27 0 100 155 0 132 123 0 100 155 0 228 27 0 164 91 0 132 123 0 132 123 0 100 155 0 228 27 0 4 251 0 164 91 0 -36 219 0 4 251 0 100 155 0 196 59 0 100 155 0 100 155 0 196 59 0 196 59 0 196 59 0 68 187 0 100 155 0 68 187 0 196 59 0 196 59 0 164 91 0 164 91 0 100 155 0 228 27 0 228 27 0 164 91 0 -36 219 0 4 251 0 4 251 0 68 187 0 4 251 0 4 251 0 68 187 0 100 155 0 164 91 0 4 251 0 36 219 0 4 251 0 196 59 0 164 91 0 100 155 0 100 155 0 100 155 0 228 27 0 4 251 0 164 91 0 -4 251 0 228 27 0 4 251 0 36 219 0 228 27 0 4 251 0 68 187 0 132 123 0 164 91 0 36 219 0 68 187 0 36 219 0 196 59 0 164 91 0 100 155 0 68 187 0 36 219 0 228 27 0 228 27 0 164 91 0 -4 251 0 228 27 0 4 251 0 36 219 0 228 27 0 4 251 0 4 251 0 36 219 0 132 123 0 4 251 0 36 219 0 36 219 0 228 27 0 228 27 0 196 59 0 132 123 0 68 187 0 36 219 0 196 59 0 164 91 0 -228 27 0 196 59 0 228 27 0 4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 164 91 0 36 219 0 36 219 0 68 187 0 4 251 0 4 251 0 196 59 0 164 91 0 68 187 0 36 219 0 4 251 0 164 91 0 -164 91 0 164 91 0 228 27 0 4 251 0 228 27 0 4 251 0 36 219 0 68 187 0 164 91 0 196 59 0 196 59 0 228 27 0 196 59 0 228 27 0 164 91 0 132 123 0 100 155 0 36 219 0 4 251 0 164 91 0 -132 122 0 132 122 0 132 122 0 164 91 0 164 91 0 164 91 0 196 59 0 196 59 0 196 59 0 228 27 0 228 27 0 228 27 0 36 219 0 4 251 0 36 219 0 4 251 0 228 27 0 164 91 0 196 59 0 164 91 0 +180 75 0 180 75 0 180 75 0 180 75 0 228 27 0 228 27 0 180 75 0 228 27 0 20 235 0 68 187 0 20 235 0 20 235 0 20 235 0 20 235 0 20 235 0 228 27 0 180 75 0 180 75 0 132 122 0 132 122 0 +180 75 0 180 75 0 180 75 0 180 75 0 228 27 0 228 27 0 180 75 0 228 27 0 68 187 0 116 139 0 116 139 0 116 139 0 116 139 0 116 139 0 116 139 0 68 187 0 20 235 0 20 235 0 180 75 0 132 122 0 +180 75 0 180 75 0 180 75 0 20 235 0 68 187 0 68 187 0 68 187 0 68 187 0 164 91 0 164 91 0 212 43 0 212 43 0 4 251 0 212 43 0 164 91 0 212 43 0 212 43 0 212 43 0 228 27 0 132 122 0 +228 27 0 228 27 0 228 27 0 68 187 0 164 91 0 164 91 0 164 91 0 164 91 0 52 203 0 52 203 0 148 107 0 100 155 0 148 107 0 4 251 0 164 91 0 212 43 0 212 43 0 212 43 0 228 27 0 132 122 0 +20 235 0 20 235 0 20 235 0 20 235 0 116 139 0 164 91 0 164 91 0 4 251 0 100 155 0 100 155 0 196 59 0 100 155 0 148 107 0 212 43 0 68 187 0 116 139 0 116 139 0 116 139 0 180 75 0 132 122 0 +68 187 0 116 139 0 116 139 0 164 91 0 52 203 0 100 155 0 148 107 0 244 11 0 244 11 0 196 59 0 36 219 0 196 59 0 244 11 0 52 203 0 164 91 0 164 91 0 68 187 0 68 187 0 180 75 0 132 122 0 +20 235 0 20 235 0 68 187 0 116 139 0 212 43 0 4 251 0 100 155 0 196 59 0 196 59 0 148 107 0 196 59 0 148 107 0 244 11 0 100 155 0 212 43 0 4 251 0 116 139 0 116 139 0 228 27 0 132 122 0 +228 27 0 228 27 0 68 187 0 116 139 0 212 43 0 52 203 0 148 107 0 244 11 0 244 11 0 180 75 0 228 27 0 180 75 0 36 219 0 148 107 0 52 203 0 100 155 0 52 203 0 164 91 0 116 139 0 132 122 0 +20 235 0 20 235 0 68 187 0 116 139 0 212 43 0 52 203 0 148 107 0 244 11 0 36 219 0 228 27 0 228 27 0 180 75 0 36 219 0 148 107 0 52 203 0 148 107 0 52 203 0 116 139 0 116 139 0 132 122 0 +68 187 0 20 235 0 68 187 0 116 139 0 164 91 0 4 251 0 52 203 0 100 155 0 148 107 0 84 171 0 36 219 0 36 219 0 148 107 0 52 203 0 212 43 0 148 107 0 52 203 0 164 91 0 164 91 0 132 122 0 +116 139 0 68 187 0 212 43 0 4 251 0 52 203 0 148 107 0 244 11 0 36 219 0 36 219 0 228 27 0 228 27 0 180 75 0 244 11 0 148 107 0 52 203 0 244 11 0 52 203 0 164 91 0 164 91 0 132 122 0 +116 139 0 20 235 0 164 91 0 212 43 0 212 43 0 4 251 0 100 155 0 196 59 0 196 59 0 180 75 0 180 75 0 132 123 0 196 59 0 148 107 0 100 155 0 100 155 0 4 251 0 116 139 0 116 139 0 180 75 0 +164 91 0 68 187 0 212 43 0 4 251 0 212 43 0 212 43 0 52 203 0 148 107 0 148 107 0 84 171 0 132 123 0 84 171 0 148 107 0 52 203 0 4 251 0 4 251 0 212 43 0 20 235 0 68 187 0 180 75 0 +116 139 0 68 187 0 212 43 0 100 155 0 212 43 0 212 43 0 100 155 0 100 155 0 100 155 0 36 219 0 84 171 0 36 219 0 100 155 0 100 155 0 52 203 0 52 203 0 212 43 0 20 235 0 20 235 0 180 75 0 +116 139 0 68 187 0 68 187 0 164 91 0 68 187 0 68 187 0 164 91 0 212 43 0 52 203 0 196 59 0 244 11 0 196 59 0 100 155 0 52 203 0 212 43 0 212 43 0 212 43 0 20 235 0 68 187 0 180 75 0 +68 187 0 20 235 0 68 187 0 116 139 0 20 235 0 68 187 0 164 91 0 4 251 0 52 203 0 244 11 0 36 219 0 244 11 0 100 155 0 52 203 0 212 43 0 164 91 0 116 139 0 20 235 0 20 235 0 180 75 0 +68 187 0 20 235 0 68 187 0 116 139 0 20 235 0 68 187 0 68 187 0 116 139 0 4 251 0 196 59 0 244 11 0 244 11 0 148 107 0 148 107 0 100 155 0 4 251 0 164 91 0 116 139 0 228 27 0 180 75 0 +20 235 0 228 27 0 20 235 0 68 187 0 20 235 0 68 187 0 116 139 0 164 91 0 52 203 0 244 11 0 244 11 0 36 219 0 196 59 0 196 59 0 100 155 0 52 203 0 164 91 0 116 139 0 68 187 0 180 75 0 +180 75 0 180 75 0 20 235 0 68 187 0 20 235 0 68 187 0 116 139 0 164 91 0 52 203 0 100 155 0 100 155 0 148 107 0 100 155 0 148 107 0 52 203 0 4 251 0 212 43 0 116 139 0 68 187 0 180 75 0 +132 122 0 132 122 0 132 122 0 180 75 0 180 75 0 180 75 0 228 27 0 228 27 0 228 27 0 20 235 0 20 235 0 20 235 0 116 139 0 68 187 0 116 139 0 68 187 0 20 235 0 180 75 0 228 27 0 180 75 0 diff --git a/training.mp4 b/training.mp4 deleted file mode 100644 index f607b77..0000000 Binary files a/training.mp4 and /dev/null differ