2D!      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ statistical utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone-CNX&A type for representing probabilities.Ythe wrapped number Z$Smart constructor for probabilities.probability (0.7 :: Double)#Probability {fromProbability = 0.7}probability (1.2 :: Double)#Probability {fromProbability = 1.0}probability (-0.3 :: Double)#Probability {fromProbability = 0.0}[JReturns number of elements, mean and variance of a collection of elements."countMeanVar [1, 2, 3, 4 :: Float] (4,2.5,1.25)\0Calculates the mean of a collection of elements.mean [1 .. 5 :: Float]3.0]Calculates the  Thttps://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curvearea under the curve.Tauc [(1, False), (2, True), (3, False), (4, True), (5, False), (6, True), (7, True)]$Probability {fromProbability = 0.75}^Calculates the  Thttps://en.wikipedia.org/wiki/Receiver_operating_characteristic#Area_under_the_curvearea under the curve for weighted samples.xauc' [(1, (1 :: Double), False), (2, 0.5, True), (3, 1, False), (4, 1, True), (5, 1, False), (6, 1, True), (7, 1, True)]0.8095238095238095_ Rounds a % to the specified number of decimals.round' 3 (2/3)0.667 XYZ[\]^_XYZ[\]^_ XYZY[\]^_XYZ[\]^_arrow utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableSafeIN`Arrows implementing `B can be mapped over containers. This means that every functor (f :: Hask -> Hask) lifts to a functor (a -> a).,Instances should satisfy the following laws: convolve id = id *convolve (g . h) = convolve g . convolve h convolve . arr = arr . fmapb,A function suitable to define the canonical  instance for arrows.cA function to define # for arrows. Combining this with d, the canonical + instance for arrows can easily be defined.dA function to define ()" for arrows. Combining this with c, the canonical + instance for arrows can easily be defined.e,A function suitable to define the canonical  instance for arrows.`abcde`abcde`abcde`abcde*commonly used standard types and functions(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneS  !"#$%&'()*+,-./012456789:;<=>?@ABCDEFJKLMNOPQRSTUVWfgW654,@CDEAB2#.:; ?fg>F=WVQ<UTVSRNPOJMLOK('$-*)!"%+/10&789 list utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneINh\Collects upstream data in chunks of a specified size and then passes those chunks downstram.#import qualified Pipes.Prelude as P@runEffect $ each [1 .. 10 :: Int] >-> chunks 3 >-> P.mapM_ print[1,2,3][4,5,6][7,8,9]OrunEffect $ each [1 .. 30000 :: Int] >-> chunks 10000 >-> P.mapM_ (print . sum)50005000 150005000 250005000iSafely produces 3s from a file.jConverts a stream of 3s into a stream of s.hij3GHIhijhijIGH3hija simple stack monad(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneC kA pure stack monad.lA computation of type l s m a+ has access to a stack of elements of type s.m/Peeks at the top element of the stack. Returns  if the stack is empty.n-Pops the top element from the stack. Returns  if the stack is empty.o$Pushes a new element onto the stack.pRuns a computation in the l s m monad.qEvaluates a computation in the l s m monad.rExecutes a computation in the l s m monad.sRuns a computation in the k s monad.tEvaluates a computation in the k s monad.uExecutes a computation in the k s monad. klmnopqrstu klmnopqrstu lnmopqrkstu klmnopqrstuutilities for traversables(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNonevvTries to create a traversable (which must also be applicative) from a list. If the list contains too few elements,  is returned,import Data.MyPrelude*fromList [1, 2, 3] :: Maybe (Identity Int)Just (Identity 1)$fromList [] :: Maybe (Identity Char)Nothingvvvvlist utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneCNwMonad for pure list editting.xx a m3 is a monad transformer for editting lists of type [a].y0Splits off the last element of a non-empty list.splitLast [1, 2, 3]Just ([1,2],3) splitLast []NothingzVGiven a valid index, returns the list element at the index and the remaining elements.pick 1 [1,2,3,4] (2,[1,3,4]){aDistributes the elements of a list as uniformly as possible amongst a specified number of groups.distribute 3 [1,2,3,4,5][[3],[4,1],[5,2]]|1Pads a litst with a provided element on the left.pad 4 'x' "oo""xxoo"}Runs the editor.~9Replaces the list at the "cursor" with the provided list.'Tries to move the "cursor" to the left.(Tries to move the "cursor" to the right.!Gets the list under the "cursor".Runs the pure editor.1editList (do _ <- tryRightT; editT [3,2]) [1,2,3][1,3,2])Gets all pairs of adjacent list elements.pairs "Haskell"=[('H','a'),('a','s'),('s','k'),('k','e'),('e','l'),('l','l')]<Gets the first index of the provided element in the list or  if it is not in the list.indexOf "Haskell" 'l'Just 5indexOf "Haskell" 'y'Nothing(Returns the head of a non-empty list or  for the empty list.safeHead "Haskell"Just 'H' safeHead ""Nothingwxyz{|}~wxyz{|}~yz{|x}~wwxyz{|}~fixed-length vectors(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone !"(>KLN  n a" is the type of vectors of length n with elements of type a.The scalar product# of two vectors of the same length.:set -XDataKinds2cons 1 (cons 2 nil) <%> cons 3 (cons 4 nil) :: Int11The vector of length zero.7Prepends the specified element to the specified vector.cons False (cons True nil) [False,True]@Generates a vector by applying the given function to each index.:set -XDataKindsgenerate id :: Vector 3 Int[0,1,2]PGets the vector element at the specified index if the index is valid, otherwise .cons 'x' nil !? 0Just 'x'cons 'x' nil !? 1Nothing\Gets the vector element at the specified index, throws an exception if the index is invalid.cons 'x' nil ! 0'x'cons 'x' nil ! 12*** Exception: Data.Utils.Vector.!: invalid index ?Gets the first element of a vector of length greater than zero.vhead (cons 'x' (cons 'y' nil))'x'YFor a vector of length greater than zero, gets the vector with its first element removed.vtail (cons 'x' (cons 'y' nil))"y"$Adds two vectors of the same length.:set -XDataKinds?(cons 1 (cons 2 nil)) <+> (cons 3 (cons 4 nil)) :: Vector 2 Int[4,6])Subtracts two vectors of the same length.:set -XDataKinds?(cons 1 (cons 2 nil)) <-> (cons 3 (cons 4 nil)) :: Vector 2 Int[-2,-2]Calculates the squaredP euclidean norm of a vector, i.e. the scalar product of the vector by itself.:set -XDataKinds#sqNorm (cons 3 (cons 4 nil)) :: Int25Calculates the squared; euclidean distance between two vectors of the same length.:set -XDataKinds9sqDiff (cons 1 (cons 2 nil)) (cons 3 (cons 4 nil)) :: Int8 random number utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneN WPicks a random element of the list and returns that element and the remaining elements.+evalRand (pickR' "Haskell") (mkStdGen 4712)('s',"Hakell")#Picks a random element of the list.*evalRand (pickR "Haskell") (mkStdGen 4712)'s'rTakes the specified number of random elements from the list. Returns those elements and the remaining elements.-evalRand (takeR' 3 "Haskell") (mkStdGen 4712)("aks","Hell")<Takes the specified number of random elements from the list.,evalRand (takeR 3 "Haskell") (mkStdGen 4712)"aks"Shuffles an array with the  :https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffleFisher-Yates algorithm.Shuffles an list with the  :https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffleFisher-Yates algorithm.-evalRand (shuffleR "Haskell") (mkStdGen 4712) "skalHle" Uses the  :https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transformBox-Muller transformQ to sample the standard normal distribution (zero expectation, unit variance).<evalRand (replicateM 5 boxMuller) (mkStdGen 1234) :: [Float]<[0.61298496,-0.19325614,4.4974413e-2,-0.31926495,-1.1109064] Uses the  :https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transformBox-Muller transformN to sample a normal distribution with specified mean and stadard deviation.DevalRand (replicateM 5 $ boxMuller' 10 2) (mkStdGen 1234) :: [Float]/[11.22597,9.613487,10.089949,9.36147,7.7781873]7Randomly selects the specified number of elements of a weighted list.EevalRand (roulette 10 [('x', 1 :: Double), ('y', 2)]) (mkStdGen 1000) "yxxyyyyxxy"  fixed-size matrices(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone (-./>CKL m n a is the type of matrices with m rows, n columns and entries of type a.Multiplication of a matrix by a (column-)vector.:set -XDataKinds3(pure 1 :: Matrix 1 2 Int) <%%> cons 1 (cons 2 nil)[3]eGives the matrix row with the specified index (starting at zero) if the index is valid, otherwise .:set -XDataKinds!row (pure 42 :: Matrix 2 4 Int) 0Just [42,42,42,42]!row (pure 42 :: Matrix 2 4 Int) 2NothinghGives the matrix column with the specified index (starting at zero) if the index is valid, otherwise .:set -XDataKinds$column (pure 42 :: Matrix 2 4 Int) 3 Just [42,42]$column (pure 42 :: Matrix 2 4 Int) 4NothingNGenerates a matrix by applying the given function to each index (row, column).:set -XDataKinds%mgenerate id :: Matrix 3 2 (Int, Int)2Matrix [[(0,0),(0,1)],[(1,0),(1,1)],[(2,0),(2,1)]]dGives the matrix element with the specified index (row, column) if the index is valid, otherwise .:set -XDataKinds1let m = mgenerate (uncurry (+)) :: Matrix 2 3 Int m !!? (0,0)Just 0 m !!? (1, 2)Just 3 m !!? (5, 7)NothingxGives the matrix element with the specified index (row, column) if the index is valid, otherwise throws an exception.:set -XDataKinds1let m = mgenerate (uncurry (+)) :: Matrix 2 3 Int m !!! (0,0)0 m !!! (1, 2)3 m !!! (5, 7)3*** Exception: Data.Utils.Matrix.!!!: invalid indexTransposes a matrix.Btranspose (Matrix $ cons (cons 'a' nil) (cons (cons 'b' nil) nil)) Matrix ["ab"]    "analytic" values(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone345INType > can be thought of as the type of differentiable functions Double -> Double.Type  f g= can be thought of as the type of "differentiable" functions f Double -> g Double.Class 9 is a helper class for defining differentiable functions.9Lifts a differentiable function by pointwise application.QComputes the gradient of an analytic function and combines it with the argument. MgradWith' (\_ d -> d) (Diff $ \[x, y] -> Identity $ x * x + 3 * y + 7) [2, 1](14.0,[4.0,3.0]) $how to combine argument and gradientdifferentiable functionfunction argument7function value and combination of argument and gradientvarious utilities(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNoneK3GHIXYZ[\]^_`abcdehijklmnopqrstuv "neural" components and models(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone!"-./4;>IJNcA type abbreviation for the most common type of models, where samples are just input-output tuples.A  f g a b c wraps a  f g and models functions b -> c; with "samples" (for model error determination) of type a.Composition of functors.The analogue for  in the category of functors.3The analogue for pairs in the category of functors.A  f g, is a parameterized differentiable function f Double -> g Double. In contrast to , when components are composed, parameters are not shared. Each component carries its own collection of parameters instead.the specific parameter values'the encapsulated parameterized functionrandomly sets the parameters The type  t a b( describes parameterized functions from a to b&, where the parameters are of type t s;. When such components are composed, they all share the same parameters.A D to get or set the weights of a component. The shape of the parameter collection is hidden by existential quantification, so this lens has to use simple generic lists.bActivates a component, i.e. applies it to the specified input, using the current parameter values.The analogue of  for s.The analogue of  for s.The analogue of  for s.The analogue of a for s.A Lens1 for accessing the component embedded in a model.Computes the modelled function.nGenerates a model with randomly initialized weights. All other properties are copied from the provided model. ACalculates the avarage model error for a "mini-batch" of samples.DPerforms one step of gradient descent/ backpropagation on the model, Creates a d, using the simplifying assumtion that the error can be computed from the expected output allone.1   *the model whose error should be decreased the learning ratea mini-batch of samples7returns the average sample error and the improved model  %      a pipes API for models(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone The training state of a model. updated model generation learning ratelast training errorA } for training a model: It consumes mini-batches of samples from upstream and pushes the updated training state downstream. A simple  of mini-batches.A * for progress reporting of model training.A T of training states that decides when training is finished and then returns a value.  initial modelfirst generation.computes the learning rate from the generationall available samplesthe mini-batch sizereport interval report actionBcheck whether training is finished and what to return in that case3. !:;"#F$%&'()*+,-./0123456789:;<=>? layer components(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone(IKLNA  i o is a component that maps a  of length i to a  of length o. Creates a linear 7, i.e. a layer that multiplies the input with a weight # and adds a bias to get the output.WRandom initialization follows the recommendation from chapter 3 of the online book  )http://neuralnetworksanddeeplearning.com/!Neural Networks and Deep Learning by Michael Nielsen. Creates a I as a combination of a linear layer and a non-linear activation function.This is a simple , specialized to @9-activation. Output values are all in the interval [0,1].This is a simple c, specialized to the logistic function as activation. Output values are all in the interval [-1,1].This is a simple , specialized to the rectified linear unit= activation function. Output values are all non-negative.The  function normalizes a vector, so that all entries are in [0,1] with sum 1. This means the output entries can be interpreted as probabilities.AAnormalizing data(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNone(IKLN A  f n b c is a  that classifies items of type b into categories of type c(, using a component with input shape f and output shape  n.Provides "1 of n " encoding for enumerable types.:set -XDataKindsencode1ofN LT :: Vector 3 Int[1,0,0]encode1ofN EQ :: Vector 3 Int[0,1,0]encode1ofN GT :: Vector 3 Int[0,0,1]Provides "1 of n " decoding for enumerable types.0decode1ofN [0.9, 0.3, 0.1 :: Double] :: OrderingLT0decode1ofN [0.7, 0.8, 0.6 :: Double] :: OrderingEQ0decode1ofN [0.2, 0.3, 0.8 :: Double] :: OrderingGT3Provides equidistant encoding for enumerable types.:set -XDataKinds#encodeEquiDist LT :: Vector 2 Float [1.0,0.0]#encodeEquiDist EQ :: Vector 2 Float[-0.5,-0.86602545]#encodeEquiDist GT :: Vector 2 Float[-0.5,0.86602545]3Provides equidistant decoding for enumerable types.:set -XDataKinds9let u = fromJust (fromList [0.9, 0.2]) :: Vector 2 DoubledecodeEquiDist u :: OrderingLT:set -XDataKinds;let v = fromJust (fromList [-0.4, -0.5]) :: Vector 2 DoubledecodeEquiDist v :: OrderingEQ:set -XDataKinds9let w = fromJust (fromList [0.1, 0.8]) :: Vector 2 DoubledecodeEquiDist w :: OrderingGT>Computes the cross entropy error (assuming "1 of n" encoding).VrunDiff (crossEntropyError LT) (cons 0.8 (cons 0.1 (cons 0.1 nil))) :: Identity DoubleIdentity 0.2231435513142097VrunDiff (crossEntropyError EQ) (cons 0.8 (cons 0.1 (cons 0.1 nil))) :: Identity DoubleIdentity 2.3025850929940455 Function  takes a batch of values (of a specific shape) and computes a normalization function which whitens values of that shape, so that each component has zero mean and unit variance.:set -XDataKinds^let xss = [cons 1 (cons 1 nil), cons 1 (cons 2 nil), cons 1 (cons 3 nil)] :: [Vector 2 Double]let f = white xss f <$> xss>[[0.0,-1.2247448713915887],[0.0,0.0],[0.0,1.2247448713915887]] Modifies a F by whitening the input before feeding it into the embedded component.Makes a standard K which uses a softmax layer, "1 of n" encoding and the cross entropy error. BCoriginal model batch of input datathe embedded componentconverts input  BCneural networks(c) Lars Brnjes, 2016MITbrunjlar@gmail.com experimentalportableNonea. !:;"#F$%&'()*+,-./0123456789:;<=>?D ! " # $ % &'(')'*+,-./0123242456789:;<=>=?@A@B@C@D@EFGFHFIFJFKLMNONPQRQSQTUVUWXYZ[Z\Z]^_`ab+,c+,d+,efghijkijlmnomnpmqrmqstuvtuwxyzxy{x|}x~xxmmmmmmmmmqmqmqmqmqmqmqtutu                                     ^!^"^#^$^%&'()*+,-./012345 6 7 8 9 :N;<=<><? @ @ A B C D E F G H I J K L M N O P QRSTRSURSVFW^X^Y^Zm[\]^\]_R`aR`bR`cR`dR`eR`fR`gR`hR`iR`jR`kR`lR`mR`nR`oR`pR`qR`rR`sR`tRSuRSvRSwRSxRSyRz{Rz|}~neura_9wex5OgBHyF3qBfFE3TmEPData.MyPreludeData.Utils.VectorData.Utils.PipesData.Utils.StatisticsData.Utils.ArrowData.Utils.StackData.Utils.TraversableData.Utils.ListData.Utils.RandomData.Utils.MatrixData.Utils.AnalyticNumeric.Neural.ModelNumeric.Neural.PipesNumeric.Neural.LayerNumeric.Neural.NormalizationData.Profunctor Profunctor Data.UtilsNumeric.Neuralbase Control.Monadguard GHC.TypeLitsKnownNatGHC.WordWord8rando_9Kgekc9yEaLHLNUuw6paWL System.RandommkStdGenStdGenMonad_CLO5AInWsHZAZxUa5zJXgrControl.Monad.RandomrunRandevalRandrunRandT evalRandTRandTRandControl.Monad.Random.Class getRandomR getRandom MonadRandomdeeps_6vMKxt5sPFR0XsbRWvvq59Control.DeepSeqNFData Text.PrintfprintfSystem.EnvironmentgetArgsData.Functor.Identity runIdentityIdentitynatValunless replicateMforeverData.TraversableforM System.IOwithFileGHC.IO.Handle.Text hPutStrLnhPutStr GHC.IO.IOMode ReadWriteMode AppendMode WriteModeReadModeIOMode Data.Foldable minimumBy maximumByforM_toListfoldl' Data.Monoid<> Data.Eitherrightslefts Data.OldListsortBysort intercalate Data.Function&on Data.Functorvoid Data.Maybe catMaybes fromMaybefromJustGHC.Basewhenbytes_6VWy06pWzJq9evDvK2d4w6Data.ByteString.Internal ByteStringforcedeepseqrnfdirec_0hFG6ZxK1nk4zsyOqbNHfmSystem.DirectorygetDirectoryContentsfilep_Ey7a1in9roBAE8bUFJ5R9mSystem.FilePath.Posix<.>trans_GZTjP9K5WFq01xC9BAGQpFControl.Monad.IO.ClassMonadIOliftIOControl.Monad.Trans.State.LazyrunStateStatemtl_Aue4leSeVkpKLsfHIV51E8Control.Monad.State.Classstate MonadStatelens_J90cef9Zp6NHnGeofWmE35Control.Lens.Getter^.toControl.Lens.LenslensControl.Lens.Setter.~Control.Lens.TypeLens'GetterControl.Monad.Trans.Classliftpipes_4rbd9wDkjes7DzUcy1UwsR Pipes.SaferunSafePrunSafeT MonadSafeControl.Monad.Trans.Writer.Lazytell execWriterT execWriter runWriterWriter runWriterTWriterTmodify execStateT evalStateT execState evalState runStateTStateT ProbabilityfromProbability probability countMeanVarmeanaucauc'round' ArrowConvolveconvolvefmapArrpureArrapArrdimapArrgetputchunksfromFiletoWord8StackStackTpeekpoppush runStackT evalStackT execStackTrunStack evalStack execStackfromList ListEditor ListEditorT splitLastpick distributepad editListTeditTtryLeftT tryRightTfocusTeditListpairsindexOfsafeHeadVector<%>nilconsgenerate!?!vheadvtail<+><->sqNormsqDiffpickR'pickRtakeR'takeR fisherYatesshuffleR boxMuller boxMuller'rouletteMatrix<%%>rowcolumn mgenerate!!?!!! transposeDiff'DiffrunDiffAnalytic fromDoublediff gradWith'StdModelModelConvolveFEitherFLeftFRightPair ComponentweightscomputeinitRParamFunrunPF_weightsactivatecArrcFirstcLeft cConvolve _componentmodelmodelR modelErrordescent mkStdModelTStsModel tsGenerationtsEta tsBatchErrordescentP simpleBatchP reportTSP consumeTSPLayer linearLayerlayer tanhLayer logisticLayer reLULayersoftmax Classifier encode1ofN decode1ofNencodeEquiDistdecodeEquiDistcrossEntropyErrorwhitewhitenmkStdClassifierghc-prim GHC.TypesDoubleFunctorpure Applicative<*>NothingLZlzlzToListlzEditlzLeftlzRightlzFocustryT$fNFDataVector $fReadVector$fTraversableVector$fFoldableVector$fApplicativeVector$fFunctorVector $fShowVector $fEqVectorpickR''$fApplicativeMatrix$fCategory(->)Diff$fAnalyticReverse$fAnalyticDoubleEither Control.ArrowarrfirstleftEmptyerrFun modelError' $fNFDataModel$fProfunctorModel$fNFDataComponent$fCategory(->)Component$fApplicativePair $fNFDataPair $fNFDataEmpty$fApplicativeEmpty$fProfunctorParamFun$fApplicativeParamFun$fFunctorParamFun$fArrowConvolveParamFun$fArrowChoiceParamFun$fArrowParamFun$fCategory*ParamFunpipes_BuPv5OpHkYKJdGg885pSs7 Pipes.CorePipeProducerConsumerFoldablemplusmzero MonadPlus MonadTransmmorp_2Jm5FlYBlmjDhcU1ovZRKPControl.Monad.MorphMFunctorhoistPipes<-<discardeveryeachnextrunListT>->cat~<>~await<~~>foryield enumerateSelectListTtoListT Enumerable runEffectEffectEffect' Producer' Consumer'Pipes.InternalProxyX GHC.Floattanh linearLayer' polyhedron polyhedron'