-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_multi_infer.m
55 lines (46 loc) · 2.42 KB
/
gen_multi_infer.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
function coef_vals = gen_multi_infer(dictionary_n, x_im, infer_hand, opts)
% coef_vals = multi_l1ls(dictionary_n, x_im, infer_type, opts)
%
% Function to perform inference on a multitude of test vectors. The
% inference algorithm given by infer_type is run on each column of x_im
% with repect to dictionary_n.
%
% Inputs:
% dictionary_n - The dictionary to decompose the data into
% x_im - A matrix with the columns as data to decompose
% infer_hand - Handle for a wrapper that calls an inference
% function. Included in the package is the default
% conjugate gradient descent method (both wrapper
% and function) as well as wrappers for some
% recommended inference functions easily available
% online. Some included wrappers are The 'MP' and
% 'OOMP' from the SparseLab100 library available at
% http://sparselab.stanford.edu, the OMP_qr from
% the sparsify package (v4 or later) available at
% http://www.personal.soton.ac.uk/tb1m08/sparsify/s
% parsify.html, and the L1-regularized functions
% l1_ls and l1_ls_nonneg available at
% http://www.stanford.edu/~boyd/l1_ls/. To use a
% different inference function, simply create a
% wrapper as per the examples for the functions
% above.
% opts - A struct of options needed for the optimization
% program selected.
%
% Outputs:
% coef_vals - optimized coefficients
%
% Last Modified 6/3/2010 - Adam Charles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initializations
% Initialize coefficients
coef_vals = zeros(size(dictionary_n, 2), size(x_im, 2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Perform the L1-regulized optimization on the data
parfor index_in = 1:size(x_im, 2)
coef_vals(:, index_in) = feval(infer_hand, dictionary_n, x_im(:,index_in),...
opts);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%