Overview: In this lab you will be completing the building of pieces of your own neural network. You are not allowed to use any neural network or machine learning libraries to implement this. Use vectorization with numpy instead. The learning outcome for this lab is being able to use numerical differentiation to train a neural network. This is a partner lab.
You may find it helpful to watch the following video series to supplement your understanding of training neural networks, but these are based on symbolic differentiation rather than numeric differentiation:
Implement the # FIXME week 7 items in your solution to the week 6 lab. If you did not complete the week 6 lab, talk to your instructor. One of the updates will be to replace the current, hard-coded initial sets of weights and biases by code to generate these using random values. When you are finished, the neural network should work for any dimension inputs and any number of nodes in the single hidden layer (layer 2).
The following input files contain training data for your neural network:
The “Full” file has additional valid game configurations.
The first step is to implement the training algorithm and confirm it works by
monitoring the lost function. Use the numerical differentiation
method described in class to update the network in
update_weights
. That is, increase and decrease each weight by a
small, fixed amount (such as 0.1) and use feed_forward
to
determine if that reduces or increases loss (or makes no significant
difference). This gives you a matrix of deltas; multiply them by the learning
rate and add them to create a new set of weights. Over a number of epochs, the
loss should decrease and the accuracy should improve. You are expected to plot
the loss function using MatPlotLib to demonstrate that your loss decreases.
You are provided this test file so you can test your code: test_nn.py
. This file is not intended to be a comprehensive set of tests, but it should get you going in the right direction. If you aren’t sure why your code isn’t passing a test, feel free to ask the instructor since some of the thresholds are sensitive to implementation details.
Additionally, you are expected to implement a train/test split mechanism
for this lab. You should run experiments to see the accuracy differences
between using a train/test split of 80/20 and 100/0. You should find/choose
hyperparameters that show a difference and document the accuracy
differences between splitting and not for the various data sets. Note you
can use
numpy.random.Generator.shuffle
shuffle your data and then use that to generate your splits.
Write a report containing the following:
tic-tac-toeFull.csv
; use Snip & Sketch or a similar tool to capture the relevant part of the screen. This should include the split of training vs. test data, a MatPLotLib output showing the reduction in loss, and the evaluation of the neural network against the test data.Convert the report to PDF and upload it and nn.py file to Canvas for grading. Be sure your nn.py file meets your instructor’s standards!