联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2022-05-30 08:01

ECS 170: Spring 2022

Homework Assignment 5


Due Date:


No later than Thursday, June 2, 9:15pm PDT. (You don't have to wait that long, and you

shouldn't. You have a final exam the next day. But I understand that some of you prefer to wait

until the last minute.)


You are expected to do this assignment on your own, not with another person.


This assignment looks really long. Don't panic. Most of this document is just examples.


The assignment:


Recall the perceptron learning model described in Lectures 16 and 17. Your task is to use Python

to write a function that implements the perceptron described in those lectures. Your function

should be named perceptron.


Your function should expect five arguments, in this order, left-to-right:

A number representing the threshold

A number representing the adjustment factor

A list of numbers representing the initial weights on the inputs

A list of examples for training the perceptron

A number representing the number of passes the perceptron should make through

the list of examples


Let’s map these descriptions onto the actual values used in the example:

In the example, the threshold was 0.5

The adjustment factor was 0.1

If contained in a list, the initial weights were [-0.5, 0, 0.5, 0, -0.5]

The list of examples was: [[True, [1,1,1,1,0]],

[False, [1,1,1,1,1]],

[False, [0,0,0,0,0]],

[False, [0,0,1,1,0]],

[False, [1,0,1,0,1]],

[False, [1,0,1,0,0]],

[False, [0,1,0,1,1]],

[False, [0,1,0,1,0]],

[False, [0,0,1,0,0]],

[False, [0,0,0,1,0]]]

The number of passes through the list of examples was 4


Each example in the list of examples has two parts. The first part (True or False) indicates

whether this example is a positive example (True) of the concept to be learned or a negative

example (False). The second part is a list of 1’s or 0’s. This list (the 1's and 0's) must be the same

length as the list of initial weights.


Now let’s say that the variable weights is bound to the list of weights shown above, and that the

variable examples is bound to that list of examples above. If you write your function exactly like

I did, then when your function is called like this:


>>> perceptron(0.5, 0.1, weights, examples, 4)


your function would print the following output (sorry, it’s really long, just like in Lecture 17):


Starting weights: [-0.5, 0, 0.5, 0, -0.5]

Threshold: 0.5 Adjustment: 0.1


Pass 1


inputs: [1, 1, 1, 1, 0]

prediction: False answer: True

adjusted weights: [-0.4, 0.1, 0.6, 0.1, -0.5]

inputs: [1, 1, 1, 1, 1]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.6, 0.1, -0.5]

inputs: [0, 0, 0, 0, 0]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.6, 0.1, -0.5]

inputs: [0, 0, 1, 1, 0]

prediction: True answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [1, 0, 1, 0, 1]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [1, 0, 1, 0, 0]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [0, 1, 0, 1, 1]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [0, 1, 0, 1, 0]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [0, 0, 1, 0, 0]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]

inputs: [0, 0, 0, 1, 0]

prediction: False answer: False

adjusted weights: [-0.4, 0.1, 0.5, 0.0, -0.5]


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp