function K=svmWriteKernel(K_file,type,D,Dnull,gamma) % Deprecated! % since A is: E_{p(y|x)}\{||x||_2^2\}, we concatenate it to the kernel to % provide the nulldoc row,col that SVM_light expects. %nulldocK = exp(-gamma * A); % SVM_light fixup % Line 4058 of svm_learn.c performs the following to estimate SVM c: % avgxlen+=sqrt( K(i,i)-2*K(i,nulldoc)+K(nulldoc,nulldoc)); % Thus, avgxlen goes to NaN unless the following is true: % (K(i,i)+K(nulldoc,nulldoc))/2 >= K(i,nulldoc) % Hence, K(nulldoc,nulldoc)=2 will never let it go NaN, assuming: % K(i,nulldoc) \in [0,1] % nulldocK is a col vector if nargin<3 error('must supply kernel type and matrix'); end if strcmp(type,'rbf') if nargin~=5 error('rbf kernel: must supply square euclidean distances, square '... 'euclidean distance from zero, and gamma'); end K = exp(-gamma * [[0 Dnull'];[Dnull D]]); elseif strcmp(type,'linear') Dnull = sparse(1,size(Dnull,1)); K = [[0 Dnull'];[Dnull D]]; else error('unrecognized kernel type'); end floatfmt = '%.16g'; jvdmatrixWrite(K_file,K,floatfmt);