[Home]


LUHC

A Demo Matlab code for Laplacian Unit-Hyperplane Learning for PU problem. (You could Right-Click [Code], and Save, then you can download the whole matlab code.)


Reference

Yuan-Hai Shao, Wei-Jie Chen, Nai-Yang Deng*. Laplacian unit-hyperplane learning from positive and unlabeled examples[J]. Submitted.


Main Function

Need kernel function and laplacian function.

function [PredictY Times] = LUHL(TestX,Data,FunPara) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % LUHL: Laplacian Unit-Hyperplane Learning for PU problem % % Predict_Y = LUHL(TestX,DataTrain,FunPara) % % Input: % TestX - Test Data matrix. % Each row vector of fea is a data point. % % DataTrain - Struct value in Matlab------Training data. % Data.X: Feature X matrix. % Data.Y: Label Y matrix. % If Y is positive, set 0; else(unlabel), set 0 % % FunPara - Struct value in Matlab. The fields in options % that can be set: % c1: [0,inf] Paramter to tune the weight. % c2: [0,1] Paramter to tune the weight. % kerfPara:Kernel parameters. See kernelfun.m. % % Output: % Predict_Y - Predict value of the TestX. % % % Examples: % % DataTrain.A = rand(50,10); % A = rand(100,2); % B = rand(100,2)+ 1.5; % X = [A;B]; % Y = [ones(4,1);zeros(96,1);zeros(100,1)]; % Data.X = X;Data.Y = Y; % TestX = [rand(100,2);rand(100,2)+ 1.5;]; % TestY = [ones(100,1);-ones(100,1)]; % FunPara.p1=2; % FunPara.p2=0.1; % FunPara.kerfPara.type = 'rbf'; % FunPara.kerfPara.pars = 0.5; % Predict_Y =LUHL(TestX,Data,FunPara); % %Reference: % Yuan-Hai Shao, Wei-Jie Chen and Nai-Yang Deng, "Laplacian unit-hyperplane % learning from positive and unlabeled examples" Submitted 2013 % % version 1.0 --May/2013 % % Written by Wei-Jie Chen (wjcper2008@126.com) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Initailization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tic; A = Data.X((Data.Y==1),:); U = Data.X((Data.Y~=1),:); K = Data.X; m1 = size(A,1); m2 = size(U,1); m = size(Data.X,1); n = size(Data.X,2); c1 = FunPara.p1; c2=FunPara.p2; e1 = ones(m1,1); e = ones(m,1); if m1>8, knn = 8; else knn = m1 - 1; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Construct laplacian matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LA = laplacian(knn,A); LU = laplacian(knn,U); L = [LA zeros(m1,m2);zeros(m2,m1) LU]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Cache kernel matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% kerfPara = FunPara.kerfPara; if ~strcmp(kerfPara.type,'lin') K = kernelfun(Data.X,kerfPara); A = kernelfun(A,kerfPara,Data.X); O1 = speye(m+1); else O1 = speye(n+1); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Train classifier using QP solver %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% H = [A,e1]; J = [K,e]; V = (J'*L*J + c1*O1)\H'; HH= H*V; HH = (HH + HH')/2; options = optimset('Algorithm','active-set','Display','off'); alpha=quadprog(HH,0*e1,-e1',-c2,[],[],0*e1,e1/m1,0*e1,options); v1=V*alpha; rhoIndex = 0 < v1 & v1< 1/m1; rhov1 = v1; rhov1(~rhoIndex) = 0; rho = mean(J*rhov1); clear HH V alpha Times= toc; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Predict and output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% m3 = size(TestX,1); e = ones(m3,1); if ~strcmp(kerfPara.type,'lin') K = [kernelfun(TestX,kerfPara,Data.X),e]; else K = [TestX, e]; end PredictY = sign(K*v1 - rho); end
Contacts


Any question or advice please email to shaoyuanhai21@163.com and wjcper2008@126.com.