Setting Up Your Programming Assignment Environment
Setting Up Your Programming Assignment Environment
Setting Up Your Programming Assignment Environment
Assignment Environment
The Machine Learning course includes several programming assignments which youll need to
finish to complete the course. The assignments require the Octave or MATLAB scientific
computing languages.
Octave is a free, open-source application available for many platforms. It has a text
FAQ
Does it cost money?
While youre taking the course, both software packages are available free of charge. Octave is
distributed under the GNU MATLAB Public License, which means that it is always free to
download and distribute. MATLAB licenses are available for completing the programming
assignments in the course only. For any other purposes (like your own work after you complete
the course), MATLAB can be licensed to individuals or companies from Mathworks directly.
We are working with the Octave team to resolve this issue. In the meantime, please use
MATLAB.
2. Download the Octave 3.8.0 installer. The file is large so this may take some time.
3. Open the downloaded image, probably named GNU_Octave_3.8.0-6.dmg on your computer,
and then open Octave-3.8.0-6.mpkg inside.
4. Follow the installers instructions. You may need to enter the administrator password for your
computer.
5. After the installer completes, Octave should be installed on your computer. You can
find Octave-cli in your Macs Applications, which is a text interface for Octave that you can use to
complete Machine Learnings programming assignments.
Octave also includes an experimental graphical interface which is called Octave-gui, also in your
Macs Applications, but we recommend using Octave-cli because its more stable.
Note: If you use a package manager (like MacPorts or Homebrew), we recommend you
follow the package manager installation instructions.
MathWorks is providing you access to MATLAB for use in your coursework. When planning your
activity, please note that access is valid for 120 days upon activating.
Use the link provided to download and install. You will need to log-in to your MathWorks account,
or create one if you do not have one. After starting the installer, accept all defaults and log-in to
your MathWorks account when prompted.
Installing Octave/MATLAB on
GNU/Linux
Installing Octave on GNU/Linux
We recommend using your system package manager to install Octave.
On Ubuntu, you can use:
Please consult the Octave maintainers instructions for other GNU/Linux systems.
MATLAB Resources
At the MATLAB command line, typing help followed by a function name displays documentation
for a built-in function. For example, help plot will bring up help information for plotting. Further
documentation can be found at the MATLAB documentation pages.
MathWorks also has a series of videos about various MATLAB features:
Introduction to MATLAB
Learning Module
Learning Goals
What is MATLAB?
Introduce MATLAB
The MATLAB
Environment
MATLAB Variables
MATLAB as a
Calculator
Mathematical
Use MATLAB variables for input and output to functions. Examples include:
Functions
Vectors
Learning Module
Learning Goals
Vector Arithmetic
element-wise operations
Vector Transpose
Visualization
Learning Module
Learning Goals
Line Plots
Create a line plot of a vector and customize plot markers and colors
Annotating Graphs
Learning Module
Learning Goals
Creating Matrices
Array
row-column indexing.
Concatenating Arrays
Matrix Multiplication
Programming
Learning Module
Learning Goals
Write a script in the MATLAB Editor, break code into sections to execute,
and find help on functions
Logical Operators
Use relational and logical operators to create logical variables for program
control
Conditional Data
Selection
Access and change elements for a vector the meet a specified criteria
If-Else Statements
For Loops
While Loops
videos together as a group. However, the answers that you submit for the review
questions should be your own work. For theprogramming exercises, you are welcome to
discuss them with other students, discuss specific algorithms, properties of algorithms, etc.; we
ask only that you not look at any source code written by a different student, nor show your
solution code to other students.
>> A(:,1) = 0
The above is always acceptable (in my understanding). Demonstrating techniques and learning
the language/syntax are important Forum activities.
Thank you to Machine Learning Mentor, Tom Mosher, for compiling this list
Text:
The lectures and exercise PDF files are based on Prof. Ng's feeling that novice programmers will
adapt to for-loop techniques more readily than vectorized methods. So the videos (and PDF files)
are organized toward processing one training example at a time. The course uses column
vectors (in most cases), so h (a scalar for one training example) is theta' * x.
Lower-case x typically indicates a single training example.
The more efficient vectorized techniques always use X as a matrix of all training examples, with
each example as a row, and the features as columns. That makes X have dimensions of (m x n).
where m is the number of training examples. This leaves us with h (a vector of all the hypothesis
values for the entire training set) as X * theta, with dimensions of (m x 1).
X (as a matrix of all training examples) is denoted as upper-case X.
Throughout this course, dimensional analysis is your friend.
Subject: Tips from the Mentors: submit problems and fixing program errors
Text:
This post contains some frequently-used tips about the course, and to help get your programs
working correctly.
At the Octave/Matlab command line, you do not need to include the ".m" portion of the script file
name. If you include the ".m", you'll get an error message about an invalid indexing operation. So,
run the Exercise 1 scrip by typing just "ex1" at the command line.
You also do not need to include parenthesis () when using the submit script. Just type "submit".
You cannot execute your functions by simply typing the name. All of the functions you will work
on require a set of parameter values, enter between a set of parenthesis. Your three methods of
testing your code are:
1 - use an exercise script, such as "ex1"
2 - use a Unit Test (see below) where you type-in the entire command line including the
parameters.
3 - use the submit script.
Getting Help:
When you want help from the Forum community, please use this two-step procedure:
1 - Search the Forum for keywords that relate to your problem. Searching by the function name is
a good start.
2 - If you don't find a suitable thread, then do this:
2a - Find the unit tests for that exercise (see below), and run the appropriate test. Attempt to
debug your code.
2b - Take a screen capture of your whole console workspace (including the command line), and
post it to the forum, along with any other useful information (computer type, Octave/Matlab
version, other tests you've tried, etc).
Debugging:
If your code runs but gives the wrong answers, you can insert a "keyboard" command in your
script, just before the function ends. This will cause the program to exit to the debugger, so you
can inspect all your variables from the command line. This often is very helpful in analysing math
errors, or trying out what commands to use to implement your function.
Unit Tests:
Each programming assignment has a "Discussions" area in the Forum. In this section you can
often find "unit tests". These are additional test cases, which give you a command to type, and
provides the expected results. It is always a good idea to test your functions using the unit tests
before submitting to the grader.
If you run a unit test and do not get the correct results, you can most easily get help on the
forums by posting a screen capture of your workspace - including the command line you entered,
and the results.
The "short-circuit" warnings are due to use a change in the syntax for conditional expressions (|
and & vs || and &&) in the newer versions of Matlab. You can edit the fmincg.m file and the
warnings may be resolved.