wolffd@0: function success = save_svmlight_inequalities(lhs, rhs, factors, file) wolffd@0: % success = save_svmlight_inequalities(lhs, rhs, file) wolffd@0: % wolffd@0: % saves the optimisation problem given by lhs and rhs to wolffd@0: % a svmlight data file. the individual equations can wolffd@0: % be weighted using wolffd@0: % wolffd@0: % success = save_svmlight_inequalities(lhs, rhs, factors, file) wolffd@0: wolffd@0: if nargin == 3 wolffd@0: file = factors; wolffd@0: factors = []; wolffd@0: end wolffd@0: wolffd@0: % open file wolffd@0: fid = fopen(file, 'w+'); wolffd@0: if fid < 1 wolffd@0: success = 0; wolffd@0: return; wolffd@0: end wolffd@0: wolffd@0: try wolffd@0: % write individual constraint rows wolffd@0: for i = 1:size(lhs,1) wolffd@0: wolffd@0: % --- wolffd@0: % print rows:" rhs #fnum:#fval #fnum:#fval #fnum:#fval ..." wolffd@0: % --- wolffd@0: wolffd@0: % print right hand side wolffd@0: fprintf(fid,'%d ', rhs(i)); wolffd@0: wolffd@0: % print cost factors if availablefactor wolffd@0: if (numel(lhs{i,1}) > 0) && (numel(factors) >= i) wolffd@0: wolffd@0: fprintf(fid,'cost:%f ', factors(i)); wolffd@0: end wolffd@0: wolffd@0: % print left hand side wolffd@0: for j = 1:numel(lhs{i,1}) wolffd@0: wolffd@0: fprintf(fid,'%d:%2.16f ', lhs{i,1}(j), lhs{i,2}(j)); wolffd@0: end wolffd@0: wolffd@0: % finish line wolffd@0: fprintf(fid,'\n'); wolffd@0: end wolffd@0: catch wolffd@0: success = 0; wolffd@0: fclose(fid); wolffd@0: return; wolffd@0: end wolffd@0: success = 1; wolffd@0: fclose(fid); wolffd@0: wolffd@0: wolffd@0: