Revision 444e5a3daf141740f8beedb68560a6eaf9c0fd3f (click the page title to view the current version)

Neural Networks

Changes from 444e5a3daf141740f8beedb68560a6eaf9c0fd3f to current

title: Neural Networks
categories: session

This page is intended for two session; i.e. one week.

+ [Briefing 10 November](ANN) - Principles of training and testing
+ [Briefing 11 November](CNN) - Convolutional Networks - what are they?

# Reading

+ [PyTorch Quickstart](
    + the quickstart tutorial is part of [Learn the Basics](
+ [Learn the Basics](
    + see also the tutorial under Exercise 1. below
+ Szeliski 2022 Chapter 5


# Exercise 1. Basic tutorial.

I have added a couple of exercises to the official
[PyTorch Quickstart](

+ Download and open the (augmented) [tutorial](ann-tutorial.ipynb).
+ Download and open the (augmented) [tutorial](Python/ann-tutorial.ipynb).
+ Please reflect upon and discuss the questions.

# Exercise 3. Regression.

One in-house project is to classify images of remote galaxies,
which are often distorted due to the gravity of dark matter.
This effect is known as gravitational lensing.
# Exercise 2. Convolutional Neural Networks

A sample dataset can be found at
This directory contains
1. Complete the [CIFAR-10 Tutorial](
2. Compare the approach to Exercise 1.  What is different?
   What is the same?
# Exercise 3. Evaluation and Analysis

+ A data file, `sphere-pm.csv` 
+ 10000 images of distorted galaxies
+ A python file `` defining a subclass of `Dataset`
  to manage these data
1.  Copy the code out of the tutorials so that you can run it
    in your regular environment (IDE, command line, etc.).
2.  Test one of the networks with different numbers of epochs.
    Record the accuracy both on the training set and on the testing
    set for each epoch.
3.  Plot the training and testing accuracy as a function of the number
    of epochs.  What do you see?
4.  What is the ideal number of epochs?
5.  Calculate a confidence interval for the accuracy at the ideal
    number of epochs.  What do you think of the quality of the network?
    What do you think about the quality of the assessment of the network?

The CSV file has the form
The interesting columns are the filename which points to the
input image,  and
the four output variables $x$, $y$, `einsteinR`, and $\sigma$.
The other columns are associated with more advanced problem instances
and should be ignored.
Note that you do not have to rerun the entire process for more epochs.
You can test the network after each epoch and continue training. 

1.  Study the Dataset class ``.  How is the dataset managed?
2.  Use this class to test if you can train a network to determine the
    four outputs for an image.
If you do not see the effect of *overtraining*, try to use smaller training sets and see how it changes the behaviour of the network.

# Exercise 4.  Managing Data.
# Exercise 4.  Different networks (optional)

Doing a tutorial is good, but it is little use if you 
you can only use the sample data.
The goal of this exercise is to learn to manage other
Try to change the neural network in Exercise 1 and 2.
Can you improve the performance?

Please be aware that deep learning is usually extremely compute
intensive, and you can easily run into a problem which takes days
to compute.  The immediate solution to this is to
# Exercise 5.  More examples (optional)

Download another dataset, for instance from 
Other datases may be found at 
[this collection]( 
and try to solve the classification problem.
if you want to try other variants.