Skip to content

Testing document

irenenikk edited this page May 7, 2018 · 8 revisions

About testing

You can run the tests in PyCharm, or by running pytest in the root of the project folder.

The project is practically a Pytorch copy not only due to the lack of imagination by the creator, but also because this makes testing it so much easier.

There are some unit tests for the functions and layers, but the most valuable tests are definitely the "integration tests" in test_net. There you can also see how similiar the APIs between Neurose and Pytorch are.

What was tested

Well, almost everything. I decided not to test some raisings of ValueErrors (which need to be there since it's supposed to be a usable library after all), since I would have done that just to amp up the line coverage to 100% everywhere.

Usually, the output of a neural network varies between passes, because the weights are initialized randomly. However, once the weights are fixed, forward and backward passes are deterministic operations, since they're just a bunch of matrix multiplication and derivatives. They are both tested in test_net.

First, equal networks are created with Neurose and Pytorch, and then a forward pass is run and the respective outputs compared. In backpropagation, the gradients used in weight update, as well as the updated weights and biases are compared to those of Pytorch. Backpropagation also tests the derivatives of the activation and loss functions, which I wasn't able to test any other way.

The tests are done in two parts: with networks without activations, and then with networks using ReLu, Sigmoid and Softmax. This is mostly because I only found a bug in my backpropagation by adding activations to the networks, and so I decieded to separate the two cases in different tests. Softmax is tested with CrossEntropy as the loss function, others with Mean Squared error. This way all activation and loss functions are tested. Technically it would have been clearer to test the activation and loss functions separately, but that would have required building separate networks for each case, so I decided to combine the networks a bit.

I have learned to value tests during this project: already twice have I found a bug in the library, which would have been impossible to find without being able to compare the result to Pytorch.