Changeset 114
- Timestamp:
- 11/16/16 15:10:36 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
prextra/lassoc.m
r108 r114 6 6 % parameter. 7 7 8 function w = lassoc(x, lambda) 8 % w = lassoc(x, lambda) 9 function w = lassoc(varargin) 9 10 10 mustScale=0; 11 argin = shiftargin(varargin,'scalar'); 12 argin = setdefaults(argin,[],1); 11 13 12 if (nargin < 2) 13 %prwarning(3,'Lambda set to one'); 14 lambda = 1; 15 end 16 if (nargin < 1) | (isempty(x)) 17 w = prmapping(mfilename,{lambda}); 18 w = setname(w,'LASSO classifier'); 19 return 20 end 14 if mapping_task(argin,'definition') 21 15 22 if ~ismapping(lambda) % train the mapping 16 w = define_mapping(argin,'untrained','LASSO classifier'); 23 17 18 elseif mapping_task(argin,'training') 19 20 [x,lambda] = deal(argin{:}); 24 21 % Unpack the dataset. 25 22 islabtype(x,'crisp'); … … 27 24 [n,k,c] = getsize(x); 28 25 29 % Is this necessary??30 if mustScale31 wsc = scalem(x,'variance');32 x.data = x.data*wsc;33 end34 26 % make sure a bias is added: 35 27 x = [x ones(n,1)]; … … 52 44 53 45 % and store the results: 54 if mustScale55 W.wsc = wsc;56 end57 58 46 W.beta = beta; % the ultimate weights 59 47 W.nr = nr; 60 w = prmapping(mfilename,'trained',W,getlablist(x), size(x,2),c);48 w = prmapping(mfilename,'trained',W,getlablist(x),k,c); 61 49 w = setname(w,'LASSO classifier (l=%f)',lambda); 62 50 63 51 else 52 [x,lambda] = deal(argin{1:2}); 64 53 % Evaluate the classifier on new data: 65 54 W = getdata(lambda); 66 55 n = size(x,1); 67 56 68 % scaling and linear classifier:69 if mustScale70 x = x*W.wsc;71 end72 57 % make sure a bias is added: 73 58 x = [x ones(n,1)];
Note: See TracChangeset
for help on using the changeset viewer.