gridsearch_jld_trial.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. %% "Fitting" to human accuary and bias data (grid search)
  2. % update: squircleBehave2 should now yield A at the exact same scale as in
  3. % RSA/RDM-mixtue (see mixvectors.m in old_dev)
  4. function [BestParams]=gridsearch(aCueI,tCueI,sim,ob,CvetIn,granu);
  5. % Input:
  6. % aCueI ccw responses (1) and cw (0) per ori (1st dim) and trial (2nd dim)
  7. % tCueI correct responses in the rest; ccw (1) and cw (0) per ori (1st dim) and trial (2nd dim)
  8. % sim=1 will replace your data by toy data (useful for parameter recovery
  9. % etc.). When fitting subjects, use: gridsearch(yourAccu,yourBias,0)
  10. % ob =1 ssqmat only based on accu
  11. % granu is the granularity of the grid search
  12. % Output: fitted params: [s (noise), A (squircle factor), C (cardinal precision), min SSQ]
  13. %% simulate toy data (replaces yourData, i.e. skip when fitting subjects)
  14. % can run this directly with "gridsearch(1,1,1)" from command line
  15. if sim
  16. s=0.2; % noise (in memory/decision-making)
  17. A=1; % Key Parameter (squircle) 0: all circle; 1: all square
  18. C=0.6; % Reduce noise near cardinal by this factor (1: off)
  19. makefig=0;
  20. makefigonlybias=1;
  21. [yourAccu yourBias]=squircleBehave2(s,A,C,makefig,makefigonlybias);
  22. end
  23. %% Estimate parameters (grid search)
  24. % Specify parameter grid (compromise granularity <-> computation time)
  25. Avec=-1:granu:1;
  26. svec=0:granu:1;
  27. Cvec=CvetIn; % to omit Cardinal precision estimation, set Cvec=1
  28. % allocate results mat
  29. ssqmat=NaN(length(svec),length(Avec),length(Cvec));
  30. nits=prod(size(ssqmat)); % this many iterations will be in total
  31. % scan the grid
  32. fig=0; % no plotting on iterations
  33. fig2=0; % no plotting on iterations
  34. for i=1:length(svec)
  35. for j=1:length(Avec)
  36. for k=1:length(Cvec)
  37. %%
  38. [CP_P, CP_N, AccuMix BiasMix]=squircleBehave3(svec(i),Avec(j),Cvec(k),fig,fig2);
  39. SSpt=[];
  40. for or=1:length(CP_P)
  41. %Selecting trials where the correct response for the test was CW (and
  42. %compare with CP_P
  43. ii=(tCueI(or,:)==1&~isnan(aCueI(or,:)));
  44. SSpt=[SSpt (CP_P(or)-aCueI(or,ii)).^2];
  45. %Selecting trials where the correct response for the test was CCW (and
  46. %compare with CP_N
  47. iii=(tCueI(or,:)==0&~isnan(aCueI(or,:)));
  48. SSpt=[SSpt (CP_N(or)-aCueI(or,iii)).^2];
  49. end
  50. ssqmat(i,j,k)=sum(SSpt);
  51. end
  52. end
  53. end
  54. % find minimum
  55. [v,loc] = min(ssqmat(:));
  56. [ii,jj,k] = ind2sub(size(ssqmat),loc);
  57. BestParams=[svec(ii) Avec(jj) Cvec(k) min(ssqmat(:))];
  58. end