%
% Liscense Notification 2013
%
% Redistributions in source and binary forms, with or without
% modification, are totally FREE provided that you keep this keep this
% notification
%
% Descritption: This package demonstrates the discrete adaboost with
% stump(decision tree with only the root node) weak classifers.
% Author: Ranch Lai (ranchlai@hotmail.com)
% Release date: Aug 17, 2013
%/
%%
clc;
clear;
close all;
%% generate random data
shift =3.0;
n = 2;%2 dim
%y = 1./exp(-w'*x+b)
sigma = 1;
N = 500;
x = [randn(n,N/2)-shift, randn(n,N/2)*sigma+shift];
y = [ones(N/2,1);-ones(N/2,1)];
%show the data
figure;
plot(x(1,1:N/2),x(2,1:N/2),'rs');
hold on;
plot(x(1,1+N/2:N),x(2,1+N/2:N),'go');
title('2d training data');
legend('Positve samples','Negative samples','Location','SouthEast');
% model fitting using maximum likelihood
[model_pos,model_neg] = FindGuassianModel(x,y);
%% test on new dataset, same distribution
n = 2;%2 dim
%y = 1./exp(-w'*x+b)
sigma = 2;
N = 500;
x = [randn(n,N/2)-shift, randn(n,N/2)*sigma+shift];
y = [ones(N/2,1);-ones(N/2,1)];
figure;
plot(x(1,1:N/2),x(2,1:N/2),'rs');
hold on;
plot(x(1,1+N/2:N),x(2,1+N/2:N),'go');
title('2d testing data');
hold on;
%% gaussian model as a baseline
[err,h] = FindModelError(model_pos,model_neg,x,y);
fprintf('Baysian error on test data set: %f\n',err/N);
x_pos = x(:,h==1);
x_neg = x(:,h~=1);
plot(x_pos(1,:),x_pos(2,:),'r.');
hold on;
plot(x_neg(1,:),x_neg(2,:),'g.');
legend('Positve samples','Negative samples','Positve samples as predicted','Negative samples as predicted','Location','SouthEast');
- 1
- 2
- 3
- 4
- 5
- 6
前往页