Octave implementation for Programming Assignment 1: The perceptron learning algorithm.

To start with, let's read the passage and follow the instruction:

In this assignment you will take the provided starter code and fill in the missing details in order to create a working perceptron implementation.

To start, download the following code files:

And the following datasets:

Attention: some people have notified us that the provided datasets do not load under some versions of Octave. We are providing the same datasets in a different format that will hopefully work with more versions. You can find these files below.

And the following datasets:

For those who want to download all of the files together in a zip archive, you get get them here: Assignment1.zip

To run the code, you first need to load a dataset. To do so enter the following command in the Octave console (to load dataset 1):

load dataset1

after we type it, This should load 4 variables:

  • neg_examples_nobias - The matrix containing the examples belonging to class 0.
  • pos_examples_nobias - The matrix containing the examples belonging to class 1.
  • w_init - Some initial weight vector.
  • w_gen_feas - A generously feasible weight vector (empty if one doesn't exist)

That is: (the picture is as follow)


The variables have _nobias appended to their names because they do not have an additional column of 1's appended to them. This is done automatically in the learn_perceptron.m code already. Now that you have loaded a dataset, you can run the algorithm by entering the following at the Octave console:

w = learn_perceptron(neg_examples_nobias,pos_examples_nobias,w_init,w_gen_feas)

This will start the algorithm and plot the results as it proceeds. Until the algorithm converges you can keep pressing enter to run the next iteration. Pressing 'q' will terminate the program. At each iteration it should produce a plot that looks something like this.

So I type the command above( Which I colored it in blue)


 and things are shown below:


maybe you will be confused about the "distance" and " Number of errors", so let's do several iteration, and then you will see it clearly:

we can find that in the plot above, the dot linked into a line, let's do more iterations and you can figure it out:


this is after 6 interations, we get a longer line, because we didn't make up the missing part in the code, so now the distance will not change.

The top left plot shows the data points. The circles represent one class while the squares represent the other. The line shows the decision boundary of the perceptron using the current set of weights. The green examples are those that are correctly classified while the red are incorrectly classified. The top-right plot will show the number of mistakes made by the perceptron. If a generously feasible weight vector is provided (and not empty), then the bottom left plot will show the distance of the learned weight vectors to the generously feasible weight vector.

Currently, the code doesn't do any learning. It is your job to fill this part in. Specifically, you need to fill in the lines under learn_perceptron.m marked %YOUR CODE HERE (lines 114 and 122). When you are finished, use this program to help you answer the questions below.

In addition, we print out the plot of dataset 2/3/4, because it will help us answering the questions below.


we can see that if we load different dataset, the variables will also change, and the plot of dataset2 is:


then, dataset3:


then, dataset4


第 1 个问题

now we can answer the following questions:

第 2 个问题
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值