⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threshold_tr.m

📁 boost算法
💻 M
字号:
function model = threshold_tr(train_set, sample_weights, labels)%% TRAINING THRESHOLD CLASSIFIER%%	Training of the basic linear classifier where seperation hyperplane%	is perpedicular to one dimension.%%	model = threshold_tr(train_set, sample_weights, labels)%		train_set: an NxD-matrix, each row is a training sample in the D dimensional feature%           space.%       sample_weights: an Nx1-vector, each entry is the weight of the corresponding training sample%       labels: Nx1 dimensional vector, each entry is the corresponding label (either 1 or 2)%%       model: the ouput model. It consists of%           1) min_error: training error%           2) min_error_thr: threshold value%           3) pos_neg: whether up-direction shows the positive region (label:2, 'pos') or%               the negative region (label:1, 'neg')%% Bug Reporting: Please contact the author for bug reporting and comments.%% Cuneyt Mertayak% email: cuneyt.mertayak@gmail.com% version: 1.0% date: 21/05/2007model = struct('min_error',[],'min_error_thr',[],'pos_neg',[],'dim',[]);sample_n = size(train_set,1);min_error = sum(sample_weights);min_error_thr = 0;pos_neg = 'pos';% for each dimensionfor dim=1:size(train_set,2)	sorted = sort(train_set(:,dim),1,'ascend');	% for each interval in the specified dimension	for i=1:(sample_n+1)        if(i==1)            thr = sorted(1)-0.5;        elseif(i==sample_n+1)            thr = sorted(sample_n)+0.5;        else    		thr = (sorted(i-1)+sorted(i))/2;        end        		ind1 = train_set(:,dim) < thr;		ind2 = ~ind1;		tmp_err = sum(sample_weights((labels.*ind1)==2)) + sum(sample_weights((labels.*ind2)==1));		if(tmp_err < min_error)			min_error = tmp_err;			min_error_thr = thr;			pos_neg = 'pos';			model.dim = dim;		end		ind1 = train_set(:,dim) < thr;        ind2 = ~ind1;        tmp_err = sum(sample_weights((labels.*ind1)==1)) + sum(sample_weights((labels.*ind2)==2));		if(tmp_err < min_error)            min_error = tmp_err;            min_error_thr = thr;            pos_neg = 'neg';			model.dim = dim;        end	endendmodel.min_error = min_error;model.min_error_thr = min_error_thr;model.pos_neg = pos_neg;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -