-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathflatten.m
48 lines (42 loc) · 1.11 KB
/
flatten.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
% flatten - mode-k unfolding of a tensor
%
% Syntax
% Z=flatten(X,ind)
%
% See also
% flatten_adj
%
% Reference
% "Estimation of low-rank tensors via convex optimization"
% Ryota Tomioka, Kohei Hayashi, and Hisashi Kashima
% arXiv:1010.0789
% http://arxiv.org/abs/1010.0789
%
% "Statistical Performance of Convex Tensor Decomposition"
% Ryota Tomioka, Taiji Suzuki, Kohei Hayashi, Hisashi Kashima
% NIPS 2011
% http://books.nips.cc/papers/files/nips24/NIPS2011_0596.pdf
%
% Convex Tensor Decomposition via Structured Schatten Norm Regularization
% Ryota Tomioka, Taiji Suzuki
% NIPS 2013
% http://papers.nips.cc/paper/4985-convex-tensor-decomposition-via-structured-schatten-norm-regularization.pdf
%
% Copyright(c) 2010-2014 Ryota Tomioka
% This software is distributed under the MIT license. See license.txt
function Z=flatten(X,ind)
sz=size(X);
if isnumeric(ind)
nd=max(ndims(X),ind);
ind = {ind, [ind+1:nd, 1:ind-1]};
else
nd=max(cellfun(@max,ind));
end
if length(ind{1})~=1 || ind{1}~=1
X=permute(X,cell2mat(ind));
end
if length(ind{1})==1
Z=X(:,:);
else
Z=reshape(X,[prod(sz(ind{1})),prod(sz(ind{2}))]);
end