Hi,

I just released the 0.1 version of my Haskell Neural Network library on Hackage.

Instead of writing a long blog post, I created a page on the Haskell wiki that you can find here : HNN describing what is HNN, how to get it, showing a sample and all.

There is an online version of the documentation here : hnn documentation

You can also consult hnn’s hackage page : hnn at hackage (the documentation should be generated soon there)

Here is a sample showing how you can use HNN :

module Main where

import AI.HNN.Net

import AI.HNN.Layer

import AI.HNN.Neuron

import Data.Array.Vector

import Control.Arrow

import Data.List

alpha = 0.8 :: Double — learning ratio

epsilon = 0.001 :: Double — desired maximal bound for the quad error

layer1, layer2 :: [Neuron]

layer1 = createSigmoidLayer 4 0.5 [0.5, 0.5, 0.5] — the hidden layer

layer2 = createSigmoidLayer 1 0.5 [0.5, 0.4, 0.6, 0.3] — the output layer

net = [layer1, layer2] — the neural network

finalnet = train alpha epsilon net [([1, 1, 1],[0]), ([1, 0, 1],[1]), ([1, 1, 0],[1]), ([1, 0, 0],[0])] — the trained neural network

good111 = computeNet finalnet [1, 1, 1]

good101 = computeNet finalnet [1, 0, 1]

good110 = computeNet finalnet [1, 1, 0]

good100 = computeNet finalnet [1, 0, 0]

main = do

putStrLn $ "Final neural network :

" ++ show finalnet

putStrLn " —- "

putStrLn $ "Output for [1, 1, 1] (~ 0): " ++ show good111

putStrLn $ "Output for [1, 0, 1] (~ 1): " ++ show good101

putStrLn $ "Output for [1, 1, 0] (~ 1): " ++ show good110

putStrLn $ "Output for [1, 0, 0] (~ 0): " ++ show good100

Output :

$ ./xor-3inputs

Final neural network :

[[Threshold : 0.5

Weights : toU [1.30887603787326,1.7689534867644316,2.2908214981696453],Threshold : 0.5

Weights : toU [-2.4792430791673947,4.6447786039112655,-4.932860802255383],Threshold : 0.5

Weights : toU [2.613377735822592,6.793687725768354,-5.324081206358496],Threshold : 0.5

Weights : toU [-2.5134194114492585,4.730152273922408,-5.021321916827272]],[Threshold : 0.5

Weights : toU [4.525235803191061,4.994126671590998,-8.2102354168462,5.147655509585701]]]

—-

Output for [1, 1, 1] (~ 0): [2.5784449476436315e-2]

Output for [1, 0, 1] (~ 1): [0.9711209812630944]

Output for [1, 1, 0] (~ 1): [0.9830499812666017]

Output for [1, 0, 0] (~ 0): [1.4605247804272069e-2]

Don’t hesitate to try it, play with it and give some feedback ! For any feedback or question, see the end of the HNN wiki page.

Thanks, and enjoy !