📄 util_get_resp.m
字号:
function r_out = util_get_resp (dn, param)% FUNCTION r_out = util_get_resp (dn, param)%% Get random unit's responses from a directory named dn. The input% arguement param determines how many model units from which layers% to pick. For example, if dn = 'Test', and param = [0 100 0 200],% then 100 and 200 random responses from Animal/Layer2 and% Animal/Layer4 directories will be retrieved for each stimulus% image. For exmaple,% r_out = util_get_resp ('Animal', [0 100 0 200]);%% The output r_out is a structure with fields r_out.layerX,% which is a number of features (defined by param) by number of% images (determined by the number of files in the directory).%% If the requested number is too many (over 1000000), all units are chosen.BigNUM = 1000000;if ~exist(dn, 'dir') error(['No such directory: ' dn]);endr_out = [];for layer = 1:length(param) % loop thru layers if param(layer) > 0 dn_layer = [dn '/Layer' num2str(layer) '/']; D = dir([dn_layer 'r_i*.mat']); disp(['Getting response from ' dn_layer]); for i = 1:length(D) % loop thru files fprintf('.'); if mod(i,50)==0 fprintf('\n'); end clear r r_all; load([dn_layer D(i).name]); % r_all is (x times y times scales) by (num_features). r_all = aux_get_all_resp(r); if i == 1 % Load the saved random picks? if param(layer)>BigNUM % Too many neurons, then pick all. filename = ['rand_pick_L' num2str(layer) '_all.mat']; else filename = ['rand_pick_L' num2str(layer) '_']; filename = [filename num2str(param(layer)) '.mat']; end if ~exist(filename,'file') % Decide which units to pick. Note that this random pick % is the same for a given directory, but if the user % runs this function again, another random set will be % picked. num_units = size(r_all,1) * size(r_all,2); if num_units > param(layer) % If the number of possible units is greater than % requested number of units, then go ahead with random pick. x = randperm(num_units); rand_pick = x(1:param(layer)); else rand_pick = [1:num_units]; filename = ['rand_pick_L' num2str(layer) '_all.mat']; end save(filename, 'rand_pick'); else load(filename); end r_tmp = zeros(length(rand_pick),length(D)); end r_tmp(:,i) = r_all(rand_pick); end fprintf('\n'); r_out = setfield(r_out, ['Layer' num2str(layer)], r_tmp); clear r_tmp; endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -