<commit_before>{-# LANGUAGE BangPatterns, FlexibleInstances, DeriveDataTypeable #-} 
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | minimal NN implementation based on hmatrix

module MinimalNN where

import Data.Packed.Vector as Vector
import Data.Packed.Matrix as Matrix 
import Numeric.Container
import Numeric.LinearAlgebra () -- instances

import Data.Typeable

data TNetwork = TNetwork { weights :: [Matrix Double] 
                         , biases :: [Vector Double]
                         } deriving (Show, Ord, Eq, Typeable)

instance Ord (Matrix Double) where
    compare a b = compare (toLists a) (toLists b)

computeTNetworkSigmoid :: TNetwork -> Vector Double -> Vector Double
computeTNetworkSigmoid (TNetwork ws bs) inp0 = foldl (\ inp (w,b) -> cmap sigmoid ((inp `vXm` w) `add` b) ) inp0 (zip ws bs)
{-# INLINE computeTNetworkSigmoid #-}
<commit_msg>use foldl' in computeTNetworkSigmoid in MinimalNN<commit_after>{-# LANGUAGE BangPatterns, FlexibleInstances, DeriveDataTypeable #-} 
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | minimal NN implementation based on hmatrix

module MinimalNN where

import Data.Packed.Vector as Vector
import Data.Packed.Matrix as Matrix 
import Numeric.Container
import Numeric.LinearAlgebra () -- instances
import Data.List (foldl')

import Data.Typeable

data TNetwork = TNetwork { weights :: [Matrix Double] 
                         , biases :: [Vector Double]
                         } deriving (Show, Ord, Eq, Typeable)

instance Ord (Matrix Double) where
    compare a b = compare (toLists a) (toLists b)

computeTNetworkSigmoid :: TNetwork -> Vector Double -> Vector Double
computeTNetworkSigmoid (TNetwork ws bs) inp0 = foldl' (\ inp (w,b) -> cmap sigmoid ((inp `vXm` w) `add` b) ) inp0 (zip ws bs)
{-# INLINE computeTNetworkSigmoid #-}

{'fraction_non_alphanumeric': 0.10508664058133035, 'fraction_numerical': 0.0022358859698155395, 'mean_word_length': 3.475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2435240', 'n_tokens_mistral': 585, 'n_tokens_neox': 558, 'n_words': 178}