module AI.Network (
Network(..),
toActivation, toDerivative,
toLambda, toWeights,
toWeightMatrices, toArchitecture,
setActivation, setDerivative,
setLambda, setWeights,
setArchitecture
) where
import Data.Packed.Vector
import Data.Packed.Matrix
data Network = Network
{
activation :: (Double -> Double),
derivative :: (Double -> Double),
lambda :: Double,
weights :: Vector Double,
architecture :: [Int]
}
toActivation :: Network -> (Double -> Double)
toActivation (Network {activation = f}) = f
toDerivative :: Network -> (Double -> Double)
toDerivative (Network {derivative = df}) = df
toLambda :: Network -> Double
toLambda (Network {lambda = la}) = la
toWeights :: Network -> Vector Double
toWeights (Network {weights = w}) = w
toWeightMatrices :: Network -> [Matrix Double]
toWeightMatrices (Network {weights = ws, architecture = arch}) =
let elems = 0:[((x + 1) * y) | (x,y) <- zip arch (tail arch)] in
[reshape i v | (i, v) <- zip (tail arch) (takesV (tail elems) ws)]
toArchitecture :: Network -> [Int]
toArchitecture (Network {architecture = a}) = a
setActivation :: Network -> (Double -> Double) -> Network
setActivation (Network {derivative = df, lambda = la, weights = w, architecture = a}) f =
(Network {activation = f, derivative = df, lambda = la, weights = w, architecture = a})
setDerivative :: Network -> (Double -> Double) -> Network
setDerivative (Network {activation = f, lambda = la, weights = w, architecture = a}) df =
(Network {activation = f, derivative = df, lambda = la, weights = w, architecture = a})
setLambda :: Network -> Double -> Network
setLambda (Network {activation = f, derivative = df, weights = w, architecture = a}) la =
Network {activation = f, derivative = df, lambda = la, weights = w, architecture = a}
setWeights :: Network -> Vector Double -> Network
setWeights (Network {activation = f, derivative = df, lambda = la, architecture = a}) w =
(Network {activation = f, derivative = df, lambda = la, weights = w, architecture = a})
setArchitecture :: Network -> [Int] -> Network
setArchitecture (Network {activation = f, derivative = df, lambda = la, weights = w}) a =
(Network {activation = f, derivative = df, lambda = la, weights = w, architecture = a})