-
Notifications
You must be signed in to change notification settings - Fork 1
/
genSimDat.m
75 lines (51 loc) · 1.59 KB
/
genSimDat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% genSimDat.m
% generate a simulated dataset (for code testing)
% Apr 2017 Ji Hyun Bak
%% initialize
clear all;
clc;
setpaths;
% set directory
basedir = 'Test/';
if(~exist(basedir,'dir'))
mkdir(basedir);
end
%%% set overall parameters
% set data size
N = 2000; %500; % number of trials
% set "true" hyperparameters
alpha = 2^-6; % learning rate
sigma = 2^-6; % noise strength
%% generate simulated data
%%% set up stimulus spaces
% stimulus space
xgrid1D = (55:10:95);
xx = combvec(xgrid1D,xgrid1D)';
xx = xx(diff(xx,[],2)~=0,:); % exclude diagonal
% scaled stimulus space
xcenter = mean(xgrid1D); % typical scale of stimulus
xstd = std(xgrid1D);
xsetTrue = (unique(xx,'rows')-xcenter)/xstd;
nxsetTrue = size(xsetTrue,1);
%%% prepare stimuli
% simulate full session
iall = randsample(nxsetTrue,N,'true');
xall0 = xsetTrue(iall,:);
xprev0 = sign(diff(xsetTrue(randsample(nxsetTrue,1),:)));
zall = [xprev0; sign(diff(xall0(1:end-1,:),[],2))];
xall = [xall0 zall]; % with single-step-back history term
xset = unique(xall,'rows'); % extended stimulus set
%%% run simulation
wInit = [-1 0 0 1];
K = numel(wInit); % number of parameter types
dims_sim = struct('y',1,'g',K); % binary response
params = struct('alpha',alpha,'sigma',sigma,'AT',false); % AT false: random stimuli
[~,wSim,simdat,~,~] = getSimRat_active(params,dims_sim,xall,wInit);
% wrap like a real dataset
alldat = simdat;
alldat.z = simdat.x(:,3);
alldat.x = simdat.x(:,1:2);
dims = struct('y',numel(alldat.allys)-1,'g',size(alldat.x,2)+1);
%%% save to file
filename = [basedir,'testdat.mat'];
save(filename,'alldat','dims','alpha','sigma');