Deep Learning with elixir. This project is called Deep Pipe(DP). I implemented backpropagation and numerical-gradient. Now I'm testing small data set.
Network example (See test.ex)
defnetwork init_network2(_x) do
_x |> f(5,5) |> flatten
|> w(576,100) |> b(100) |> sigmoid
|> w(100,10) |> b(10) |> sigmoid
endTODO:
Organize test case
Improve testing
Create a library and register to hex
sudo apt install build-essential
sudo apt-get install build-essential erlang-dev libatlas-base-dev
mix deps.get
make clone or download and enter "iex -S mix" on terminal
module DP is Deep Pipe(DP) module module CTensor is code for CNN data operation module Cmatrix is code for Matrix module MNIST is code for MNIST data set module Time is time/1 for measure execution time
iex(1)> require(Time)
Time
iex(2)> Time.time(Test.momentum(30,100))
preparing data
ready
2.866287227629866
2.5600212240059506
...
0.04318082027257467
0.029026173275906994
0.03131037967594155
0.06550367669302301
accuracy rate = 0.879
"time: 55248299 micro second"
"-------------"
:okstructure of Matrex(CBLAS) e.g. m[2*3]
data structure of Matrex(CBLAS) e.g. m[1*3]
e.g. [m[23],n[23]]
e.g. [{:weight,w,lr,v},{:bias,b,lr},{:function,f,g}]
{:weight,w,lr,v} w is matrix, lr is learning rate, v is for momentum,adagrad,adam
{:bias,b,lr,v} b is row vector
{:filter,w,lr,st,v} st is stradd for convolution
{:pad,n} n is size of padding
{:pool,st} st is stradd
{:function,f,g,h} f is function, g is differential function, h is function name softmax {:softmax,f,_ } f is function, only output layer softmax is set with cross_entropy
defnetwork is macros to describe network argument must have under bar to avoid warning message
weight matrix size(m,n). elements are Gaussian distribution random float
lr is learning rate (default is 0.1)
z is multiple for Gaussian distribution random float. (default is 0.1)
bias row_vector size(n). elements are all zero b(n,lr) lr is learning rate (default is 0.1)
sigmoid,relu,ident,softmax
filter matrix size(m,n). elements are Gaussian distribution random float
lr is learning rate
z is multiple for Gaussian distribution random float.(default is 0.1)
st is stradd
padding n is size of padding
pooling stride size is st
forward calculation for batch data forward(x,network) x is data(matrix or tensor) , network
calculate gradient by numerical differentiation
x is data, t is train data, loss function is mean_square
loss function is cross_entropy
loss function is mean_square
caluculate gradient by backpropagation
x is data, t is train data
update network with gradient
update with sgd
update with sgd
update with momentum method
update with adagrad method
update with adam method
print data
print LF
save network data to file
load network data from file
loss function
y is row vector of result and t is row vector of train
loss function
y is row vector of result and t is row vector of train
get train image data size of n. Each data is 28*28 matrix
get train image data size of n. Each data is 784 row_vector
get train label data aas onehot row_vector
get test image data size of n. Each data is 28*28 matrix
get test image data size of n. Each data is 784 row_vector
get test label data aas onehot row_vector