posact() - Make runica() activations all RMS-positive. Adjust weights and inverse weight matrix accordingly. Usage: >> [actout,winvout,weightsout] = posact(data,weights,sphere) Inputs: data = runica() input data weights = runica() weights sphere = runica() sphere {default|0 -> eye()} Outputs: actout = activations reoriented to be RMS-positive winvout = inv(weights*sphere) reoriented to match actout weightsout = weights reoriented to match actout (sphere unchanged) Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 11/97
0001 % posact() - Make runica() activations all RMS-positive. 0002 % Adjust weights and inverse weight matrix accordingly. 0003 % 0004 % Usage: >> [actout,winvout,weightsout] = posact(data,weights,sphere) 0005 % 0006 % Inputs: 0007 % data = runica() input data 0008 % weights = runica() weights 0009 % sphere = runica() sphere {default|0 -> eye()} 0010 % 0011 % Outputs: 0012 % actout = activations reoriented to be RMS-positive 0013 % winvout = inv(weights*sphere) reoriented to match actout 0014 % weightsout = weights reoriented to match actout (sphere unchanged) 0015 % 0016 % Author: Scott Makeig, SCCN/INC/UCSD, La Jolla, 11/97 0017 0018 % Copyright (C) 11/97 Scott Makeig, SCCN/INC/UCSD, scott@sccn.ucsd.edu 0019 % 0020 % This program is free software; you can redistribute it and/or modify 0021 % it under the terms of the GNU General Public License as published by 0022 % the Free Software Foundation; either version 2 of the License, or 0023 % (at your option) any later version. 0024 % 0025 % This program is distributed in the hope that it will be useful, 0026 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0027 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0028 % GNU General Public License for more details. 0029 % 0030 % You should have received a copy of the GNU General Public License 0031 % along with this program; if not, write to the Free Software 0032 % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0033 0034 % $Log: posact.m,v $ 0035 % Revision 1.1 2002/04/05 17:36:45 jorn 0036 % Initial revision 0037 % 0038 0039 % 01-25-02 reformated help & license, added links -ad 0040 0041 function [actout,winvout,weightsout] = posact(data,weights,sphere) 0042 0043 if nargin < 2 0044 help posact 0045 return 0046 end 0047 if nargin < 3 0048 sphere = 0; 0049 end 0050 0051 [chans,frames]=size(data); 0052 [r,c]=size(weights); 0053 if sphere == 0 0054 sphere = eye(chans); 0055 end 0056 [sr,sc] = size(sphere); 0057 if sc~= chans 0058 fprintf('posact(): Sizes of sphere and data do not agree.\n') 0059 return 0060 elseif c~=sr 0061 fprintf('posact(): Sizes of weights and sphere do not agree.\n') 0062 return 0063 end 0064 0065 activations = weights*sphere*data; 0066 0067 if r==c 0068 winv = inv(weights*sphere); 0069 else 0070 winv = pinv(weights*sphere); 0071 end 0072 0073 [rows,cols] = size(activations); 0074 0075 actout = activations; 0076 winvout = winv; 0077 0078 fprintf('Inverting negative activations: '); 0079 for r=1:rows, 0080 pos = find(activations(r,:)>=0); 0081 posrms = sqrt(sum(activations(r,pos).*activations(r,pos))/length(pos)); 0082 neg = find(activations(r,:)<0); 0083 negrms = sqrt(sum(activations(r,neg).*activations(r,neg))/length(neg)); 0084 if negrms>posrms 0085 fprintf('-'); 0086 actout(r,:) = -1*activations(r,:); 0087 winvout(:,r) = -1*winv(:,r); 0088 end 0089 fprintf('%d ',r); 0090 end 0091 fprintf('\n'); 0092 0093 if nargout>2 0094 if r==c, 0095 weightsout = inv(winvout); 0096 else 0097 weightsout = pinv(winvout); 0098 end 0099 if nargin>2 % if sphere submitted 0100 weightsout = weightsout*inv(sphere); % separate out the sphering 0101 end 0102 end