Machine Learning Explained – Part 1.4

Getting Started with Matlab – Part 1:

A lot of the math used for Machine Learning (ML) is linear algebra, actually a lot of engineering in general is based on the stuff. A matrix of numbers could represent everything from a circuit based control system, to a concrete pillar under a bridge. This also means that all the CAD software runs on the stuff as well. Its basically everywhere.

Linear algebra can be done by hand or you could do it using a programming language. You could be hardcore and write your own super optimized matrix inversion antilogarithms in C. Or even use python’s Numpy, or even R. However the industry standard is Matlab, these guys hold a virtual monopoly over the realm of engineering programming languages. When I say “engineering” I mean the hard physically based stuff like designing aircraft and rockets, or buildings.

Some would argue that Matlab is easier then Python, it is but only for linear algebra. You would not want to make your website in this stuff. Matlab works using a repal interface, all your variables are stored in memory and persist in your work space, this work space can be saved and loaded up again when you need it.

Below are some Matlab’s more basic commands.

% The ; means we are stoping and starting a new row
A = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12] % 4 X 3 matrix
% making a vector and stroing it in v
v = [1;2;3] % 3 X 1 matrix
[m,n] = size(A) % the size function returns the amoutn of rows and columns and puts them in m and n
% now you can access m and n as two different variables
% You could also store it this way
% in this case size will return a vector that has the size
% it will be [4,3]
dim_A = size(A)
% You can access different parts of the matrix
A_23 = A(2,3) % loking for the element in the 2nd row and 3rd column
% OPERATIONS
A = [1, 2, 4; 5, 3, 2]
B = [1, 3, 4; 1, 1, 1]
s = 2 % just like python there is no static typing
% adds element-wise
add_AB = A + B
% subtraction element-wise
sub_AB = A B
% scalar multiplication
mult_As = A * s
% Divide A by s
div_As = A / s
% scalar addition, does the same thing as what you would expect in A/s
add_As = A + s
v = [1;1;1]
% Multipling A * v
A_Times_v = A * v % easy as pie 🙂
% taking the inverse of a matrix
InvOfA = A'
% Taking the inverse of A
A_inv = inv(A) % also easy as pie 🙂
% note bigger matrices take longer

view raw
Mat1.m
hosted with ❤ by GitHub

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s