Computational Intelligence, SS08
2 VO 442.070 + 1 RU 708.070 last updated:
Course Notes (Skriptum)
Online Tutorials
Practical Course Slides
Animated Algorithms
Interactive Tests
Key Definitions
Literature and Links

Homework 2: Neural Networks

[Points: 12.5; Issued: 2008/03/20; Deadline: 2008/05/16; Tutor: Robert Peharz; Infohour: 2008/05/09, 15:30-16:30, HS i11; Einsichtnahme: 2008/05/30, 15:30-16:30, HS i11; Download: pdf; ps.gz]

Simple Regression with Neural Networks[4 points]

In this task a simple 1-dimensional function should be learned with feed-forward neural networks. Use the same data set as for homework 1.
  • Train a neural network with $ n = [1, 2, 3, 4, 6, 8]$ neurons. Use the training algorithm 'trainscg', train for $ 700$ epochs.
  • Plot the mean squared error of the training and of the test set for the given number of neurons. For the test set, plot the mean squared error (mse) after training ( $ tmse_{end}$) and the minimum mse during training ( $ tmse_{min}$).
  • Interpret your results. Why is there a difference between $ tmse_{end}$ and $ tmse_{min}$ ? What is the best value of $ n$?
  • Plot the learned functions for $ n = 1$, $ n = 2$ and $ n = 10$. Interpret your results, refer to results from the previous plots!
  • Compare the results to homework 1. Is there any connection of $ n$ and $ \alpha$ ? [2 Extra-Points]


  • Normalize your input data using mapstd (in older Matlab versions (< 7.5) this function is called prestd)
  • You can easily use the performance structure returned by the train function to get the error on the training and on the test set.

Face Recognition with Neural Networks [8.5 points]

In this task you are ask to work with the dataset faces.mat which contains face images. The dataset contains images of different persons, with different pose (straight/left/right/up), with/without sunglasses and showing different emotions. Download the matlab dataset. It contains 2 datasets: dataset1 (input1, target1) with 60 data points and dataset2 (input2, target2) with 564 data points. The target matrices contain the class informations. The first column codes the person, the second column the pose, the third column the emotion and the last column indicates wether the person is wearing sunglasses. In template_faces.m you can find a script for training a sunglasses recognizer. This script can be used as template. Additionally you need to download the file confmat.m which is needed to calculate the confusion matrix.

Pose Recognition

  • Train a 2 layer feed-forward neural network ith 6 hidden units for pose recognition. Use dataset2 for training, trainscg as training algorithm and train for $ 300$ epochs. Do not use any test set.
  • State the confusion matrix on the training set. Are there any poses which can be better separated than others?
  • Plot the weights of the hidden layer for every hidden unit. Can you find particular regions of the images which get more weights than others? Do particular units seem to be tuned to particular features of some sort?

Face Recognition

  • Train 2 layer feed-forward neural network with 20 hidden units for recognizing the individuals. Use dataset1 for training, trainscg as training algorithm and train for $ 1000$ epochs. Use dataset2 as test set.
  • Repeat the process 10 times starting from a different initial weight vector. Plot the histogram for the resulting mean squared error (mse) on the training and on the test set.
  • Interpret your results! Explain the variance in the results.
  • Use the best network (with minimal mse on the test set) to calculate the confusion matrix for the test set and the mean classification error (not the mse !) on the test set. Plot a few missclassified images. Do they have anything in common?


  • Normalize your input data using mapstd (in older Matlab versions (< 7.5) this function is called prestd)
  • In the template script you can find code for plotting an image and plotting the weights of a hidden neuron
  • Be aware that the template script only covers the 2 class classification case !
  • Use the functions full and ind2vec to get from the standard class coding to a 1 out of n coding.


  • Hand-in your matlab code as print-outs (no emails !!).
  • Present your results clearly, structured and legible. Document them in such a way that anybody can reproduce them effortless.
  • Use your matrikel number to initialize the state of the random number generators.