annotate core/tools/machine_learning/svmlight2weight.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 w = svmlight2weight(modelfile)
Daniel@0 2 % returns the dual weight vecor for a given svm model
Daniel@0 3 %
Daniel@0 4 % All the script does is compute the weighted sum of the support vectors
Daniel@0 5 % (first element in line is alpha*y, what follows is the feature vector).
Daniel@0 6 % For further info, see the comment in the model file for its format.
Daniel@0 7
Daniel@0 8 tagstr = python('svmlight2weight.py', modelfile);
Daniel@0 9
Daniel@0 10 [firstidx] = strfind(tagstr, '1 :');
Daniel@0 11
Daniel@0 12 %get start of vector description
Daniel@0 13 tagstr = tagstr(firstidx:end);
Daniel@0 14
Daniel@0 15 % parse text function output
Daniel@0 16 vecs = textscan(tagstr,'%d %f','Delimiter',':');
Daniel@0 17
Daniel@0 18 % initialise
Daniel@0 19 w = zeros(max(vecs{1}),1);
Daniel@0 20
Daniel@0 21 % set values
Daniel@0 22 w(vecs{1}) = vecs{2};
Daniel@0 23