Model Solver

Introduction

The mission of the model solver is to find the best set of parameters, that minimize the train/accuracy errors. On this chapter we will give a UML description with some piece of python/matlab code that allows you implement it yourself.

From the UML description we can infer some information about the Solver class:

  1. It uses the training set, and has a reference to your model

  2. Uses different type of optimizers(ex: SGD, ADAM, SGD with momentum)

  3. Keep tracks of all the loss, accuracy during the training phase

  4. Keep the set of parameters, that achieved best validation performance

Usage example

Train operation

This is the method called when you actually want to start a model training, the methods Step, Check_Accuracy are called inside the Train method:

  1. Calculate number of iterations per epoch, based on number of epochs, train size, and batch size

  2. Call step, for each iteration

  3. Decay the learning rate

  4. Calculate the validation accuracy

  5. Cache the best parameters based on validation accuracy

Step operation

Basically during the step operation the following operations are done:

  1. Extract a batch from the training set.

  2. Get the model loss and gradients

  3. Perform a parameter update with one of the optimizers.

Check Accuracy

This method basically is called at the end of each epoch. Basically it uses the current set of parameters, and predict the whole validation set. The objective is at the end get the accuracy. accuracy=mean(ypredicted==yvalidation)accuracy=mean(y_{predicted}==y_{validation})

Model loss operation

We mentioned during the "Step" operation that we get the model loss and gradients. This operation is implemented by the "getLoss" method. Consider the following basic model.

Bellow we have the "getLoss" function for the previous simple model.

Also bellow we have the "softmaxloss" function including "dout", $$\frac{\partial L}{\partial X{scores}}$$