-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Machine learning in Haskell -- -- Provides a very simple implementation of deep (i.e. - multi-layer), -- fully connected (i.e. - _not_ convolutional) neural networks. Hides -- the type of the internal network structure from the client code, while -- still providing type safety, via existential type quantification and -- dependently typed programming techniques, ala Justin Le. (See -- Justin's blog post.) The API offers a single network creation -- function: randNet, which allows the user to create a randomly -- initialized network of arbitrary internal structure by supplying a -- list of integers, each specifying the output width of one hidden layer -- in the network. (The input/output widths are determined automatically -- by the compiler, via type inference.) The type of the internal -- structure (i.e. - hidden layers) is existentially hidden, outside the -- API, which offers the following benefits: - Client generated networks -- of different internal structure may be stored in a common list (or, -- other Functorial data structure). - The exact structure of the network -- may be specified at run time, via: user input, file I/O, etc., while -- still providing GHC enforced type safety, at compile time. - Complex -- networks with long training times may be stored, after being trained, -- so that they may be recalled and used again, at a later date/time, -- without having to re-train them. @package haskell-ml @version 0.4.1 module Haskell_ML.Util -- | The 3 classes of iris are represented by the 3 constructors of this -- type. data Iris Setosa :: Iris Versicolor :: Iris Virginica :: Iris -- | Data type representing the set of attributes for a sample in the Iris -- dataset. data Attributes Attributes :: Double -> Double -> Double -> Double -> Attributes [sepLen] :: Attributes -> Double [sepWidth] :: Attributes -> Double [pedLen] :: Attributes -> Double [pedWidth] :: Attributes -> Double -- | A single sample in the dataset is a pair of a list of attributes and a -- classification. type Sample = (Attributes, Iris) -- | Read in an Iris dataset from the given file name. readIrisData :: String -> IO [Sample] -- | Convert a value of type Attributes to a value of type R -- 4. attributeToVector :: Attributes -> R 4 -- | Convert a value of type Iris to a one-hot vector value of type -- R 3. irisTypeToVector :: Iris -> R 3 -- | Calculate the classification accuracy, given: -- -- classificationAccuracy :: (KnownNat n) => [R n] -> [R n] -> Double -- | Pretty printer for values of type R n. printVector :: (KnownNat n) => R n -> String -- | Pretty printer for values of type (R m, R -- n). printVecPair :: (KnownNat m, KnownNat n) => (R m, R n) -> String -- | Rescale all feature values, to fall in [0,1]. mkSmplsUniform :: [Sample] -> [Sample] -- | Plot a list of Doubles to an ASCII terminal. asciiPlot :: [Double] -> String -- | Calculate the mean value of a list. calcMeanList :: (Fractional a) => [a] -> a -- | Convenience function (= flip map). for :: [a] -> (a -> b) -> [b] instance GHC.Classes.Ord Haskell_ML.Util.Attributes instance GHC.Classes.Eq Haskell_ML.Util.Attributes instance GHC.Read.Read Haskell_ML.Util.Attributes instance GHC.Show.Show Haskell_ML.Util.Attributes instance GHC.Enum.Enum Haskell_ML.Util.Iris instance GHC.Classes.Ord Haskell_ML.Util.Iris instance GHC.Classes.Eq Haskell_ML.Util.Iris instance GHC.Read.Read Haskell_ML.Util.Iris instance GHC.Show.Show Haskell_ML.Util.Iris module Haskell_ML.FCN -- | A fully connected, multi-layer network with fixed input/output widths, -- but variable (and existentially hidden!) internal structure. data FCNet :: Nat -> Nat -> * -- | Data type for holding training evolution data. data TrainEvo TrainEvo :: [Double] -> [([[Double]], [[Double]])] -> TrainEvo -- | training accuracies [accs] :: TrainEvo -> [Double] -- | differences of weights/biases, by layer [diffs] :: TrainEvo -> [([[Double]], [[Double]])] -- | Returns a value of type FCNet, filled with random weights ready -- for training, tucked inside the appropriate Monad, which must be an -- instance of MonadRandom . (IO is such an instance.) -- -- The input/output widths are determined by the compiler automatically, -- via type inferencing. -- -- The internal structure of the network is determined by the list of -- integers passed in. Each integer in the list indicates the output -- width of one hidden layer, with the first entry in the list -- corresponding to the hidden layer nearest to the input layer. randNet :: (KnownNat i, KnownNat o, MonadRandom m) => [Integer] -> m (FCNet i o) -- | Run a network on a list of inputs. runNet :: (KnownNat i, KnownNat o) => FCNet i o -> [R i] -> [R o] -- | Basic sanity test of our code, taken from Justin's repository. -- -- Printed output should contain two offset solid circles. netTest :: MonadRandom m => Double -> Int -> m String -- | Returns a list of integers corresponding to the widths of the hidden -- layers of a FCNet. hiddenStruct :: FCNet i o -> [Integer] -- | Returns a list of lists of Doubles, each containing the weights of one -- layer of the network. getWeights :: (KnownNat i, KnownNat o) => FCNet i o -> [[Double]] -- | Returns a list of lists of Doubles, each containing the biases of one -- layer of the network. getBiases :: (KnownNat i, KnownNat o) => FCNet i o -> [[Double]] -- | Train a network on several epochs of the training data, keeping track -- of accuracy and weight/bias changes per layer, after each. trainNTimes :: (KnownNat i, KnownNat o) => Int -> Double -> FCNet i o -> [(R i, R o)] -> (FCNet i o, TrainEvo) instance GHC.Generics.Generic (Haskell_ML.FCN.Layer i o) instance (GHC.TypeNats.KnownNat i, GHC.TypeNats.KnownNat o) => GHC.Show.Show (Haskell_ML.FCN.Layer i o) instance (GHC.TypeNats.KnownNat i, GHC.TypeNats.KnownNat o) => Data.Binary.Class.Binary (Haskell_ML.FCN.FCNet i o) instance (GHC.TypeNats.KnownNat i, Data.Singletons.SingI hs, GHC.TypeNats.KnownNat o) => Data.Binary.Class.Binary (Haskell_ML.FCN.Network i hs o) instance (GHC.TypeNats.KnownNat i, GHC.TypeNats.KnownNat o) => Data.Binary.Class.Binary (Haskell_ML.FCN.Layer i o)