-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChidori_CUR.m
66 lines (60 loc) · 1.88 KB
/
Chidori_CUR.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
function [Core, X_sub_mat] = Chidori_CUR(X, R, const)
% Syntex:
% [Core,X_sub_mat] = Chidori_CUR(X,R,const)
%
% Environment:
% This function is developed with Tensor Toolbox v3.1
% URL: https://gitlab.com/tensors/tensor_toolbox/-/releases/v3.1
%
% Inputs:
% X: Inputed tensor.
% R: Targeted multilinear rank.
% const: Sampling constant, see paper for details. Default value: 2
%
% Outputs:
% Core : Core tensor, i.e., \mathcal{R}.
% X_sub_mat : Chidori CUR components, i.e. {C_i U_i^\dagger}.
%
% To obtain the full estimated tensor:
% X_est = tensor(ttensor(Core,X_sub_mat));
%
%
% Please cite the following paper if you find this code helpful:
% HQ Cai, K Hamm, L Huang, and D Needell. Mode-wise Tensor Decompositions:
% Multi-dimensional Generalizations of CUR Decompositions. Journal of
% Machine Learning Research, 22.185: 1-36, 2021.
%
% By:
% HanQin Cai, [email protected]
% Keaton Hamm, [email protected]
% Longxiu Huang, [email protected]
% Deanna Needell, [email protected]
if nargin == 2
const = 2;
end
n_dim = size(X);
mod_num = ndims(X);
Sub_ten_ind = struct('type','()','subs',{[]});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% Randomly generate the sub matrices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I = cell(mod_num,1);
for it_mod = 1:mod_num
len2 = min(ceil(const*R(it_mod)*log(n_dim(it_mod))),n_dim(it_mod));
I{it_mod} = randi(n_dim(it_mod),[len2 1]);
end
X_sub_mat = cell(mod_num,1);
I_temp = I;
for it_mod = 1:mod_num
%I_temp = I;
I_temp{it_mod} = (1:n_dim(it_mod))';
Sub_ten_ind.subs = I_temp;
C = subsref(X,Sub_ten_ind);
C = double(tenmat(C,it_mod));
U = C(I{it_mod},:);
[u,s,v] = svd(U,'econ');
r = R(it_mod);
X_sub_mat{it_mod} = C*v(:,1:r)*(pinv(s(1:r,1:r)))*(u(:,1:r))';
I_temp{it_mod} = I{it_mod};
end
Sub_ten_ind.subs = I;
Core = subsref(X,Sub_ten_ind);