From 2df896a769b83e7b2ab680b4fe777090f20408b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20GALLOU=C3=89DEC?= <gallouedec.quentin@gmail.com> Date: Fri, 7 Oct 2022 14:15:52 +0200 Subject: [PATCH] replace `evaluate_mlp` by `run_mlp_training` and add `train_mlp` func --- README.md | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0ccd3fe..a7a2eb5 100644 --- a/README.md +++ b/README.md @@ -171,14 +171,42 @@ Instead of the MSE loss, we prefer to use a binary cross-entropy loss. We also w 10. Write the function `one_hot` taking a (n)-D array as parameters and returning the corresponding (n+1)-D one-hot matrix. 11. Write a function `learn_once_cross_entropy` taking the the same parameters as `learn_once_mse` and returns the same outputs. The function must use a cross entropy loss and the last layer of the network must be a softmax. We admit that $`\frac{\partial C}{\partial Z^{(2)}} = A^{(2)} - Y`$. Where $`Y`$ is a one-hot vector encoding the label. -12. Write the function `evaluate_mlp` taking as parameter: +11. Write the function `learn_once_cross_entropy` taking as parameters: + - `w1`, `b1`, `w2` and `b2` the weights and biases of the network, + - `data` a matrix of shape (`batch_size` x `d_in`), + - `labels_train` a vector of size `batch_size`, and + - `learning_rate` the learning rate, + + that perform one gradient descent step using a cross entropy loss. We alos want that the last layer of the network to be a softmax. + We admit that $`\frac{\partial C}{\partial Z^{(2)}} = A^{(2)} - Y`$. Where $`Y`$ is a one-hot vector encoding the label. + The function must return: + - `w1`, `b1`, `w2` and `b2` the updated weights and biases of the network, + - `loss` the loss, for monitoring purpose. +12. Write the function `train_mlp` taking as parameters: + - `w1`, `b1`, `w2` and `b2` the weights and biases of the network, + - `data_train` a matrix of shape (`batch_size` x `d_in`), + - `labels_train` a vector of size `batch_size`, + - `learning_rate` the learning rate, and + - `num_epoch` the number of training epoch, + + that perform `num_epoch` of training steps and returns: + - `w1`, `b1`, `w2` and `b2` the updated weights and biases of the network, + - `train_accuracies` the list of train accuracies across epochs as a list of floats. +13. Write the function `test_mlp` taking as parameters: + - `w1`, `b1`, `w2` and `b2` the weights and biases of the network, + - `data_test` a matrix of shape (`batch_size` x `d_in`), and + - `labels_test` a vector of size `batch_size`, + + testing the network on the test set and returns: + - `test_accuracy` the testing accuracy. +14. Write the function `run_mlp_training` taking as parameter: - `data_train`, `labels_train`, `data_test`, `labels_test`, the training and testing data, - `d_h` the number of neurons in the hidden layer - `learning_rate` the learning rate, and - `num_epoch` the number of training epoch, - that train an MLP classifier and return the train and (accuracy computed on the train set) and the test accuracy (accuracy computed on the test set). -13. For `split_factor=0.9`, `d_h=64`, `learning_rate=0.1` and `num_epoch=10_000`, plot the evolution of accuracies across learning epochs. Save the graph as an image named `mlp.png` in the `results` directory. + that train an MLP classifier and return the training accuracies across epochs as a list of floats and the final testing accuracy as a float. +15. For `split_factor=0.9`, `d_h=64`, `learning_rate=0.1` and `num_epoch=100`, plot the evolution of learning accuracy across learning epochs. Save the graph as an image named `mlp.png` in the `results` directory. ## To go further @@ -218,16 +246,18 @@ In this section, we present all the items on which the work is evaluated. - ( /1) The function `knn_predict` works as described - ( /1) The function `evaluate_knn` works as described - ( /1) The graph `knn.png` shows the results obtained -- ( /1.5) The function `learn_once_mse` works as described +- ( /1) The function `learn_once_mse` works as described - ( /1) The function `one_hot` works as described -- ( /1.5) The function `learn_once_cross_entropy` works as described -- ( /1) The function `evaluate_mlp` works as described +- ( /1) The function `learn_once_cross_entropy` works as described +- ( /1) The function `train_mlp` works as described +- ( /1) The function `test_mlp` works as described +- ( /1) The function `run_mlp_training` works as described - ( /1) The graph `mlp.png` shows the results obtained - ( /1) The project has a good README. - ( /2) The guidlines about the project structure are all followed -- ( /2) All functions are documented -- ( /1) All functions are documented and follow the pydocstyle -- ( /1) The code is properly formatted +- ( /1) All functions are documented +- ( /1) All functions are documented clearly and follow the PEP257 recommendations +- ( /1) The code is properly formatted, i.e. follow the PEP8 recommendations **Bonus** -- GitLab