% aica -  ICA
%
% aica ::
%    model(real) ~'probability model for components',
%    [[N,N]]     ~'initial weight matrix',
%    options {
%       rate    :: nonneg/1e-4 ~'adaptation rate';
%    }
% -> arrow({[[N]]},{[[N]]},aica_state).

function o=aica(model,W0,varargin)
	opts=options('rate',1e-4,varargin{:});
	score=scorefn(model);

	rate=opts.rate;
	o=loop(@update,@(s)W0);

	function [y,W]=update(x,W)
%		y=W'*x; W=W+rate*(W-(W*y)*score(y)');
		y=W*x;  W=W+rate*(W-(score(y)/size(y,2))*(y'*W));
	end
end
