Skip to content

Commit

Permalink
add training video
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettotte committed Aug 15, 2022
1 parent 769ee33 commit eb72c86
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Binary file added docs/model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/training.mp4
Binary file not shown.
6 changes: 3 additions & 3 deletions inc/config.inc
Original file line number Diff line number Diff line change
@@ -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!)
DUMP_MAX: equ 100 ; max dump files to generate (debug)
; set to 0xC0FFEE for no limit, used to create GIF (SLOW!)
40 changes: 20 additions & 20 deletions model.ppm
Original file line number Diff line number Diff line change
@@ -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
Binary file removed training.mp4
Binary file not shown.

0 comments on commit eb72c86

Please sign in to comment.