首页 » Scheme代写 » Scheme代写 | CSI2120 Programming Paradigms

Scheme代写 | CSI2120 Programming Paradigms

这个作业是用Scheme完成旅行问题、神经网络等
CSI2120 Programming Paradigms
Winter 2020
Due on April 5
th before 11:00 pm in Virtual Campus
6 marks
There are [11 points] in this assignment. The assignment is worth 6% of your final mark.
All code must be submitted in a scm file. Screenshots, files in a format of a word editor, pdfs,
handwritten solutions, etc. will not be marked and receive an automatic 0.
Question 1. Filter and Map [1 point]
Use the built-in filter and map to change a list as follows
Drop each number between -1 and +1 inclusive
For each number greater than 1 replace the number with 10 times the number.
For each number smaller than -1 replace the number with the absolute value of the reciprocal.
(changeList ‘(0 -2 3 -4 1))
 ‘( 1/2 30 1/4 )
Question 2. List Processing [2 points]
Find the longest sub-list of numbers which are identical and return this sub-list.
In case of a tie, return the sub-list occurring last.
(sameNum ‘( 0 1 5 3 3 3 2 1 1))
 ‘( 3 3 3)
(sameNum ‘( 0 1 5 3 3 3 2 1 1 1))
 ‘( 1 1 1)
CSI 2120 page 2
_________________________________________________________________________________________________
Question 3. Travellers [4 points]
Implement a function destination that tallies the vote for where a group of friends want to travel to.
Each friend votes for three destinations. The result needs to be a list containing all destinations that
received the most votes (ties are possible).
Examples:
(define choices ‘(‘(“marie” ‘(“peru” “greece” “vietnam”))
‘(“jean” ‘(“greece” “peru” “vietnam”))
‘(“sasha” ‘(“vietnam” “peru” “greece”))
‘(“helena” ‘(“peru” “vietnam” “greece”))
‘(“emma” ‘(“greece” “peru” “vietnam”))))
(destination choices)
 ‘((“peru” . 13))
(define choices ‘(‘(“marie” ‘(“peru” “greece” “vietnam”))
‘(“jean” ‘(“greece” “peru” “vietnam”))
‘(“sasha” ‘(“vietnam” “peru” “greece”))
‘(“helena” ‘(“peru” “vietnam” “greece”))
‘(“emma” (“greece” “peru” “vietnam”))
‘(“jane” (“greece” “vietnam” “peru”))))
(destination choices)
 ‘((“peru” . 13) (“greece” . 13))
You are allowed extra global helper functions.
CSI 2120 page 3
_________________________________________________________________________________________________
Question 4. Neural Network [4 points]
Write a program that simulates a Neural Network in Scheme. We use what is called a multilayer
perceptron with 1 hidden layer with an input and output layer. Each neuron calculates the weighted sum
of its input (including an offset) and applies an activation function. Consider the figure below. for the
example of a slice of size 2.
In the above example the equation for the first hidden neuron 𝑍1 = 𝜎(𝛼10 + 𝛼11𝑋1 + 𝑎12𝑋2
). The
equation for the output neuron is 𝑇1 = 𝜎(𝛽10 + 𝛽11𝑍1 + 𝛽12𝑍2 + 𝛽13𝑍3). The inputs 𝑋1 and 𝑋2 simply
pass their value to all hidden layers.
Your program must create exactly he network shown above with the following parameters
𝛼10 = 0.1 𝛼11 = 0.3 𝑎12 = 0.4
𝛼20 = 0.5 𝛼21 = 0.8 𝑎22 = 0.3
𝛼30 = 0.7 𝛼31 = 0.6 𝑎32 = 0.6
𝛽10 = 0.5 𝛽11 = 0.3 𝛽12 = 0.7 𝛽13 = 0.1
a) Implement a neural network node which takes a list of weights and an activation function. The
function is to return a function accepting a list of input values.
(neuralNode ‘(0.1 0.3 0.4) sigmoid)
 # ((neuralNode ‘(0.1 0.3 0.4) sigmoid) ‘(0.5 0.5))
 0.610639233949222
𝑋1
𝑍1
𝑇1
𝑍2 𝑍3
𝑋2
Hidden Layer
Output Layer
Input Layer 1
1
CSI 2120 page 4
_________________________________________________________________________________________________
b) Use your neuralNode function to implement one layer of the neural network shown in the
above figure. Use the sigmoid function 𝜎(𝑣) =
1
1+𝑒−𝑣
as the activation function.
Example (hidden layer)
(neuralLayer ‘((0.1 0.3 0.4)(0.5 0.8 0.3)(0.7 0.6 0.6)))
 # ((neuralLayer ‘((0.1 0.3 0.4)(0.5 0.8 0.3)(0.7 0.6 0.6))) ‘(0.5
0.5))
 ‘(0.610639233949222 0.740774899182154 0.7858349830425586)
c) Use your neuralLayer function to implement the complete neural network shown in the
above figure. Use the sigmoid function 𝜎(𝑣) =
1
1+𝑒−𝑣
as the activation function.
(neuralNet ‘(0.5 0.5))
 ‘(0.782503850784443)
d) Write a function that takes as input a parameter k determining the number of times the neural
network is run. Your program must apply the neural network to a series of input values and
calculate the network output for each pair of input values in a loop. These input values are 𝑋1,𝑘 =
sin 2𝜋(𝑘−1)
𝑁
and 𝑋2,𝑘 = cos
2𝜋(𝑘−1)
𝑁
where 𝑘 = 1 … 𝑁 is the index of the current loop variable.
The function must return all calculated output values in a list.
(applyNet 16)
 ‘(0.7770060393971061 0.7853501263409901 0.7897263070205873
0.7902968594617558 0.7872242379440337 0.7805159297515977
0.7702872231675277 0.7573421434408293 0.7436542255881534
0.7320120209466757 0.7248686717891844 0.7235344799330423
0.7281858924381838 0.7380276807952172 0.7512282131381334
0.765101793865149)
Note that your output formatting may look different (number of digits and or line breaks)


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论

您的电子邮箱地址不会被公开。