0:00

You now know a bunch about machine learning.

Â In this video, I'd like to teach you a programming language, Octave, in which

Â you'll be able to very quickly implement the learning algorithms we've seen

Â already and the learning algorithms we'll see later in this course.

Â In the past, I've tried to teach machine learning using a live variety of

Â different programming languages including C+++, Java

Â Python NumPy, R and also Octave. And what I've found is that students were

Â able to learn the most productively learn the most quickly and prototype the

Â algorithms most quickly, using a relatively high level language like

Â Octave. In fact .

Â what I often see in Silicon Valley is that

Â if, even if you need to build, if you want to build a large scale deployment of

Â a learning algorithm, what people will often do is prototype in

Â the language like Octave, which is a great prototyping language.

Â So you can sort of get your learning algorithms working quickly.

Â And then, only if you need a very large scale deployment of it,

Â only then spend your time reimplementing the algorithms in C+++ or Java, or some

Â other language like that. Because one of the lessons we've learned

Â is that program a time or developer time, that is your time,

Â you know, the machine learning experience time is incredibly valuable.

Â And if you can get your learning happens to work more quickly in Octave, then

Â overall, you have a huge time savings by first developing the algorithms in

Â Octave, and then implementing in like maybe C++ or Java only after we have the

Â ideas working. The most common prototyping languages I

Â see people use for machine learning are Octave,

Â Matlab, Python NumPy, and R. Octave is nice since it's free open

Â source and Matlab works well, too, but is expensive to many people.

Â But if you have access to a copy of Matlab, you can also use Matlab for this

Â class. If you know Python NumPy, or if you know

Â R, I do see some people use it. But what I see is that people usually end

Â up developing somewhat more slowly in, you know, mul, these languages because

Â the Python NumPy syntax is just slightly concur than the Octave syntax. and so

Â because of that and because we're releasing starter code in Octave I

Â strongly recommend that you not try to do the programming exercises in this class

Â and NumPy R, but that I do recommend that you instead do the programming exercises

Â for this class in Octave instead. What we're going to do in this video is

Â go through a list of commands fairly quickly, and the goal is to show you the

Â range of commands and the range of things you can do in Octave.

Â The course website will have a transcript of everything I do.

Â And so after watching this video, you can refer to the, to the transcript posted on

Â the course website when you want to find a command.

Â Briefly, what I recommend you do is first watch the tutorial videos.

Â And after watching, you know, to the end, then install Octave

Â on your computer. And finally, go to the course website,

Â download the transcript of the things you see in this session and type in whatever

Â commands seem interesting to you in to the octaves of running on your own

Â computer so that you can see it work for yourself.

Â And with that, let's get started. Here's my Windows desktop, and I'm going

Â to start an Octave. And I'm now in octave and, and there's my

Â octave prompt. Let me first show you the elementary

Â operations you can do in octave. So you can type in 56, + 6, that gives

Â you the answer of 11. 3 - 2,

Â 5 * 8, 1/2, 2^6 is 64. So, those are the elementary math

Â operations. You can also do logical operations. So, 1

Â = 2 this evaluates to false. The percent command here is means a

Â comment. So, 1 = 2 evaluates to false which is represented by zero.

Â One not equals to two, this is true so that returns one, note that the not equal

Â sign is tilde equals symbol and not than equals which is what some other program

Â languages use. Let's see logical operations one and

Â zero, use a double ampersand sign to denote the logical and,

Â and that evaluates the false one over zero.

Â z or operation, and that evaluates to true.

Â And I can xor one and zero, and that evaluates to one.

Â This thing over on the left is octave 3.2.4.exe:11. This is the default octave

Â prompt. So it shows the what?

Â a version in Octave, and so on. if you don't want that problem, there's a

Â somewhat cryptic command, PS, quote, greater than, greater than, and so on,

Â that you can use to change the prompt. And I guess this quote of string in the

Â middle your quote greater than, greater than space,

Â that's what I prefer my octave prompt to look like.

Â So, if I hit Enter oops, excuse me. Like so,

Â PS1 like so, now my octave prompt is changed to the

Â greater than, greater than sign which, you know, looks quite a bit better.

Â Next, let's talk about octave variables. I can take the variable a and assign it

Â to three, and hit Enter. And now, a is equal to three.

Â If you want to assign a variable but you don't want it to print out the result, if

Â you put a semicolon, the semicolon suppresses the print the, the print

Â output. So, if we do that, Enter, it doesn't print anything.

Â Whereas a equals three, you know, makes it prints it out, whereas a equals three

Â semicolon doesn't print anything. I can do string assignments, b equals hi.

Â now, if I just enter b, it prints out the variable b,

Â so b is the string hi. c3, equals three greater than or equal to

Â one. So now, c evaluates to true.

Â If you want to print out or display a variable, here's how you go about it.

Â Let me set api. equals pi.

Â And if I want to print a, I can just type a like so, and it'll print it out.

Â For more complex printing, there's also the disp command which sense the

Â displays, when display a, just prints out a like so.

Â You can also display strings, so disp print f, two decimals.

Â The percent of 0.2f, a like so. And this print out the string, 2

Â decimals: 3.14. This is kind of a old, old style C syntax

Â for those of you that have coded in C before, this is essentially the syntax

Â you used to print strings. So the, sprint f generator generates a,

