Home > demo3 > make_pyramid_kernel.m

make_pyramid_kernel

PURPOSE ^

mode=0: pyramid kernel

SYNOPSIS ^

function K = make_pyramid_kernel(W,Finfo,npoints,L,kernel_func,mode)

DESCRIPTION ^

mode=0: pyramid kernel
mode=1: kernels on each region will be outputed.
mode=2: 0 and 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function K = make_pyramid_kernel(W,Finfo,npoints,L,kernel_func,mode)
0002 %mode=0: pyramid kernel
0003 %mode=1: kernels on each region will be outputed.
0004 %mode=2: 0 and 1.
0005 
0006 num_sample = length(npoints);
0007 code_words = unique(W);
0008 
0009 kernel_count = 0;
0010 for l=0:L
0011     llcount = 0;
0012     for ll1=1:2^l
0013         for ll2=1:2^l
0014             
0015             llcount = llcount + 1;
0016             
0017             Htmp{llcount} = zeros(num_sample,length(code_words));
0018             %Htmp = zeros(num_sample,4^l);
0019             for i=1:num_sample
0020                 start_ind = sum(npoints(1:i)) - npoints(i) + 1;
0021                 end_ind = start_ind + npoints(i) - 1;
0022                 ind = start_ind:end_ind;
0023                 xlims = [min(Finfo(ind,1)) max(Finfo(ind,1))];
0024                 ylims = [min(Finfo(ind,2)) max(Finfo(ind,2))];
0025                 unitx = (xlims(2)-xlims(1))/(2^l);
0026                 unity = (ylims(2)-ylims(1))/(2^l);
0027                 ind2 = find((unitx*(ll1-1) < Finfo(ind,1)) & (unitx*(ll1) >= Finfo(ind,1)) & (unity*(ll2-1) < Finfo(ind,2)) & (unity*(ll2) >= Finfo(ind,2)));
0028                 tmpW = W(ind(ind2),:);
0029                 for jj=1:length(code_words)
0030                     Htmp{llcount}(i,jj) = sum(tmpW == code_words(jj));
0031                 end;
0032             end;
0033             
0034             kernel_count = kernel_count + 1;
0035             K(:,:,kernel_count) = zeros(num_sample,num_sample);
0036             for i=1:num_sample
0037                 for j=i:num_sample
0038                     K(i,j,kernel_count) = kernel_func(Htmp{llcount}(i,:),Htmp{llcount}(j,:));
0039                 end;
0040             end;
0041             K(:,:,kernel_count) = K(:,:,kernel_count)+K(:,:,kernel_count)'- diag(diag(K(:,:,kernel_count)));
0042 
0043         end;
0044     end;
0045 end;
0046 
0047 if mode==0 || mode==2
0048     Ktmp = sum(K(:,:,end-4^L+1:end),3);
0049     start_ind = [1 2];    
0050     for l=0:(L-1)
0051         end_ind = start_ind + [4^l 4^(l+1)] -1;
0052         Ktmp = Ktmp + (sum(K(:,:,start_ind(1):end_ind(1)),3) - sum(K(:,:,start_ind(2):end_ind(2)),3))/(2^(L-l));
0053         start_ind = end_ind + 1;
0054     end;    
0055     if mode==0
0056         K = Ktmp;
0057     else
0058         K(:,:,end+1) = Ktmp;
0059     end;
0060 end;

Generated on Sat 22-Aug-2009 22:15:36 by m2html © 2003