Search
At the very beginning of the recognition labs, we assumed the conditioned measurement probabilities $p_{X|k}(x|k)$ and the a priori probabilities $P_K(k)$ to be known and we used them to find the optimal Bayesian strategy. Later, we looked at problems where the a priori probability is not known or does not exist and we constructed the optimal minimax strategy. Today, we face the problem of unknown probability density function $p_{X|k}(x|k)$ and we will be interested in its estimation.
Lets assume in this lab that we know the density function is from a class of functions parametrised by unknown parameters. In our case, the known model is going to be Normal distribution and all we do not know are its parameters - mean and standard deviation. To estimate the parameters we will use so called training examples (training set) - a set of examples drawn randomly from some existing but unknown distribution.
The assignment has two parts. In the first one we will explore the importance of the sufficient training set size. We will see what happens if we do not have enough training examples for the estimate. In the second part, we will continue with the letter classification task and we will train a Bayes classifier using training sets of different sizes and we will focus on maximising the likelihood function.
To fulfil this assignment, you need to submit these files (all packed in a single .zip file) into the upload system:
.zip
answers.txt
assignment_04.m
mle_normal.m
mle_variance.m
estimate_prior.m
loglikelihood_sigma.m
mle_variances.png
loglikelihood20.png
loglikelihood200.png
loglikelihood2000.png
mle_estimatesA.png
mle_estimatesC.png
mle_classif20.png
mle_classif200.png
mle_classif2000.png
Start by downloading the template of the assignment.
Experimental. Use at your own risk.
Standard is to use Matlab. You may skip this info box if you follow the standard rules.
General information for Python development.
mle.ipynb
mle.py
mle_normal
mle_variance
estimate_prior
loglikelihood_sigma
Use template of the assignment. When preparing the archive file for the upload system, do not include any directories, the files have to be in the archive file root.
First we use a synthetic experiment to demonstrate the effect of the training set size on the parameter estimate. We will generate random training sets of different sizes from the normal distribution (using randn function) and for each set we do the maximum likelihood estimate of mean and standard deviation parameters. For each training set size we will repeat the estimate 100x and we will measure the “stability” of the estimate by variance over these 100 estimates.
randn
Do the following:
[mu sigma] = mle_normal(x)
mean
std
var
x = [0 1 2 3 4 5 6 7 8 9 10]; [mu sigma] = mle_normal(x) mu = 5 sigma = 3.1623
[var_mean var_sigma] = mle_variance(cardinality)
We will keep on solving the letters classification task. However, in contrast to the previous labs, both, the a priori probabilities $p_{K}(k)$ and the conditional probability density functions $p_{Xk}(x|k)$ are unknown. We have a set of training images from which the probabilities can be estimated and test examples (test set) to verify our estimate.
To estimate $p_{X|k}(x|k)$ we assume that a normal distribution fits the data, $p_{X|k}(x|k) \sim N(\mu_k, \sigma_k)$, and we compute its parameters $\mu_k$, $\sigma_k$ with the maximum likelihood criteria. Here, the $k$ is the class label - the letter we consider. The a priori probability of each class can be simply estimated by taking the fraction of the training images belonging to this class.
Having estimated the a priori probabilities and the conditional probability density functions we can use the Bayesian classifier to solve the problem.
The performance of the classifier will be measured with the classification error using a different set of pre-labelled images called test set, which was not used in the training stage. We will work with three different training sets of images (20, 200 and 2000 images) so we can experiment with the performance of the classifier, i.e. observing the classification error, when the set size changes.
As before, the following simple measurement will be used during the task:
x = (sum of pixel values in the left half of image) -(sum of pixel values in the right half of image)
x = compute_measurement_lr_discrete(imgs)
data_33rpz_cv04.mat
trn_20
trn_200
trn_2000
prior = estimate_prior(idLabel, labelling)
labelling = [1 1 1 0 0 0 0 0 0]; prior = estimate_prior(1, labelling) prior = 0.3333
[L maximizerSigma maxL] = loglikelihood_sigma(x, D, sigmas)
L
x_maximizer = fminbnd(@(x) -some_function(other_param1, other_param2, x), 0, 1)
exp(-x^2/2)
0
x
x=40
log
-Inf
-x^2/2
sigmas = 300:50:3500; x = compute_measurement_lr_cont(trn_2000.images); D.Mean = -2000; [L maximizerSigma maxL] = loglikelihood_sigma(x, D, sigmas); maximizerSigma = 2.1247e+03 maxL = -1.6345e+04
loglikelihoodXXX.png
mle_classifXXX.png
Fill the correct answers to your answers.txt file.
question2 : [1.001, 2.002, 3.003]
Implement ML estimation of a bivariate normal distribution.
cov
tst
pgauss
ppatterns