annotate core/tools/machine_learning/save_svmlight_inequalities.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function success = save_svmlight_inequalities(lhs, rhs, factors, file)
Daniel@0 2 % success = save_svmlight_inequalities(lhs, rhs, file)
Daniel@0 3 %
Daniel@0 4 % saves the optimisation problem given by lhs and rhs to
Daniel@0 5 % a svmlight data file. the individual equations can
Daniel@0 6 % be weighted using
Daniel@0 7 %
Daniel@0 8 % success = save_svmlight_inequalities(lhs, rhs, factors, file)
Daniel@0 9
Daniel@0 10 if nargin == 3
Daniel@0 11 file = factors;
Daniel@0 12 factors = [];
Daniel@0 13 end
Daniel@0 14
Daniel@0 15 % open file
Daniel@0 16 fid = fopen(file, 'w+');
Daniel@0 17 if fid < 1
Daniel@0 18 success = 0;
Daniel@0 19 return;
Daniel@0 20 end
Daniel@0 21
Daniel@0 22 try
Daniel@0 23 % write individual constraint rows
Daniel@0 24 for i = 1:size(lhs,1)
Daniel@0 25
Daniel@0 26 % ---
Daniel@0 27 % print rows:" rhs #fnum:#fval #fnum:#fval #fnum:#fval ..."
Daniel@0 28 % ---
Daniel@0 29
Daniel@0 30 % print right hand side
Daniel@0 31 fprintf(fid,'%d ', rhs(i));
Daniel@0 32
Daniel@0 33 % print cost factors if availablefactor
Daniel@0 34 if (numel(lhs{i,1}) > 0) && (numel(factors) >= i)
Daniel@0 35
Daniel@0 36 fprintf(fid,'cost:%f ', factors(i));
Daniel@0 37 end
Daniel@0 38
Daniel@0 39 % print left hand side
Daniel@0 40 for j = 1:numel(lhs{i,1})
Daniel@0 41
Daniel@0 42 fprintf(fid,'%d:%2.16f ', lhs{i,1}(j), lhs{i,2}(j));
Daniel@0 43 end
Daniel@0 44
Daniel@0 45 % finish line
Daniel@0 46 fprintf(fid,'\n');
Daniel@0 47 end
Daniel@0 48 catch
Daniel@0 49 success = 0;
Daniel@0 50 fclose(fid);
Daniel@0 51 return;
Daniel@0 52 end
Daniel@0 53 success = 1;
Daniel@0 54 fclose(fid);
Daniel@0 55
Daniel@0 56
Daniel@0 57