CSE 4311 - Assignments - Assignment 4

List of assignment due dates.

The assignment should be submitted via Canvas. Submit a file called assignment4.zip, containing the following files: These naming conventions are mandatory, non-adherence to these specifications can incur a penalty of up to 20 points.

Your name and UTA ID number should appear on the top line of both documents.

For all programming tasks, feel free to reuse, adapt, or modify, any code that is posted on the slides or the class website.


Task 1 (40 points, programming)

File nn_keras_base.py contains incomplete code that implements, using Keras, the training and evaluation process for a dense neural network that works on UCI datasets. To complete the code, you must create a file called nn_keras_solution.py, where you implement the following Python functions:
model = create_and_train_model(training_inputs, training_labels, layers, units_per_layer, epochs, hidden_activations)

test_accuracy = test_model(model, test_inputs, test_labels, ints_to_labels)
Function create_and_train_model creates and trains a model using the parameter values specified in the arguments. It returns the model that it has trained. These are the specifications for create_and_train_model: Function test_model evaluates the trained model on the test set. These are the specifications: The training and test files will follow the same format as the text files in the UCI datasets directory and the synthetic directory, that you are familiar with from Assignment 3. Function read_uci_file in uci_load.py handles reading these files and extracting the appropriate vectors and class labels. A description of the datasets and the file format can be found on this link. Your code should also work with ANY OTHER training and test files using the same format.

Training

In your implementation, you should use these guidelines: There is no need to output anything for the training phase. It is OK if Keras prints out various things per epoch.

Testing

For each test object, your test_model function should print a line containing the following info: To produce this output in Python in a uniform manner, use:
print('ID=%5d, predicted=%10s, true=%10s, accuracy=%4.2f' % 
           (test_index, predicted_class, actual_class, accuracy))
After you have printed the results for all test objects, you should print the overall classification accuracy, which is defined as the average of the classification accuracies you printed out for each test object. To print the classification accuracy in a uniform manner, use:
print('Classification accuracy on test set: %.2f%%' % (test_accuracy * 100))

In your answers.pdf document, please provide ONLY THE LAST LINE (the line printing the classification accuracy) of the output by the test stage, for the following test cases:

Expected Classification Accuracy

You may get different classification accuracies when you run your code multiple times with the same input arguments. This is due to the fact that weights are initialized randomly. These are some results I got with my implementation:

Task 1b (Optional, extra credit, maximum 10 points).

A maximum of 10 extra credit points will be given to the submission or submissions that identify the function arguments achieving the best test accuracy for any of the three UCI datasets (pendigits, yeast, satellite). These function arguments, and the attained accuracy, should be reported in answers.pdf, under a clear "Task 1b" heading. These results should be achievable using the code that you submit for Task 1. You should achieve the reported accuracy at least five out of 10 times when you run your code.


Task 1c (Optional, extra credit, maximum 10 points).

In this task, you are free to change any implementation options that you are not free to change in Task 1. Examples of such options include different optimizers and settings for those optimizers, different types of layers, different batch sizes, etc. You can submit a solution called nn_keras_opt.py, that implements your modifications. A maximum of 10 points will be given to the submission or submissions that, according to the instructor and GTA, achieve the best improvements on any of the three UCI datasets (pendigits, yeast, satellite), compared to the specifications in Task 1. In your answers.pdf document, under a clear "Task 1c" heading, explain:


Task 2 (30 points, programming)

This task is identical to the previous task, except that the model will be trained and tested on the MNIST dataset. File dense_mnist_base.py contains incomplete code that implements, using Keras, the training and evaluation process for a dense neural network that works on the MNIST dataset. To complete the code, you must create a file called dense_mnist_solution.py, where you implement the following Python functions:
(training_inputs, training_labels, test_inputs, test_labels) = load_mnist()

model = create_and_train_model(training_inputs, training_labels, layers, units_per_layer, epochs, hidden_activations)
Function load_mnist loads the MNIST dataset. It does not take any arguments. It returns training inputs, training labels, test inputs, test labels, which have the same meaning as in the previous task. It is the responsibility of this function to make sure that the return values comply with the following requirements: Function create_and_train_model has mostly the same specifications as in the previous task. The only exception that here it is up to you to decide whether training_inputs and test_inputs should be two-dimensional arrays or have a different shape. Depending on exactly how you implement this function for the previous task, and how you implement load_mnist for this task, the create_and_train_model implementation from the previous task may or may not work here. It is up to you to decide if you can reuse the implementation from the previous task, or if you need to make modifications.

There is no need to output anything for the training phase. It is OK if Keras prints out various things per epoch.

Unlike the previous task, you do not have to write a function that prints a line showing the result for each test object.

At the end, the code should print the overall classification accuracy on the test set. The last two lines in dense_mnist_base.py take care of that, so you do not need to do anything more to satisfy this requirement.

In your answers.pdf document, please provide ONLY THE LAST LINE (the line printing the classification accuracy) of the output by the test stage, for the following test case:

