instinct-0.1.0: Fast artifical neural networks

MaintainerErtugrul Soeylemez <>




This module provides an efficient connection matrix type.


Connection matrix

data ConnMatrix Source

A connection matrix is essentially a two-dimensional array of synaptic weights.


buildLayered :: [Int] -> IO ConnMatrixSource

Build a layered connection matrix, where adjacent layers are fully connected.

buildRandom :: Int -> IO ConnMatrixSource

Build a completely random connection matrix with the given edge length. The random values will be between -1 and 1 exclusive.

buildZero :: Int -> ConnMatrixSource

Build a zero connection matrix. It will represent a completely disconnected network, where all nodes are isolated.


cmAdd :: ConnMatrix -> ConnMatrix -> ConnMatrixSource

Add two connection matrices. Note that this function is left-biased in that it will adopt the connectivity of the first connection matrix.

You may want to use the Monoid instance instead of this function.

cmDests :: forall b. Int -> (b -> Int -> Double -> b) -> b -> ConnMatrix -> bSource

Strictly fold over the outputs, including zeroes.

cmFold :: Int -> (b -> Int -> Double -> b) -> b -> ConnMatrix -> bSource

Strictly fold over the nonzero inputs of a node.

cmMap :: (Int -> Int -> Double -> Double) -> ConnMatrix -> ConnMatrixSource

Map over the inputs of a node.

cmSize :: ConnMatrix -> IntSource

Edge length of a connection matrix.


addLayer :: Int -> Int -> Int -> Int -> ConnMatrix -> IO ConnMatrixSource

addLayer s1 n1 s2 n2 overwrite n1 nodes starting from s1 to be fully connected with random weights to the n2 nodes starting from s2.