Dimitrios@0: function W = normalize_W(W, type) Dimitrios@0: % function W = normalize_W(W, type) Dimitrios@0: % Dimitrios@0: % Normalize columns of W using: Dimitrios@0: % 1 - use 1-norm [default] Dimitrios@0: % 2 - use 2-norm Dimitrios@0: % k - multiply the 1-norm by k Dimitrios@0: % Dimitrios@0: % This should work both for matrices and tensors (only for Convolutive NMF) Dimitrios@0: % Dimitrios@0: % 2010-01-14 Graham Grindlay (grindlay@ee.columbia.edu) Dimitrios@0: Dimitrios@0: % Copyright (C) 2008-2028 Graham Grindlay (grindlay@ee.columbia.edu) Dimitrios@0: % Dimitrios@0: % This program is free software: you can redistribute it and/or modify Dimitrios@0: % it under the terms of the GNU General Public License as published by Dimitrios@0: % the Free Software Foundation, either version 3 of the License, or Dimitrios@0: % (at your option) any later version. Dimitrios@0: % Dimitrios@0: % This program is distributed in the hope that it will be useful, Dimitrios@0: % but WITHOUT ANY WARRANTY; without even the implied warranty of Dimitrios@0: % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Dimitrios@0: % GNU General Public License for more details. Dimitrios@0: % Dimitrios@0: % You should have received a copy of the GNU General Public License Dimitrios@0: % along with this program. If not, see . Dimitrios@0: Dimitrios@0: if nargin < 2 Dimitrios@0: type = 1; Dimitrios@0: end Dimitrios@0: Dimitrios@0: switch type Dimitrios@0: case 1 Dimitrios@0: for j = 1:size(W,3) Dimitrios@0: for i = 1:size(W,2) Dimitrios@0: W(:,i,j) = W(:,i,j) ./ norm(W(:,i,j),1); Dimitrios@0: end Dimitrios@0: end Dimitrios@0: Dimitrios@0: case 2 Dimitrios@0: for j = 1:size(W,3) Dimitrios@0: for i = 1:size(W,2) Dimitrios@0: W(:,i,j) = W(:,i,j) ./ norm(W(:,i,j),2); Dimitrios@0: end Dimitrios@0: end Dimitrios@0: Dimitrios@0: case 0 Dimitrios@0: Dimitrios@0: otherwise Dimitrios@0: for j = 1:size(W,3) Dimitrios@0: for i = 1:size(W,2) Dimitrios@0: W(:,i,j) = type*W(:,i,j) ./ norm(W(:,i,j),1); Dimitrios@0: end Dimitrios@0: end Dimitrios@0: end Dimitrios@0: