Home > @SVMClassifier > saveToFid.m

saveToFid

PURPOSE ^

SAVETOFID Saves Svm classifier to a binary file

SYNOPSIS ^

function saveToFid( cl, fid )

DESCRIPTION ^

SAVETOFID Saves Svm classifier to a binary file
   Inputs:
       cl : svm classifier
       fid : file descriptor

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function saveToFid( cl, fid )
0002 %SAVETOFID Saves Svm classifier to a binary file
0003 %   Inputs:
0004 %       cl : svm classifier
0005 %       fid : file descriptor
0006 
0007 %% Write number of classes
0008 if fwrite(fid, getNumClasses(cl), 'uint16') ~= 1
0009     error('Error writing to file\n');
0010 end
0011 
0012 %% Write classifier object
0013 
0014 %convert any sparse vector to full vector
0015 %TODO: modify libserialize to allow sparse values
0016 if isstruct(cl.trainedSVM)
0017     cl.trainedSVM.SVs = full(cl.trainedSVM.SVs);
0018 end
0019 
0020 data = serialize(cl.trainedSVM);
0021 dataSize = size(data, 1);
0022 
0023 % write length of classifier first
0024 if fwrite(fid, dataSize, 'uint16') ~= 1
0025     error('Error writing to file\n');
0026 end
0027 
0028 % write classifier object
0029 if fwrite(fid, data, 'uint8') ~= dataSize
0030      error('Error writing to file\n');
0031 end
0032 
0033 %% Write libsvm trainig parameters
0034 
0035 data = serialize(cl.libSvmTrnOpts);
0036 dataSize = size(data, 1);
0037 
0038 % write length of libsvm training options
0039 if fwrite(fid, uint16(dataSize), 'uint16') ~= 1
0040     error('Error writing to file\n');
0041 end
0042 
0043 % write training parameters
0044 if fwrite(fid, data, 'uint8') ~= dataSize
0045      error('Error writing to file\n');
0046 end
0047 
0048 %----------------------------------
0049 
0050 data = serialize(cl.libSvmPrdOpts);
0051 dataSize = size(data, 1);
0052 
0053 % write length of libsvm testing options
0054 if fwrite(fid, uint16(dataSize), 'uint16') ~= 1
0055     error('Error writing to file\n');
0056 end
0057 
0058 % write training parameters
0059 if fwrite(fid, data, 'uint8') ~= dataSize
0060      error('Error writing to file\n');
0061 end
0062 
0063 
0064 end
0065

Generated on Sun 29-Sep-2013 01:25:24 by m2html © 2005