% Inference example for logistic regression using glm-ie demonstrating the
% sparsity occuring in estimation but similar classification performance in
% inference where probabilities can readily be evaluated.
%
% We use the well known a9a dataset from the UCI machine learning repository
% with 32561 instances of dimension 123.
% B data matrix
% c binary labels
%
% (c) by Hannes Nickisch, Philips Research, 2013 August 30
clear all, close all
potS = @potLaplace; % Laplace weight prior
% load and split into train and test set
load classify % load a part of the UCI a9a dataset
nte = 30000; % say how many test examples we wich to keep
Bte = B(1:nte,:); B = B(nte+1:end,:); cte = c(1:nte); c = c(nte+1:end); % split
[q,n] = size(B);
% nearest neighbour classification
dp = sum(bsxfun(@minus, Bte, full(mean(B(c==+1,:)))).^2,2); % dist. to pos. ctr
dm = sum(bsxfun(@minus, Bte, full(mean(B(c==-1,:)))).^2,2); % dist. to neg. ctr
cc = 2*double(dp