-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
91 lines (82 loc) · 3.41 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
% ------------------------------------------------------------------------
%
% This file is part of AS-ZSL, which is a solver for the following lasso
% problem with zero-sum constraint:
%
% min 0.5*||Ax-y||^2 + lambda*||x||_1
% s.t. sum(x) = 0
%
% with given matrix A, vector y and non-negative scalar lambda.
%
% ------------------------------------------------------------------------
%
% Reference paper:
%
% A. Cristofari (2023). A decomposition method for lasso problems with
% zero-sum constraint. European Journal of Operational Research 306(1),
% 358–369
%
% ------------------------------------------------------------------------
%
% Author:
% Andrea Cristofari (e-mail: andrea.cristofari@uniroma2.it)
%
% Last update of this file:
% July 26th, 2024
%
% Licensing:
% This file is part of AS-ZSL.
% AS-ZSL is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% AS-ZSL is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with AS-ZSL. If not, see <http://www.gnu.org/licenses/>.
%
% Copyright 2022-2024 Andrea Cristofari.
%
% ------------------------------------------------------------------------
clear all, clc;
rng(1);
% In this file, it is shown how to call AS-ZSL to solve a user-defined problem.
make; % build the MEX file (just the first time)
% (1) Get the problem (i.e., matrix of covariates 'A', response vector 'y' and regularization parameter 'lambda')
m = 1000; % number of samples
n = 5000; % number of features
E = exp(randn(m,n));
A = log(E./sum(E,2)); % make data compositional and then apply a log transformation
% A = A - mean(A); % to center the columns of A
y = A*sprand(n,1,0.05) + normrnd(0,0.5,m,1);
% y = y - mean(y); % to center y
lambda = 0.5*peak2peak(A'*y)/2;
% (2) Call AS-ZSL
[x,f,as_zsl_info] = as_zsl(A,y,lambda);
% If 'lambda' is a vector of regularization parameters sorted in descending order,
% then we have to solve a problem for each regularization parameter. In this case,
% a warm start strategy is used and the output values have columns, each one
% referring to the corresponding regularization parameter.
% For example:
%
% lambda_max = peak2peak(A'*y)/2;
% lambda = logspace(log10(0.95*lambda_max),log10(1e-3*lambda_max),5);
% [x,f,as_zsl_info] = as_zsl(A,y,lambda);
%--------------------------------------------------------------------------
% *** EXAMPLE OF HOW TO CHANGE AS-ZSL PARAMETERS ***
% (see the file 'usage.txt' to know which parameters can be changed and
% their default values)
%
% Instead of calling AS-ZSL by the above instruction, do the following:
%
% - create a structure having as field names the names of the parameters
% to be changed and assign them new values, e.g.,
%
% opts.verbosity = true;
%
% - pass the structure to AS-ZSL as fourth input argument, e.g.,
%
% [x,f,as_zsl_info] = as_zsl(A,y,lambda,opts);
%--------------------------------------------------------------------------