packages feed

hopfield 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+42/−11 lines, 3 files

Files

hopfield.cabal view
@@ -1,9 +1,9 @@ name:          hopfield-version:       0.1.0.0+version:       0.1.0.1 license:       MIT author:        Mihaela Rosca, Lukasz Severyn, Niklas Hambuechen, Razvan Marinescu, Wael Al Jisihi copyright:     Copyright: (c) 2012 Mihaela Rosca, Lukasz Severyn, Niklas Hambuechen, Razvan Marinescu, Wael Al Jisihi-maintainer:    Niklas Hambüchen <mail@nh2.me>+maintainer:    Niklas Hambuechen <mail@nh2.me> category:      AI, Machine Learning stability:     experimental synopsis:      Hopfield Networks, Boltzmann Machines and Clusters@@ -31,6 +31,8 @@  build-type:    Simple cabal-version: >= 1.10++extra-source-files: src/Hopfield/Images/convertImage.h  source-repository head   type: git
+ src/Hopfield/Images/convertImage.h view
@@ -0,0 +1,16 @@+#ifndef CONVERT_IMAGE_H+#define CONVERT_IMAGE_H++#include <stdint.h>+#include <stddef.h>+struct BinaryPattern+{+  uint32_t size;+  uint32_t * pattern;+};++typedef struct BinaryPattern binary_pattern_t;++binary_pattern_t * load_picture(char* inputImg, size_t width, size_t height);++#endif
src/Hopfield/TestUtil.hs view
@@ -71,7 +71,11 @@   len <- choose (0, n)   vectorOf len g -+-- | @patListGen t maxPatSize maxPatListSize@ Generates a list of patterns.+-- The size of each pattern is less than maxPatSize.+-- The size odf the list is less than maxPatListSize.+-- The type is required in order to create types specific for Boltzmann, +-- Hopfield etc. patListGen :: Type -> Int -> Int -> Gen [Pattern] patListGen t maxPatSize maxPatListSize = do     i <- choose (1, maxPatSize)@@ -190,29 +194,38 @@         i <- arbitrary         return $ evalRand (stopped pat) (mkStdGen i) -+-- | @boltzmannBuildGen maxPatSize maxPatListSize max_hidden@ +-- Generates the structures required for creating a Boltzmann machine: +-- a list of patterns together with the number of hidden layers,+-- which has to be less than max_hidden. boltzmannBuildGen :: Int -> Int -> Int -> Gen ([Pattern], Int)-boltzmannBuildGen m1 m2 max_hidden = do-  pats <- patListGen BM m1 m2+boltzmannBuildGen maxPatSize maxPatListSize max_hidden = do+  pats <- patListGen BM maxPatSize maxPatListSize   i    <- choose (1, max_hidden)   return $ (pats, i) -+--  | Checks that the buildBoltzmann function does not modify+-- the given patterns or the number of hidden layers. buildBoltzmannCheck :: ([Pattern], Int) -> Gen Bool buildBoltzmannCheck (pats, nr_h) = do   i <- arbitrary   let bd = evalRand (buildBoltzmannData' pats nr_h) (mkStdGen i)   return $ patternsB bd == pats && nr_hiddenB bd == nr_h -+-- | Generates a list of patterns and the number of hidden layers+-- used to train a Boltzmann machine, as well as a generic pattern to +-- recognize on this machine. boltzmannAndPatGen :: Int -> Int -> Int -> Gen ([Pattern], Int, Pattern)-boltzmannAndPatGen m1 m2 max_hidden = do-  pats_train <- patListGen BM m1 m2+boltzmannAndPatGen maxPatSize maxPatListSize max_hidden = do+  pats_train <- patListGen BM maxPatSize maxPatListSize   i          <- choose (1, max_hidden)   pats_check <- patternGen BM (V.length $ pats_train !! 0)   return $ (pats_train, i, pats_check) -+-- | @probabilityCheck (pats, nr_h, pat)@. Trains a Boltzmann machine+-- using @pats@ and @nr_h@ and computes the activation probability for +-- @pat@ using this machine, and check if it is indeed a probability,+-- ie in [0,1] probabilityCheck ::  ([Pattern], Int, Pattern) -> Gen Bool probabilityCheck (pats, nr_h, pat) = do   seed <- arbitrary