Robot Learning
Winter Semester 2011/12, Homework 2
Prof. Dr. J. Peters, M.Eng. O. Kroemer
Aufgabe 2.1 Bayesian Decision Theory [ 30 Points]
a) Deriving Logistic Regression [ 10 Points]
1. Starting with the equality p(C = 1, x) = p(x, C = 1), derive Bayes rule for p(C = 1|x). The variable
C ∈ {0, 1} represents the class label of data points x ∈ Rd .
2. Starting with the solution to the previous question, show that Bayes rule can be rewritten in the logistic
sigmoid form p(C = 1|x) = (1 + exp (a(x)))−1 . Write out the function a(x).
3. Given equal costs for all classification errors, what condition is fulfilled at the decision boundary of a two
class decision problem?
1
Robot Learning - Homework 2
Name, Vorname:
Matrikelnummer:
4. Assume that the class-conditional distributions are given by p(x|C = 1) = N (x|µ1 , Σ1 ) and p(x|C = 0) =
N (x|µ0 , Σ0 ), and the classes’ priors are equivalent p(C = 0) = p(C = 1). Show that the decision boundary
can be written in the quadratic form xT Ax + bT x + c = 0, and write down the values of A, b, and c.
5. Under which condition does the boundary between two Gaussians become a hyper-plane?
b) Bayesian Classifier[ 20 Points]
In this problem, you will be classifiying the “Iris” dataset from the UCI Machine Learning Repository. The original
data describes 3 classes of Iris flowers and contains various measurements about them: 1. sepal length in cm 2.
sepal width in cm 3. petal length in cm 4. petal width in cm. To make things a little easier, we left out one of the
flower types and only included the “Iris Setosa” (class 0) and “Iris Versicolor” (class 1). There are two data files for
this assignment, a training data set (70 data items) and a test data set (30 data items). The training and testing
datasets can be found at
http://www.ias.informatik.tu-darmstadt.de/uploads/Teaching/MachineLearning1Lecture/Iris_train.dat
and
http://www.ias.informatik.tu-darmstadt.de/uploads/Teaching/MachineLearning1Lecture/Iris_test.dat
Every line in each file describes one data item; the 5 numbers in each row contain the 4 measurements in above
order plus the class label. Use only the second measurement (sepal width) for classification and ignore all others.
1. Load the training data. Compute a feature histogram for each class (see histc and bar in Matlab), using edges
between the bins at 0.2 intervals between 1 and 5; i.e. 1 : 0.2 : 5. Show the histograms either in two figures
using subplot in Matlab, and make sure both plots have the same x-axis range.
2
Robot Learning - Homework 2
Name, Vorname:
Matrikelnummer:
2. Estimate the class priors from the training data. Report the prior probabilities of a flower being an “Iris
Setosa” or being an “Iris Versicolor”.
3. Assume that we can model the class-conditional probability density of each class using a univariate Gaussian
(remember to only use the sepal width). Estimate the class-conditional distributions for both classes using
maximum likelihood. What are the mean and variance of both class-conditional densities?
4. Plot the estimated class-conditional densities in a single diagram. Make a second figure plotting the class
posteriors for both classes. Write down the equation you used to compute the class posteriors.
5. Compute the Bayes classification of the training data. How many “Setosas” do you mistakenly classify as
“Versicolor” and how many “Versicolors” do you mistakenly classify as “Setosa”? What is the overall training
error (i.e. percentage of incorrectly classified training data items)?
6. Now classify the test data. How many “Setosas” do you mistakenly classify as “Versicolor” and how many
“Versicolors” do you mistakenly classify as “Setosa”? Report the number of cases that are incorrectly classified
as above as well as the test error.
3
Robot Learning - Homework 2
Name, Vorname:
Matrikelnummer:
Aufgabe 2.2 Kernel Density Estimation [ 10 Points]
The one dimenstional data for this problem can be found at
http://www.ias.informatik.tu-darmstadt.de/uploads/Teaching/MachineLearning1Lecture/densedata.dat
Create graphs of the density estimates using the methods listed below. Plot the data in the range from 0 to 1 at 0.001
intervals; i.e. x = 0 : 0.001 : 1. Plot the data for both hyperparameter settings of each method on the same graph, in
different colors, such that you have three graphs in total. Hand in a copy of your code together with the plots.
a) Parzen Window [ 3 Points]
1. h = 0.0375
2. h = 0.075
b) K-nearest neighbours [ 3 Points]
1. K = 15
2. K = 30
c) Gaussian Kernel Density Estimate [ 4 Points]
1. σ = 0.03
2. σ = 0.06
Aufgabe 2.3 Mixture Density Estimation [ 30 Points]
Re-use the data from Question 2, i.e., from
http://www.ias.informatik.tu-darmstadt.de/uploads/Teaching/MachineLearning1Lecture/densedata.dat
and additionally download the file
http://www.ias.informatik.tu-darmstadt.de/uploads/Teaching/MachineLearning1Lecture/mmdens.m
as a rough sketch of a computer program for mixture density modeling. If you use this Matlab example, make sure to use
sum, mean, var, repmat, and ./ instead of loops. Study function emdens in detail, check especially all the points where
there are „????“. Follow the instructions below.
a) Initialize the mixture model.
1. Use uniform prior probilities for each cluster.
2. Initialize the variance of the clusters with the variance of the data divided by the squared number of mixture.
3. Place the centers randomly around the mean of the data (with the variance of the data).
b) The E-step: calculate the posterior probabilities p(j|x). Use repmat where needed!
c) The M-step: calculate the parameter updates.
1. Update the prior.
2. Update the variance.
3. Update the mean.
4
Robot Learning - Homework 2
Name, Vorname:
Matrikelnummer:
d) Run the program with different numbers of mixture components.
1. Describe the difference which the number of mixture components make.
2. Find the optimal number of components.
3. Create a plot of the mixtures for this optimal number of components. Attach the plot to your homework.
4. Find a case where the number of components breaks the algorithm.
Attach your program listing. Note: 15 points extra credit will be given to all students who implement the program
in any language but Matlab (or clones like Octaves). We recommended: SciPy. The code has to be sent to the TA
by email for the non-MATLAB solutions.
5
© Copyright 2026 Paperzz