1234567891011121314151617181920212223242526272829303132333435 |
- function model = learn_multiclass_gp(K, labels, noise)
- % Learn a multi-class GP model
- %
- % function model = learn_multiclass_gp(K, labels, noise)
- %
- % INPUT: K -- kernel matrix of all data points
- % labels -- multi-class labels, e.g., 1, 3, 4, 5, ...
- % noise -- variance of Gaussian noise model within GP framework
- % Copyright (c) by Alexander Freytag, 2013-11-13.
- % obtain unique class labels (length of this vector equals the number of classes)
- unique_labels = unique(labels);
- % cholesky factorization of regularized kernel matrix
- L = chol( K + noise*eye(size(K)) , 'lower');
- % store relevant data
- model.L = L;
- model.noise = noise;
- model.unique_labels = unique_labels;
- % loop over classes and thus over binary one-vs-all tasks
- for k=1:length(unique_labels)
- % binary label vector for each binary task
- current_labels = 2*(labels==unique_labels(k))-1;
- % precompute and store alpha vector for each binary task
- model.alpha{k} = L'\(L\current_labels);
- end
-
- model.y = labels;
- end
|