Â generates a string that is this, you know, two decimals 3.14 one for string.

Â This percent 0.2f means substitute a into here, sharing it with, you know, two

Â digits after the decimal point. And the disp takes this string that's generated

Â by this print f command, s print f or the string print f command, and disp actually

Â displays the string. And to show you another example,

Â sprint f six decimals percent 0.6f, a and this should print pi with six decimal to,

Â to six decimal places. Finally, I was explaining a like so, a

Â lot like this. There, there are useful short cuts that

Â you type format long. It causes strings to by default to be

Â assuage to a lot more decimal places to and format short is a command that

Â resources default of just printing a small number of digits.

Â Okay. That's how you work with variables.

Â Now, let's look at vectors and matrices. Let's say, I want to assign a to a

Â matrix, let me show you an example. 12; 34; 56, this generates a three by two

Â matrix a whose first row is one two, second row is three, four, the third row

Â is five, six. What the semicolon does is essentially

Â say, go to the next row of the matrix. There are other ways to type this, a=12;1

Â 34;. 56 like so,

Â and that's another equivalent way of assigning a to be the values of this

Â three by two matrix. Similarly, you can assign vectors.

Â So, v = 1,2,3. this is actually a row vector,

Â or this is a three by one vector, right?

Â This is a fat y vector, as a, excuse me, not, this is

Â a one by three matrix, right?

Â 8:37

not three by one. If I want to assign this to a column

Â vector, what I would do is instead do v1;2;3.

Â = 1; 2; 3, and this will give me a three by one, instead of one by three vector.

Â So this would be a column vector. So here's some more useful notation.

Â I can all set v1:0.1:2. = 1:0.1:2.

Â What this does is it sets v to the bunch of elements that start from one and

Â increments in steps of 0.1 until you get up to two.

Â So, I might do this. v is going to be this, you know, row

Â vector or this is what? A one by eleven matrix really that's 1.1,

Â one, 1.1, 1.2, 1.3 and so on until we get up to two.

Â Now and I can also say that v1:6, = 1:6 and that set's v to v, you know, these

Â numbers one through six. Okay.

Â Now, here are some other ways to generating matrices.

Â One's two by three, is a command that generates a matrix that is a two by three

Â matrix that is the matrix of all ones. So, if I set c equals 2 times ones, two

Â by three, this generates a two by three matrix that is all twos.

Â And this is, you can think of it as a shorter way of writing this and c equals

Â two, two, two, semicolon two, two, two, which would also give you the same

Â result. The set w equals ones, one by three, so

Â this is going to be a row vector or a you know, a row of three ones.

Â And similarly, you can also say w equals zeroes one by three, and, this generates

Â a matrix, a one by three matrix of all zeroes.

Â Just a couple more ways to generate matrices.

Â if I do w equals rand one by three, this gives me a one by three matrix of all

Â random numbers. If I do rand three by three,

Â this gives me a three by three matrix of all random numbers drawn from the uniform

Â distribution between zero and one. So, every time I do this, I get a

Â different set of random numbers drawn uniformly between zero and one.

Â For those of that who know what a Gaussian random variable is or for those

Â of you who know what a normal random variable is,

Â you can also set w equals rand n one by three.

Â and so these are going to be three values drawn from a Gaussian distribution with

Â mean zero and variant or standard deviation equal to one. And you can set

Â more complex things like w-6 = -6 plus square root of ten times let's say, rand

Â n one by ten thousand, and I'm going to put a semicolon at the end because I

Â don't really want this printed out. This is going to be what, well, it's going to

Â be a vector with a hundred thousand excuse me, ten thousand elements. So,

Â well, actually, you know what? Lets, lets print it out.

Â So this will generate a matrix like this right? With 10,000 elements, so that's

Â what w is. And if I now plot the histogram of w with

Â the hist command, I can now, and octaves print hist command,

Â you know, it takes a couple seconds to bring this up, but this is a histogram of

Â my random variable for w. That was -6 plus zero, ten times this

Â Gaussian random variable. And I can plot a histogram with more

Â buckets with more bins with say, 50 bins and

Â this is my histogram of Gaussian with mean minus six, because I have minus six

Â there, plus square root ten times this. So, the the varians or, this, of, of this

Â Gaussian random variable is ten over standard diviation, this square root of

Â ten, which is about what? 3.1. Finally, one special command to generate

Â a matrix, which is the eye command. So, eye stands for this is maybe a pun on

Â the word identity, but so I'm going to set eye 4, this is the four by four

Â identity matrix. So, I equals eye 4, this gives me a four

Â by four identity matrix. And I equals eye 5 eye 6, that gives me a

Â six by six identity matrix, and eye 3 is the three by three identity matrix.

Â Lastly, to wrap up this video there's one more useful command which is the help

Â command. So you can type help eye, and this brings

Â up the help function for the identity matrix.

Â hit q to quit. And you can also type help rand, brings

Â up documentation for the rand or the random number generation function, or

Â even help, help which shows you, you know, help on the help function.

Â So, those are the basic operations in Octave.

Â and with this you should be able to generate a few matrices multiply, add

Â things and, and use the basic operations in Octave.

Â In the next video, I'd like to start talking about more sophisticated commands

Â and how to move data around and to start to process data in Octave.

Â