Haskell AI (HAI)
Minimalistic implementation of a basic neural network with backpropagation in Haskell using only the Prelude, Data.Matrix and System.Random.
Run
Code runs using Stack to manage imports. First clone the repository, then run
stack build
stack exec hai-exe
or alternatively just,
stack run
Code
The code can be found in app/Main.hs and src/Lib.hs. The latter includes the train function whereas the former has the main monad which initializes the matrices and calls the train function. The X matrix in app/Main.hs can be changed (to experiment) and the amount of epochs in the train function can be changed.
Results
Training Data X:
┌ ┐
│ 1.0 0.0 1.0 │
│ 1.0 1.0 1.0 │
│ 0.0 0.0 1.0 │
└ ┘
Desired Ouput Y:
┌ ┐
│ 1.0 │
│ 1.0 │
│ 0.0 │
└ ┘
Result After Training:
┌ ┐
│ 0.9968757999762028 │
│ 0.9993985458752835 │
│ 3.899624248201951e-3 │
└ ┘
The last matrix is the final approximation of the desired output Y above it after 100.000 epochs of training on the X matrix training data. As you can see above, it converged to ~0.99 for the points where 1.0 was correct and to ~0.00389 where 0.0 was correct (The 3.89e-3 is scientific notation).
Possible Additions
- MNIST Classifier
- Repa arrays and Repa algorithms
- Good read on randomness in Haskell
- OG Tutorial "Future Work" section