homework | Artificial Intelligence作业 | Artificial Intelligence代做 | 代做Algorithm | java | assignment – CS 540: Introduction to Artificial Intelligence

CS 540: Introduction to Artificial Intelligence

homework | ai作业 | network代做 | 代做Algorithm | java | assignment – 该题目是一个常规的network的练习题目代写, 是有一定代表意义的artificial intelligence/人工智能/Algorithm/java等代写方向, 这个项目是assignment代写的代写题目

network代写 代写计算机网络

homework assignment # 10

Assigned: 4/

Due: 4/30 before class

Hand in your homework:

If a homework has programming questions, please hand in the java program. If a homework has written questions, please hand in a PDF file. Regardless, please zip all your files into hwX.zip where X is the homework number. Go to UW Canvas, choose your CS540 course, choose Assignment, click on Homework X: this is where you submit your zip file.

Late Policy:

All assignments are due at the beginning of class on the due date. One (1) day late, defined as a 24-hour period from the deadline (weekday or weekend), will result in 10% of the total points for the assignment deducted. So, for example, if a 100-point assignment is due on a Wednesday 9:30 a.m., and it is handed in between Wednesday 9:30 a.m. and Thursday 9:30 a.m., 10 points will be deducted. Two (2) days late, 25% off; three (3) days late, 50% off. No homework can be turned in more than three (3) days late. Written questions and program submission have the same deadline. Assignment grading questions must be raised with the instructor within one week after the assignment is returned.

Collaboration Policy:

You are to complete this assignment individually. However, you are encouraged to discuss the general algorithms and ideas with classmates, TAs, and instructor in order to help you answer the questions. You are also welcome to give each other examples that are not on the assignment in order to demonstrate how to solve problems. But we require you to:

  • not explicitly tell each other the answers
  • not to copy answers or code fragments from anyone or anywhere
  • not to allow your answers to be copied
  • not to get any code on the Web

In those cases where you work with one or more other people on the general discussion of the assignment and surrounding topics, we suggest that you specifically record on the assignment the names of the people you were in discussion with.

Question 1: Neural network [60 points, evenly among parts]

We will build a neural network to determine if a bank note is authentic. We have obtained a data set (https: //archive.ics.uci.edu/ml/datasets/banknote+authentication) with features that are properties of a wave transformed bank note image such as variance, skewness, curtosis and entropy. The data set has already been processed and three csv files (train.csv, eval.csv and test.csv) can be downloaded from the course website. Each line in these files have four real-valued features which we will denote withx= (x 1 ,x 2 ,x 3 ,x 4 ), and the class labelywhich is either 0 or 1. Our neural network architecture is shown below:

Input
layer
(1)
Hidden
layer
(2)
Output
layer
(3)
1
x
x
x
x
w(2) 10
w(2) 11
w(2) 23
w(2) 24
w(3) 10
w(3) 11
w(3) 12
1
y
Figure 1: Neural Network Architecture.

There is one hidden layer with two hidden units, and one output layer with a single output unit. The input layer is fully connected to the hidden layer, and the hidden layer is fully connected to the output layer. Each layer also has a constant bias 1 input with the corresponding weight. The weight of the network from unitjin layerl1 to unitkin layerlwill be denoted byw(kjl). For bias nodes,jwill be denoted by 0 in the weights. This convention is demonstrated for some of the weights in figure 1. We will useSigmoidactivation

function for all the activation units. Recall that the sigmoid function activation is obtained by,

g(z) =(z) =
1
1 +ez

This neural network is fully defined by the 13 weightsw(2) 10 ,…,w 14 (2),w(2) 20 ,…,w(2) 24 ,w(3) 10 ,w(3) 11 andw(3) 12. Write a programNeuralNet.javawith the following command line format:

$java NeuralNet FLAG [args]

Where the optional arguments are real valued (use double data type for them).

1.Forward Propagation:
We will first focus on making predictionsgivenfixed weights.
Recall in a neural network for any unitj, it first collects input from lower units to producez(jl), then
applies a non linear activation function to produce an activation,a(jl):
zj(l)=
i:ij
(a(il1)wji)
a
(l)
j =g(z
(l)
j ) =
1
1 +ez
Note that the activations for the input layer are the input themselves:a(1)j =xjanda(1) 0 = 1 is the
bias unit.
When FLAG=100, arg1 ... arg13 are the weightsw(2) 10 ,...,w(2) 14 ,w(2) 20 ,...,w(2) 24 ,w 10 (3),w(3) 11 andw(3) 12 , and
arg14=x 1 , arg15=x 2 , arg16=x 3 , arg17=x 4. Print activations of the hidden layer units (a(2) 1 ,a(2) 2 ) on
line one separated by a space followed by the activation of the output layer unit (a(3) 1 ) on line two.
When printing, show 5 digits after decimal point by rounding (but do not round the actual variables).
For example,
$java NeuralNet 100 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2 1 0 1 0
0.66819 0.
0.
$java NeuralNet 100 .021 .247 .35879 .1414 .75 .512 .686 .717 .818 .919 .029 .135 .20701 1 0 1 0
0.60094 0.
0.
$java NeuralNet 100 0 .2 .3 .4 .5 0 .6 .7 .8 .9 0 .5 .2 0 0 0 0
0.50000 0.
0.
Tip to handle Commandline arguments:
Since there are a lot of commandline arguments in this homework, you can use the following trick to
avoid typing the arguments each time you run the program and instead load them from a file directly.
$java NeuralNet < 100.args
where 100.args is a file that contains commandline arguments on a single line separated by spaces.
Also note that the quote characters are back-ticks. This doesnt work with normal single quotes.

2.Back Propagation:

To learn the weights of the neural network, we first store all the activations computed using forward
propagation. Then, we propagate theterms in a backwards manner to calculate the gradient of error
with respect to each weight. Once we have the gradients, we can use Gradient Descent to update the
weights to minimize the error.
Given a training examplex= (x 1 ,x 2 ,x 3 ,x 4 ) and its labely, the error made by the neural network on
the example is defined as
Ex=
1
2
(a
(3)
1 y)
2
The partial derivative of error with respect to the output activationz(3) 1 from chain rule is
Ex
z(3) 1
=
(3)
1 =
Ex
a(3) 1
a(3) 1
z 1 (3)
Now,
Ex
a(3) 1
=
(^12 (a
(3)
1 y)

(^2) ) a(3) 1

=
1
2
2(a(3) 1 y) =a(3) 1 y
and
a(3) 1
z(3) 1
=
g(z 1 (3))
z(3) 1
=a(3) 1 (1a(3) 1 )
So, we have
(3) 1 = (a(3) 1 y)a(3) 1 (1a(3) 1 )
When FLAG=200, arg1 ... arg13 are the weightsw(2) 10 ,...,w(2) 14 ,w(2) 20 ,...,w(2) 24 ,w 10 (3),w(3) 11 andw(3) 12 , and
arg14=x 1 , arg15=x 2 , arg16=x 3 , arg17=x 4 , and arg18 =y. Print a single number,(3) 1 with 5 decimals
precision. For example,
$java NeuralNet 200 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2 1 0 1 0 1
-0.
$java NeuralNet 200 -.1 .2 -.3 -.4 .5 -.5 -.6 -.7 .8 -.9 -.9 .5 -.2 -1 0 -1 0 1
-0.
$java NeuralNet 200 .101 .809 .31 .9 .13 .55 .66 .12 .31 .1 .92 .05 .22 10 0 11.1 0.01 1
-0.
  1. The partial derivative of error with respect to hidden layer activation units can be similarly computed using Chain Rule. For hidden unitj:
j(2)=(3) 1 w 1 (3)ja(2)j (1a(2)j )
FLAG=300 has same arguments as FLAG=200. Print two numbers(2) 1 ,(2) 2 separated by space. For
example,
$java NeuralNet 300 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2 1 0 1 0 1
-0.00344 -0.
$java NeuralNet 300 -.1 .2 -.3 -.4 .5 -.5 -.6 -.7 .8 -.9 -.9 .5 -.2 -1 0 -1 0 1
-0.01847 0.
$java NeuralNet 300 .101 .809 .31 .9 .13 .55 .66 .12 .31 .1 .92 .05 .22 10 0 11.1 0.01 1
-0.00000 -0.
  1. We now have all the information that we need to compute the gradient of error with respect to edge weights. To compute the partial derivative with respect to the edge weights:
Ex
w(jkl)
=(jl)a(kl1)
FLAG=400 also has same arguments as FLAG=200. Print Ex
w(3) 10
Ex
w 11 (3)
Ex
w(3) 12
on line 1, Ex
w(2) 10
Ex
w(2) 11
...Ex
w(2) 14
on line 2, andwE(2)x
20
Ex
w(2) 21 ...
Ex
w(2) 24 on line 3 each separated by a space. For example,
$java NeuralNet 400 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2 1 0 1 0 1
-0.03104 -0.02074 -0.
-0.00344 -0.00344 -0.00000 -0.00344 -0.
-0.00070 -0.00070 -0.00000 -0.00070 -0.
$java NeuralNet 400 -.1 .2 -.3 -.4 .5 -.5 -.6 -.7 .8 -.9 -.9 .5 -.2 -1 0 -1 0 1
-0.14814 -0.07777 -0.
-0.01847 0.01847 -0.00000 0.01847 -0.
0.00657 -0.00657 0.00000 -0.00657 0.
$java NeuralNet 400 .101 .809 .31 .9 .13 .55 .66 .12 .31 .1 .92 .05 .22 10 0 11.1 0.01 1
-0.04172 -0.04172 -0.
-0.00000 -0.00000 -0.00000 -0.00000 -0.
-0.00000 -0.00000 -0.00000 -0.00000 -0.
  1. Now we perform Stochastic Gradient Descent to train the neural network on the given bank note authentication data set. To do so, for each training example, we first compute activations for all the units using Forward Propagation. We then computeterms for each hidden and output unit and

compute gradients of error with respect to each weight using Backward Propagation. We then update the weights as follows:

w
(l)
jk=w
(l)
jk
Ex
wjk(l)

whereis the learning rate chosen.

We will use the training set train.csv for training the network. We will compute error on evaluation set eval.csv by summing up the error on each example from the set as follows:

Eeval=
xEval
Ex=
xEval
1
2
(a(3) 1 y)^2

When FLAG=500, arg1 … arg13 are initial weightsw(2) 10 ,…,w(2) 14 ,w 20 (2),…,w(2) 24 ,w(3) 10 ,w(3) 11 andw 12 (3), and arg14=. Print two lines for each training example in the order of their appearance (we shall ignore the actual Stochastic Gradient Descent Algorithm in which training examples are randomly selected and use the actual file order instead):

(a) the updated weightsw
(2)
10 ,...,w
(2)
14 ,w
(2)
20 ,...,w
(2)
24 ,w
(3)
10 ,w
(3)
11 ,w
(3)
12
(b) the evaluation set errorEevalafter the update

For example, (the first output line for every training example is wrapped as it is too long to fit on a single line. Please refer to the test cases provided for exact outputs)

$java NeuralNet 500 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2.
0.10020 0.19910 0.29883 0.40218 0.49989 0.50006 0.59973 0.
0.80065 0.89997 0.90277 0.50228 0.
38.
0.10071 0.19860 0.30025 0.40156 0.49910 0.50026 0.59953 0.
0.80040 0.89965 0.90709 0.50388 0.
38.
0.09969 0.19466 0.29375 0.40403 0.50010 0.50024 0.59942 0.
0.80047 0.89968 0.89494 0.49427 0.
37.
0.09986 0.19411 0.29245 0.40606 0.50000 0.50028 0.59928 0.
0.80100 0.89965 0.89770 0.49662 0.
37.
0.10012 0.19392 0.29335 0.40517 0.49912 0.50032 0.59925 0.
0.80088 0.89953 0.90327 0.49720 0.
37.
...
0.08324 -0.17301 -0.08162 0.31971 0.54455 -0.05914 1.40048 0.
0.85080 0.71119 0.99056 0.36316 -2.
7.
0.08293 -0.17443 -0.08069 0.31889 0.54418 -0.05913 1.40053 0.
0.85083 0.71120 0.98618 0.35992 -2.
7.
  1. Now, our neural network is trained. We will use the trained neural network to make predictions on the test set test.csv and compute the test set accuracy. Accuracy is defined as the fraction of examples correctly predicted. First, using the initial weights andgiven, train your neural network. FLAG=600 has same arguments as FLAG=500. For each example in test.csv, use the trained neural network weights and print actual label, predicted label and confidence of prediction on each line. Confidence of prediction is the actual value of the activation of the output unit. Consider predicted label to be 0 when this confidence is less than or equal to 0.5, else predict 1. In the end, print the test set accuracy with 2 decimal precision.
$java NeuralNet 600 .1 .2 .3 .4 .5 .5 .6 .7 .8 .9 .9 .5 .2.
1 1 0.
0 0 0.
0 1 0.
0 0 0.
0 0 0.
...
0 0 0.
0 0 0.
0.