Alp Mestanogullari's Blog

HNN-0.1 has been released !

Posted in Uncategorized by alpmestan on 2009/12/23

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 : \n" ++ 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 !

Tagged with: ,

3 Responses

Subscribe to comments with RSS.

  1. Erlend said, on 2009/12/23 at 3:29 pm

    Looks really nice. I’m taking a course in ANNs (among other things) next semester and plan to use Haskell for the assignments, so your timing is great.
    A simple library like this will be a really good starting point.

  2. alpmestan said, on 2009/12/23 at 3:34 pm

    I hope it’ll be useful for you. Moreover, I hope to have a strong 0.2 version with optimizations and some more features ! This first release isn’t one on which you should build a very important project around, but it’s still fine for a first release. Don’t hesitate to try it and give feedback ! Thank you for commenting.

  3. Erlend said, on 2009/12/23 at 5:46 pm

    Sounds really good. I will hopefully have some feedback for you in a month. 🙂


Leave a comment