Feed Forward MLP Library with Matlab. Written for readability not performance.
nn/
: library codeutil/
: scrappy utility functions for plotting, weight initialization, etc.examples/
: examples of NN classification and regression using the lib
- Mean squared error:
mean_squared_error = @(y_hat,y) (1/size(y_hat,1)) * sum((y_hat-y).^2);
mean_squared_error_gradient = @(y_hat,y) (1/size(y_hat,1))*2*(y_hat-y);
- Cross entropy loss:
cross_entropy_loss = @(y_hat,y) (1/size(y_hat,1)) * ...
sum(-(y .* log(y_hat)) ...
- (1-y) .* log(1-y_hat));
cross_entropy_loss_gradient = @(y_hat,y) (1/size(y_hat,1)) * (y_hat-y);
Add custom loss functions in nn/ErrorFunctions.m
.
- Tanh
tanh_activation = @(x) tanh(x);
tanh_activation_prime = @(x) 1-(tanh(x).^2);
- ReLU
relu_activation = @(x) x.*(x>0);
relu_activation_prime = @(x) 1.*(x>0);
- Sigmoid
sigmoid_activation = @(x) 1./(1.+exp(-x));
sigmoid_activation_prime = @(x) 1./(1.+exp(-x)).*(1-(1./(1.+exp(-x))));
Add custom activation functions in nn/ActivationLayer.m
.
- requires Matlab R2016b or later
- also Matlab sux
Add these lines to your .bash_profile
or .zshrc
:
export PATH=/Applications/Matlab_R20XXx.app/bin:$PATH
# or wherever matlab is on your computer
# if you don't know where matlab is, open the matlab gui and run 'matlabroot'
alias matlab="matlab -nodisplay -nosplash"
# now you can just run '$ matlab' to start a matlab session