gammaParamsCondshD.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function [params events temp] = gammaParamsCondshD(eventprobs,lens,shape,conds,map,maxDur)
  2. % @ lens: mean trial duration per condition [N Conditions]
  3. offset1=3;
  4. spacing=5;
  5. nconds=max(conds);
  6. map=cat(2,map,ones(nconds,1)); % add one column maps[conditions, N stages]
  7. nstates=size(eventprobs,3); % number of bumps
  8. temp=zeros(maxDur,nstates,nconds);
  9. params=zeros(nstates+1,2,nconds);
  10. for i = 1:nconds
  11. temp(:,:,i)=reshape(mean(eventprobs(:,conds==i,:),2),maxDur,nstates);
  12. % temp[samples,bumps,condition] mean accros trials per sample, like an ERP
  13. end
  14. maxobs=(maxDur+1)-(2*(offset1-1)+(nstates-1)*spacing); % max duration of trial without bumps' length and offset
  15. events=zeros(nstates+2,nconds);
  16. for j = 1:nconds
  17. offset=-2;
  18. for i = 1:nstates
  19. if map(j,i)~=0 % if condition/current stage estimation requested
  20. offset=offset+spacing;
  21. temp(1:maxobs,i,j)=temp(offset:offset+maxobs-1,i,j);
  22. % global expected location of a bump
  23. events(i+1,j)=[1:maxobs]*temp(1:maxobs,i,j);
  24. else % if not requested: assign to next stage 'events' of current stage/state
  25. events(i+1,j)=events(i,j);
  26. end
  27. end
  28. events(i+2,j)=lens(j)-offset-1; % mean trial duration per condition - offest - 1
  29. end
  30. temp(maxobs+1:end,:,:)=[];
  31. for j = 1:nstates+1 % iterate stages
  32. % get the index of requested stages to compute the duration of the flats.
  33. uniques=unique(map(:,j)); % take uinque requested map/condition values in bump
  34. uniques=uniques(uniques>0); % discard zeros (not requested)
  35. for i = 1:length(uniques) % iteratee unique values
  36. subs=find(map(:,j)==i); % index of unque value in a stage
  37. % Gamma scale : duration of a flat (event(j+1) - event(j)) divided by shape
  38. params(j,:,subs)=repmat([shape,mean(events(j+1,subs)-events(j,subs))/shape],[1,1,length(subs)]);
  39. end
  40. end
  41. params(1,2,:)=params(1,2,:)-.5/shape;
  42. params(2:nstates,2,:)=params(2:nstates,2,:)+.5/shape;