view sequences/rndzipaccum.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 79038cbcce00
children
line wrap: on
line source
function X=rndzipaccum(gen,s0,varargin)
% rndzipaccum - Random sequence by zipping argument sequences with state
%
% rndzipaccum ::
%    (A1, ..., An, S -> rndgen (B, S)) ~'stateful sampling function',
%    S                         ~'initial state',
%    seq A1, ..., seq An       ~'argument sequences', 
%    rndstate                  ~'initial random state'
% -> seq B.

	n=length(varargin)-1;
	if n>0
		X=zipaccum(@zafn,{s0,varargin{n+1}},varargin{1:n});
	else
		X=unfold(@ufn,{s0,varargin{1}});
	end

	function [x,s]=ufn(s0)
		setrndstate(s0{2});
		[x,t]=gen(s0{1});
		s={t,getrndstate};
	end
	
	function [x,s]=zafn(varargin)
		s0=varargin{n+1};
		setrndstate(s0{2});
		[x,t]=gen(varargin{1:n},s0{1});
		s={t,getrndstate};
	end
end