initial commit, still work in progress
This commit is contained in:
commit
59ab00e9c2
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 42a88fbcb6bd1d2c4dc18fae5e962bd34fb316a1
|
@ -0,0 +1,26 @@
|
|||||||
|
Copyright (c) 2006-2014 Alberto Ruiz and other contributors
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of Alberto Ruiz nor the names of other contributors may
|
||||||
|
be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,53 @@
|
|||||||
|
name: hmatrix
|
||||||
|
version: 0.18.0.0
|
||||||
|
id: hmatrix-0.18.0.0-1d8fa7590dc64d386197097d7b3b924f
|
||||||
|
key: hmatr_7PZ22o8olec0bnj98RI2Zu
|
||||||
|
license: BSD3
|
||||||
|
maintainer: Alberto Ruiz
|
||||||
|
stability: provisional
|
||||||
|
homepage: https://github.com/albertoruiz/hmatrix
|
||||||
|
synopsis: Numeric Linear Algebra
|
||||||
|
description:
|
||||||
|
Linear systems, matrix decompositions, and other numerical computations based on BLAS and LAPACK.
|
||||||
|
.
|
||||||
|
Standard interface: "Numeric.LinearAlgebra".
|
||||||
|
.
|
||||||
|
Safer interface with statically checked dimensions: "Numeric.LinearAlgebra.Static".
|
||||||
|
.
|
||||||
|
Code examples: <http://dis.um.es/~alberto/hmatrix/hmatrix.html>
|
||||||
|
category: Math
|
||||||
|
author: Alberto Ruiz
|
||||||
|
exposed: True
|
||||||
|
exposed-modules:
|
||||||
|
Numeric.LinearAlgebra Numeric.LinearAlgebra.Devel
|
||||||
|
Numeric.LinearAlgebra.Data Numeric.LinearAlgebra.HMatrix
|
||||||
|
Numeric.LinearAlgebra.Static
|
||||||
|
hidden-modules: Internal.Vector Internal.Devel Internal.Vectorized
|
||||||
|
Internal.Matrix Internal.Foreign Internal.ST Internal.IO
|
||||||
|
Internal.Element Internal.Conversion Internal.LAPACK
|
||||||
|
Internal.Numeric Internal.Algorithms Internal.Random
|
||||||
|
Internal.Container Internal.Sparse Internal.Convolution
|
||||||
|
Internal.Chain Numeric.Vector Internal.CG Numeric.Matrix
|
||||||
|
Internal.Util Internal.Modular Internal.Static
|
||||||
|
trusted: False
|
||||||
|
import-dirs: /Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/lib/x86_64-osx-ghc-7.10.3/hmatrix-0.18.0.0-7PZ22o8olec0bnj98RI2Zu
|
||||||
|
library-dirs: /Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/lib/x86_64-osx-ghc-7.10.3/hmatrix-0.18.0.0-7PZ22o8olec0bnj98RI2Zu
|
||||||
|
/opt/local/lib/ /usr/local/lib/
|
||||||
|
data-dir: /Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/share/x86_64-osx-ghc-7.10.3/hmatrix-0.18.0.0
|
||||||
|
hs-libraries: HShmatrix-0.18.0.0-7PZ22o8olec0bnj98RI2Zu
|
||||||
|
extra-libraries:
|
||||||
|
blas lapack
|
||||||
|
include-dirs: /opt/local/include/ /usr/local/include/
|
||||||
|
depends:
|
||||||
|
array-0.5.1.0-960bf9ae8875cc30355e086f8853a049
|
||||||
|
base-4.8.2.0-cc43d8e06aa74e9c4c0132becc49ee25
|
||||||
|
binary-0.7.5.0-bb2dcbe8d4c53898daa6ddc1a04a77a3
|
||||||
|
bytestring-0.10.6.0-04b5cc1d05f993b3b016543ca2863add
|
||||||
|
deepseq-1.4.1.1-8eec8f9bea2efc2500f63544ec6ca569
|
||||||
|
random-1.1-7b52ac9c2fd71a09f8ea932648ebfada
|
||||||
|
split-0.2.3.1-6d0063c12972868a1e069995047d6884
|
||||||
|
storable-complex-0.2.2-5d724e6255914e391bee90b30a4cef13
|
||||||
|
vector-0.11.0.0-3c85dee988950ea88ba0cba31473444f
|
||||||
|
frameworks: Accelerate
|
||||||
|
haddock-interfaces: /Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/doc/hmatrix-0.18.0.0/hmatrix.haddock
|
||||||
|
haddock-html: /Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/doc/hmatrix-0.18.0.0
|
Binary file not shown.
38
.stack-work/logs/MonadRandom-0.4.2.3.log
Normal file
38
.stack-work/logs/MonadRandom-0.4.2.3.log
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Configuring MonadRandom-0.4.2.3...
|
||||||
|
Building MonadRandom-0.4.2.3...
|
||||||
|
Preprocessing library MonadRandom-0.4.2.3...
|
||||||
|
[1 of 2] Compiling Control.Monad.Random.Class ( Control/Monad/Random/Class.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Control/Monad/Random/Class.o )
|
||||||
|
[2 of 2] Compiling Control.Monad.Random ( Control/Monad/Random.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Control/Monad/Random.o )
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:54:1: Warning:
|
||||||
|
Module ‘Control.Monad.Error’ is deprecated:
|
||||||
|
Use Control.Monad.Except instead
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:70:1: Warning:
|
||||||
|
The import of ‘Data.Monoid’ is redundant
|
||||||
|
except perhaps to import instances from ‘Data.Monoid’
|
||||||
|
To import instances alone, use: import Data.Monoid()
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:206:11: Warning:
|
||||||
|
In the use of type constructor or class ‘Error’
|
||||||
|
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
|
||||||
|
Deprecated: "Use Control.Monad.Trans.Except instead"
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:206:51: Warning:
|
||||||
|
In the use of type constructor or class ‘ErrorT’
|
||||||
|
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
|
||||||
|
Deprecated: "Use Control.Monad.Trans.Except instead"
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:251:11: Warning:
|
||||||
|
In the use of type constructor or class ‘Error’
|
||||||
|
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
|
||||||
|
Deprecated: "Use Control.Monad.Trans.Except instead"
|
||||||
|
|
||||||
|
Control/Monad/Random.hs:251:53: Warning:
|
||||||
|
In the use of type constructor or class ‘ErrorT’
|
||||||
|
(imported from Control.Monad.Error, but defined in Control.Monad.Trans.Error):
|
||||||
|
Deprecated: "Use Control.Monad.Trans.Except instead"
|
||||||
|
In-place registering MonadRandom-0.4.2.3...
|
||||||
|
Installing library in
|
||||||
|
/Users/mahdi/.stack/snapshots/x86_64-osx/lts-6.7/7.10.3/lib/x86_64-osx-ghc-7.10.3/MonadRandom-0.4.2.3-4XRZwPV1MjC69wlAshwzrw
|
||||||
|
Registering MonadRandom-0.4.2.3...
|
80
.stack-work/logs/hmatrix-0.18.0.0.log
Normal file
80
.stack-work/logs/hmatrix-0.18.0.0.log
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
Preprocessing library hmatrix-0.18.0.0...
|
||||||
|
[ 1 of 28] Compiling Internal.Vector ( src/Internal/Vector.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Vector.o )
|
||||||
|
[ 2 of 28] Compiling Internal.Devel ( src/Internal/Devel.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Devel.o )
|
||||||
|
[ 3 of 28] Compiling Internal.Vectorized ( src/Internal/Vectorized.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Vectorized.o )
|
||||||
|
[ 4 of 28] Compiling Internal.Matrix ( src/Internal/Matrix.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Matrix.o )
|
||||||
|
[ 5 of 28] Compiling Internal.Conversion ( src/Internal/Conversion.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Conversion.o )
|
||||||
|
[ 6 of 28] Compiling Internal.Foreign ( src/Internal/Foreign.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Foreign.o )
|
||||||
|
[ 7 of 28] Compiling Internal.ST ( src/Internal/ST.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/ST.o )
|
||||||
|
[ 8 of 28] Compiling Internal.Element ( src/Internal/Element.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Element.o )
|
||||||
|
[ 9 of 28] Compiling Internal.IO ( src/Internal/IO.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/IO.o )
|
||||||
|
[10 of 28] Compiling Internal.LAPACK ( src/Internal/LAPACK.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/LAPACK.o )
|
||||||
|
[11 of 28] Compiling Internal.Numeric ( src/Internal/Numeric.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Numeric.o )
|
||||||
|
[12 of 28] Compiling Internal.Sparse ( src/Internal/Sparse.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Sparse.o )
|
||||||
|
[13 of 28] Compiling Numeric.LinearAlgebra.Devel ( src/Numeric/LinearAlgebra/Devel.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/LinearAlgebra/Devel.o )
|
||||||
|
[14 of 28] Compiling Internal.Algorithms ( src/Internal/Algorithms.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Algorithms.o )
|
||||||
|
[15 of 28] Compiling Internal.Container ( src/Internal/Container.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Container.o )
|
||||||
|
[16 of 28] Compiling Internal.Random ( src/Internal/Random.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Random.o )
|
||||||
|
[17 of 28] Compiling Internal.Convolution ( src/Internal/Convolution.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Convolution.o )
|
||||||
|
[18 of 28] Compiling Internal.Chain ( src/Internal/Chain.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Chain.o )
|
||||||
|
[19 of 28] Compiling Numeric.Vector ( src/Numeric/Vector.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/Vector.o )
|
||||||
|
[20 of 28] Compiling Internal.CG ( src/Internal/CG.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/CG.o )
|
||||||
|
[21 of 28] Compiling Numeric.Matrix ( src/Numeric/Matrix.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/Matrix.o )
|
||||||
|
[22 of 28] Compiling Internal.Util ( src/Internal/Util.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Util.o )
|
||||||
|
[23 of 28] Compiling Internal.Modular ( src/Internal/Modular.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Modular.o )
|
||||||
|
[24 of 28] Compiling Numeric.LinearAlgebra.Data ( src/Numeric/LinearAlgebra/Data.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/LinearAlgebra/Data.o )
|
||||||
|
[25 of 28] Compiling Numeric.LinearAlgebra ( src/Numeric/LinearAlgebra.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/LinearAlgebra.o )
|
||||||
|
[26 of 28] Compiling Numeric.LinearAlgebra.HMatrix ( src/Numeric/LinearAlgebra/HMatrix.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/LinearAlgebra/HMatrix.o )
|
||||||
|
[27 of 28] Compiling Internal.Static ( src/Internal/Static.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Internal/Static.o )
|
||||||
|
[28 of 28] Compiling Numeric.LinearAlgebra.Static ( src/Numeric/LinearAlgebra/Static.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Numeric/LinearAlgebra/Static.o )
|
||||||
|
clang: warning: -O4 is equivalent to -O3
|
||||||
|
clang: warning: -O4 is equivalent to -O3
|
||||||
|
clang: warning: -O4 is equivalent to -O3
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:574:14:
|
||||||
|
warning: absolute value function 'abs' given an argument of type 'const int64_t' (aka 'const long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
|
||||||
|
OP(3,abs)
|
||||||
|
^
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:574:14:
|
||||||
|
note: use function 'labs' instead
|
||||||
|
OP(3,abs)
|
||||||
|
^~~
|
||||||
|
labs
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:504:53: note: expanded from macro 'OP'
|
||||||
|
#define OP(C,F) case C: { for(k=0;k<xn;k++) rp[k] = F(xp[k]); OK }
|
||||||
|
^
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:941:9:
|
||||||
|
warning: randomVector is not thread-safe in OSX and FreeBSD [-W#pragma-messages]
|
||||||
|
#pragma message "randomVector is not thread-safe in OSX and FreeBSD"
|
||||||
|
^
|
||||||
|
2 warnings generated.
|
||||||
|
clang: warning: -O4 is equivalent to -O3
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:574:14:
|
||||||
|
warning: absolute value function 'abs' given an argument of type 'const int64_t' (aka 'const long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
|
||||||
|
OP(3,abs)
|
||||||
|
^
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:574:14:
|
||||||
|
note: use function 'labs' instead
|
||||||
|
OP(3,abs)
|
||||||
|
^~~
|
||||||
|
labs
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:504:53: note: expanded from macro 'OP'
|
||||||
|
#define OP(C,F) case C: { for(k=0;k<xn;k++) rp[k] = F(xp[k]); OK }
|
||||||
|
^
|
||||||
|
|
||||||
|
src/Internal/C/vector-aux.c:941:9:
|
||||||
|
warning: randomVector is not thread-safe in OSX and FreeBSD [-W#pragma-messages]
|
||||||
|
#pragma message "randomVector is not thread-safe in OSX and FreeBSD"
|
||||||
|
^
|
||||||
|
2 warnings generated.
|
||||||
|
ld: warning: directory not found for option '-L/opt/local/lib/'
|
||||||
|
In-place registering hmatrix-0.18.0.0...
|
||||||
|
Installing library in
|
||||||
|
/Users/mahdi/Documents/Workshop/sibe/.stack-work/install/x86_64-osx/lts-6.7/7.10.3/lib/x86_64-osx-ghc-7.10.3/hmatrix-0.18.0.0-7PZ22o8olec0bnj98RI2Zu
|
||||||
|
Registering hmatrix-0.18.0.0...
|
30
LICENSE
Normal file
30
LICENSE
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
Copyright Author name here (c) 2016
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer in the documentation and/or other materials provided
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of Author name here nor the names of other
|
||||||
|
contributors may be used to endorse or promote products derived
|
||||||
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
BIN
app/Main.hi
Normal file
BIN
app/Main.hi
Normal file
Binary file not shown.
27
app/Main.hs
Normal file
27
app/Main.hs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module Main where
|
||||||
|
|
||||||
|
import Lib
|
||||||
|
import Numeric.LinearAlgebra
|
||||||
|
import Data.List
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
|
-- 1x2
|
||||||
|
-- 2x3 + 1x3
|
||||||
|
-- 3x1 + 1x1
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main =
|
||||||
|
let learning_rate = 0.5
|
||||||
|
ih = randomLayer 0 (2, 10)
|
||||||
|
ho = randomLayer 1 (10, 1)
|
||||||
|
network = ih :- O ho
|
||||||
|
inputs = [vector [0, 1], vector [1, 1], vector [1, 0], vector [0, 0]]
|
||||||
|
|
||||||
|
-- result = forward input network
|
||||||
|
|
||||||
|
labels = [vector [1], vector [0], vector [1], vector [0]]
|
||||||
|
|
||||||
|
updated_network = session inputs network labels 0.01 10000
|
||||||
|
-- updated_network = train (head inputs) network (head labels) 0.5
|
||||||
|
results = map (\x -> forward x updated_network) inputs
|
||||||
|
in print results
|
BIN
app/Main.o
Normal file
BIN
app/Main.o
Normal file
Binary file not shown.
41
sibe.cabal
Normal file
41
sibe.cabal
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
name: sibe
|
||||||
|
version: 0.1.0.0
|
||||||
|
synopsis: Initial project template from stack
|
||||||
|
description: Please see README.md
|
||||||
|
homepage: https://github.com/githubuser/sibe#readme
|
||||||
|
license: BSD3
|
||||||
|
license-file: LICENSE
|
||||||
|
author: Author name here
|
||||||
|
maintainer: example@example.com
|
||||||
|
copyright: 2016 Author name here
|
||||||
|
category: Web
|
||||||
|
build-type: Simple
|
||||||
|
-- extra-source-files:
|
||||||
|
cabal-version: >=1.10
|
||||||
|
|
||||||
|
library
|
||||||
|
hs-source-dirs: src
|
||||||
|
exposed-modules: Lib
|
||||||
|
build-depends: base >= 4.7 && < 5
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable sibe-exe
|
||||||
|
hs-source-dirs: app
|
||||||
|
main-is: Main.hs
|
||||||
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
build-depends: base
|
||||||
|
, sibe
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
test-suite sibe-test
|
||||||
|
type: exitcode-stdio-1.0
|
||||||
|
hs-source-dirs: test
|
||||||
|
main-is: Spec.hs
|
||||||
|
build-depends: base
|
||||||
|
, sibe
|
||||||
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
source-repository head
|
||||||
|
type: git
|
||||||
|
location: https://github.com/githubuser/sibe
|
BIN
src/Lib.hi
Normal file
BIN
src/Lib.hi
Normal file
Binary file not shown.
100
src/Lib.hs
Normal file
100
src/Lib.hs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
{-# LANGUAGE GADTs #-}
|
||||||
|
{-# LANGUAGE BangPatterns #-}
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE TypeOperators #-}
|
||||||
|
|
||||||
|
module Lib
|
||||||
|
(Network(..),
|
||||||
|
Layer,
|
||||||
|
Input,
|
||||||
|
Output,
|
||||||
|
forward,
|
||||||
|
randomLayer,
|
||||||
|
train,
|
||||||
|
session,
|
||||||
|
) where
|
||||||
|
import Numeric.LinearAlgebra
|
||||||
|
import Control.Monad.Random
|
||||||
|
import System.Random
|
||||||
|
import Debug.Trace
|
||||||
|
import Data.List (foldl')
|
||||||
|
|
||||||
|
type LearningRate = Double
|
||||||
|
type Input = Vector Double
|
||||||
|
type Output = Vector Double
|
||||||
|
|
||||||
|
data Layer = L { biases :: !(Vector Double)
|
||||||
|
, nodes :: !(Matrix Double)
|
||||||
|
} deriving (Show)
|
||||||
|
|
||||||
|
data Network = O Layer
|
||||||
|
| Layer :- Network
|
||||||
|
deriving (Show)
|
||||||
|
infixr 5 :-
|
||||||
|
|
||||||
|
runLayer :: Input -> Layer -> Output
|
||||||
|
runLayer input (L !biases !weights) = input <# weights + biases
|
||||||
|
|
||||||
|
forward :: Input -> Network -> Output
|
||||||
|
forward input (O l) = cmap logistic $ runLayer input l
|
||||||
|
forward input (l :- n) = forward (cmap logistic $ runLayer input l) n
|
||||||
|
|
||||||
|
randomLayer :: Seed -> (Int, Int) -> Layer
|
||||||
|
randomLayer seed (wr, wc) =
|
||||||
|
let weights = uniformSample seed wr $ replicate wc (-1, 1)
|
||||||
|
biases = randomVector seed Uniform wc * 2 - 1
|
||||||
|
in L biases weights
|
||||||
|
|
||||||
|
logistic :: Double -> Double
|
||||||
|
logistic x = 1 / (1 + exp (-x))
|
||||||
|
|
||||||
|
logistic' :: Double -> Double
|
||||||
|
logistic' x = logistic x / max 1e-8 (1 - logistic x)
|
||||||
|
|
||||||
|
train :: Input
|
||||||
|
-> Network
|
||||||
|
-> Output -- target
|
||||||
|
-> Double -- learning rate
|
||||||
|
-> Network -- network's output
|
||||||
|
train input network target alpha = fst $ run input network
|
||||||
|
where
|
||||||
|
run :: Input -> Network -> (Network, Vector Double)
|
||||||
|
run input (O l@(L biases weights)) =
|
||||||
|
let y = runLayer input l
|
||||||
|
o = cmap logistic y
|
||||||
|
delta = o - target
|
||||||
|
de = delta * cmap logistic' y
|
||||||
|
|
||||||
|
biases' = biases - scale alpha de
|
||||||
|
weights' = weights - scale alpha (input `outer` de) -- small inputs learn slowly
|
||||||
|
layer = L biases' weights' -- updated layer
|
||||||
|
|
||||||
|
pass = weights #> de
|
||||||
|
-- pass = weights #> de
|
||||||
|
|
||||||
|
in (O layer, pass)
|
||||||
|
run input (l@(L biases weights) :- n) =
|
||||||
|
let y = runLayer input l
|
||||||
|
o = cmap logistic y
|
||||||
|
(n', delta) = run o n
|
||||||
|
|
||||||
|
de = delta * cmap logistic' y
|
||||||
|
|
||||||
|
biases' = biases - scale alpha de
|
||||||
|
weights' = weights - scale alpha (input `outer` de)
|
||||||
|
layer = L biases' weights'
|
||||||
|
|
||||||
|
pass = weights #> de
|
||||||
|
-- pass = weights #> de
|
||||||
|
in (layer :- n', pass)
|
||||||
|
|
||||||
|
session :: [Input] -> Network -> [Output] -> Double -> Int -> Network
|
||||||
|
session inputs network labels alpha epochs =
|
||||||
|
foldl' iter network [0..n * epochs]
|
||||||
|
where
|
||||||
|
iter net i =
|
||||||
|
let n = length inputs - 1
|
||||||
|
index = i `mod` n
|
||||||
|
input = inputs !! index
|
||||||
|
label = labels !! index
|
||||||
|
in train input net label alpha
|
72
stack.yaml
Normal file
72
stack.yaml
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# This file was automatically generated by 'stack init'
|
||||||
|
#
|
||||||
|
# Some commonly used options have been documented as comments in this file.
|
||||||
|
# For advanced use and comprehensive documentation of the format, please see:
|
||||||
|
# http://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||||
|
|
||||||
|
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||||
|
# A snapshot resolver dictates the compiler version and the set of packages
|
||||||
|
# to be used for project dependencies. For example:
|
||||||
|
#
|
||||||
|
# resolver: lts-3.5
|
||||||
|
# resolver: nightly-2015-09-21
|
||||||
|
# resolver: ghc-7.10.2
|
||||||
|
# resolver: ghcjs-0.1.0_ghc-7.10.2
|
||||||
|
# resolver:
|
||||||
|
# name: custom-snapshot
|
||||||
|
# location: "./custom-snapshot.yaml"
|
||||||
|
resolver: lts-6.7
|
||||||
|
|
||||||
|
# User packages to be built.
|
||||||
|
# Various formats can be used as shown in the example below.
|
||||||
|
#
|
||||||
|
# packages:
|
||||||
|
# - some-directory
|
||||||
|
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||||
|
# - location:
|
||||||
|
# git: https://github.com/commercialhaskell/stack.git
|
||||||
|
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||||
|
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||||
|
# extra-dep: true
|
||||||
|
# subdirs:
|
||||||
|
# - auto-update
|
||||||
|
# - wai
|
||||||
|
#
|
||||||
|
# A package marked 'extra-dep: true' will only be built if demanded by a
|
||||||
|
# non-dependency (i.e. a user package), and its test suites and benchmarks
|
||||||
|
# will not be run. This is useful for tweaking upstream packages.
|
||||||
|
packages:
|
||||||
|
- location:
|
||||||
|
git: git@github.com:albertoruiz/hmatrix.git
|
||||||
|
commit: 42a88fbcb6bd1d2c4dc18fae5e962bd34fb316a1
|
||||||
|
subdirs:
|
||||||
|
- packages/base
|
||||||
|
#- '.'
|
||||||
|
|
||||||
|
# Dependency packages to be pulled from upstream that are not in the resolver
|
||||||
|
# (e.g., acme-missiles-0.3)
|
||||||
|
extra-deps: []
|
||||||
|
|
||||||
|
# Override default flag values for local packages and extra-deps
|
||||||
|
flags: {}
|
||||||
|
|
||||||
|
# Extra package databases containing global packages
|
||||||
|
extra-package-dbs: []
|
||||||
|
|
||||||
|
# Control whether we use the GHC we find on the path
|
||||||
|
# system-ghc: true
|
||||||
|
#
|
||||||
|
# Require a specific version of stack, using version ranges
|
||||||
|
# require-stack-version: -any # Default
|
||||||
|
# require-stack-version: ">=1.1"
|
||||||
|
#
|
||||||
|
# Override the architecture used by stack, especially useful on Windows
|
||||||
|
# arch: i386
|
||||||
|
# arch: x86_64
|
||||||
|
#
|
||||||
|
# Extra directories used by stack for building
|
||||||
|
# extra-include-dirs: [/path/to/dir]
|
||||||
|
# extra-lib-dirs: [/path/to/dir]
|
||||||
|
#
|
||||||
|
# Allow a newer minor version of GHC than the snapshot specifies
|
||||||
|
# compiler-check: newer-minor
|
2
test/Spec.hs
Normal file
2
test/Spec.hs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
main :: IO ()
|
||||||
|
main = putStrLn "Test suite not yet implemented"
|
Loading…
Reference in New Issue
Block a user