comparison core/tools/machine_learning/save_svmlight_inequalities.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function success = save_svmlight_inequalities(lhs, rhs, factors, file)
2 % success = save_svmlight_inequalities(lhs, rhs, file)
3 %
4 % saves the optimisation problem given by lhs and rhs to
5 % a svmlight data file. the individual equations can
6 % be weighted using
7 %
8 % success = save_svmlight_inequalities(lhs, rhs, factors, file)
9
10 if nargin == 3
11 file = factors;
12 factors = [];
13 end
14
15 % open file
16 fid = fopen(file, 'w+');
17 if fid < 1
18 success = 0;
19 return;
20 end
21
22 try
23 % write individual constraint rows
24 for i = 1:size(lhs,1)
25
26 % ---
27 % print rows:" rhs #fnum:#fval #fnum:#fval #fnum:#fval ..."
28 % ---
29
30 % print right hand side
31 fprintf(fid,'%d ', rhs(i));
32
33 % print cost factors if availablefactor
34 if (numel(lhs{i,1}) > 0) && (numel(factors) >= i)
35
36 fprintf(fid,'cost:%f ', factors(i));
37 end
38
39 % print left hand side
40 for j = 1:numel(lhs{i,1})
41
42 fprintf(fid,'%d:%2.16f ', lhs{i,1}(j), lhs{i,2}(j));
43 end
44
45 % finish line
46 fprintf(fid,'\n');
47 end
48 catch
49 success = 0;
50 fclose(fid);
51 return;
52 end
53 success = 1;
54 fclose(fid);
55
56
57