You may get different classification accuracies when you run your code multiple times with the same input arguments. This is due to the fact that weights are initialized randomly. I ran my solution 5 times for the test case described above. The classification accuracy on the test set was between 97.40% and 98.08%. On my computer, the training process took about 4 minutes and the test process took about 2 seconds. Note that the test process can be much faster here compared to the previous task, because here we do not print out information for each individual test object.


Task 2b (Optional, extra credit, maximum 10 points).

A maximum of 10 extra credit points will be given to the submission or submissions that identify the function arguments achieving the best test accuracy. These function arguments, and the attained accuracy, should be reported in answers.pdf, under a clear "Task 2b" heading. These results should be achievable using the code you submit for Task 2. You should achieve the reported accuracy at least five out of 10 times when you run your code.


Task 2c (Optional, extra credit, maximum 10 points).

In this task, you are free to change any implementation options that you are not free to change in Task 2. Examples of such options include different optimizers and settings for those optimizers, different types of layers, different batch sizes, etc. You can submit a solution called dense_mnist_opt.py, that implements your modifications. A maximum of 10 points will be given to the submission or submissions that, according to the instructor and GTA, achieve the best improvements compared to the specifications in Task 2. In your answers.pdf document, under a clear "Task 2c" heading, explain:


Task 3 (30 points, programming)

This task is similar to the previous task, except here you will use a convolutional neural network (CNN). File cnn_mnist_base.py contains incomplete code that implements, using Keras, the training and evaluation process for a CNN that works on the MNIST dataset. To complete the code, you must create a file called cnn_mnist_base.py, where you implement the following Python functions:
(training_inputs, training_labels, test_inputs, test_labels) = load_mnist()

model = create_and_train_model(training_inputs, training_labels, blocks, 
                               filter_size, filter_number, region_size, 
                               epochs, cnn_activation)
Function load_mnist has the same specifications as in the previous task. Note that, depending on exactly how you implement this function for the previous task, and how you implement create_and_train_model for this task, the load_mnist implementation from the previous task may or may not work here. It is up to you to decide if you can reuse the implementation from the previous task, or if you need to make modifications.

These are the specifications for create_and_train_model:

There is no need to output anything for the training phase. It is OK if Keras prints out various things per epoch.

As in Task 2, you do not have to write a function that prints a line showing the result for each test object. At the end, the code should print the overall classification accuracy on the test set. The last two lines in cnn_mnist_base.py take care of that, so you do not need to do anything more to satisfy this requirement.

In your answers.pdf document, please provide ONLY THE LAST LINE (the line printing the classification accuracy) of the output by the test stage, for the following test case:

You may get different classification accuracies when you run your code multiple times with the same input arguments. This is due to the fact that weights are initialized randomly. I ran my solution 5 times for the test case described above. The classification accuracy on the test set was between 98.71% and 98.94%. On my computer, the training process took about 6 minutes and the test process took about 6 seconds.


Task 3b (Optional, extra credit, maximum 10 points).

A maximum of 10 extra credit points will be given to the submission or submissions that identify the function arguments achieving the best test accuracy. These function arguments, and the attained accuracy, should be reported in answers.pdf, under a clear "Task 3b" heading. These results should be achievable by calling the code you submit for Task 3. You should achieve the reported accuracy at least five out of 10 times when you run your code.


Task 3c (Optional, extra credit, maximum 10 points).

In this task, you are free to change any implementation options that you are not free to change in Task 3. Examples of such options include different optimizers and settings for those optimizers, different types of layers, different batch sizes, etc. You can submit a solution called cnn_mnist_opt.py, that implements your modifications. A maximum of 10 points will be given to the submission or submissions that, according to the instructor and GTA, achieve the best improvements compared to the specifications in Task 3. In your answers.pdf document, under a clear "Task 3c" heading, explain:


Task 4 (Optional, extra credit, maximum 10 points).

Design your own dataset, that satisfies the following requirements:
  1. The dataset is computer-generated, using some randomized process. You should submit the code (in any language that you like) that generates the data.
  2. Every input is two-dimensional.
  3. The dataset has at least 200 training objects, and at least 200 test objects.
  4. There are two classes, half the training objects belong to each class, and half the test objects also belong to each class.
  5. In the training set, the standard deviation for each class, along each dimension, is at least 2.
  6. In the training set, the euclidean distance of the means of the two classes is at most 1.
  7. In the test set, the standard deviation for each class, along each dimension, is at least 2.
  8. In the test set, the euclidean distance of the means of the two classes is at most 1.
  9. For each class, the euclidean distance between the mean of the training objects belonging to that class and the mean of the test objects belonging to that class is at least 2.
  10. A 4-layer neural network (that is, with two hidden layers) achieves 100% accuracy on the test set. Your solution for Task 1 should be sufficient for achieving the accuracy. In your answers.pdf file, you can specify the parameters that your network uses.
You should submit the training and test files, formatted the same way as the data sets for Task 1. You should also submit the code (in any language that you like) that was used to generate the dataset. In answers.pdf, specify the file or files where the code and data are stored.


CSE 4311 - Assignments - Assignment 4