function dictionary = learn_layer(layer_params, file_info, config)
% K-SVD or MI-KSVD Dictionary learning 
% Austin Myers July 2013
% Adapted from code by Liefeng Bo

% Sample patch level features
params.data = sample_layer(layer_params, file_info, config);

% KSVD Options
% params.exact = 1; % Exact dictionary update memory and time intensive
params.Tdata = layer_params.sparsity ; % Sparsity level
params.dictsize = layer_params.dict_sz;
% params.iternum = 50;
params.iternum = 10;
params.memusage = 'high';

if isfield(params, 'memusage')
    fprintf('starting K-SVD with memusage %s\n', params.memusage);
else
    fprintf('starting K-SVD with memusage normal\n');
end

dictionary = ksvd(params);
% params.blk_size = config.blk_size;
% dictionary = ksvd_parfor(params);

% disp('MI-KSVD ... ...');
% dictionary = ksvdd(params); % Mutual Incoherence Version
