This is the second homework assignment. Your goal in this assignment is to write a function that implements a simple artificial neural network.
Practical information#
The assignment is due on Sunday of semester week 3, the 10th of March, at 11:55pm (Canberra time). To submit your solution, upload a single python file via wattle. Here is the assignment submission link.
NOTE: No excuses about technical problems like internet connection or computer issues are accepted. You can actually submit the homework as many times as you like, as the last submitted file will be marked. Do not wait until the last minute!
The homework is individual. You must write your own solution, and you are expected to be able to explain every aspect of it. You are not allowed to share your solution (code) with other students; this includes posting it (or parts of it) to the discussion forum, or to any other on-line forum. You may be contacted for an additional oral assessement, which may result in a change of mark.
If you have questions?
- Ask the tutor in your lab,
- Look at the Wattle discussion forum for similar question, and only post your question if not found,
- Go to drop-in sessions.
The problem#
Given the following neural network with three neurons:
Your task is to write a function neural_network
that takes 12
parameters in the following order:
- \(x1, x2, x3\): the three input values of the input layer,
- \(w1, w2, w3, w4, w5, w6\): the weights of various arrows (or edges) of the network,
- \(b1, b2, b3\): the bias values of the neurons.
You can assume that all these parameters are floating-point numbers (of type
float
). This function should return a single value of the output layer.
The \(\Sigma\) symbol at the neurons denotes a summation.
The ReLU activation function is defined as: \(\textrm{ReLU}(x) = \textrm{max}(0, x)\), meaning
that it returns zero if x
is negative; otherwise it just returns x
.
This is currently one of the most commonly used activation functions in machine
learning.
The sigmoid (or logistic) function was discussed in the lecture and is defined as: \(\textrm{sigmoid}(x) = 1/(1+\textrm{exp}(-x))\).
The function must take exactly 12 parameters, and return a floating-point number.
We provide you with a skeleton code file: neural_network.py.
Download this file and write in it your implementation of the function.
The function neural_network
in this file has a pass
statement,
which you should replace it with your own code.
The other is a testing function that you can (and should!) use to test if your function is working correctly.
With this homework we encourage you to think about functional decomposition. That means, how would you break the problem into smaller problems, for example, by defining a new function and reusing it several times, instead of writing code in a single function?
Testing#
The skeleton file has a testing function that you must not modify:
test_neural_network()
This function runs a number of tests of your function, and produces an error message if any of the tests fail. If all tests are ok, it will print the message “all tests passed”.
Note that this testing function only test a limited number of test cases. Passing all the tests does not necessarily means that your code is correct. But failing at least one test case means that your code is wrong.
Marking#
What to submit
You should edit the skeleton file neural_network.py
that you downloaded,
then upload only this file with your solution using the
assignment submission link on wattle.
The file that you submit must meet the following requirements:
- It must be syntatically correct python code.
- Like the file you downloaded, it must contain only function definitions; comments, including docstrings (if they are used appropriately) are of course ok to include. Anything that is not a function definition will be ignored when we check your submission.
- You should not modify the testing functions.
In marking this assignment we will consider the following:
- Did you put your name and uID at the top of the file?
- Does your submitted file satisfy the requirements specified above?
- Does your implementation of the
neural_network
function computes the correct value for all argument values?
The assignment is worth 3% of your final mark.