-
Notifications
You must be signed in to change notification settings - Fork 3
/
create_parafac2_problem.m
45 lines (42 loc) · 1.03 KB
/
create_parafac2_problem.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
function [X, Mat] = create_parafac2_problem(K, J, F, sparsity, MAXSAMPLES, PARFOR_FLAG)
rng('default');
C = rand(K, F);
A = rand(J, F);
L=rand(F,50);
Mat=C*L;
H=orth(orth(rand(F))');
H(H<0);
assert(rank(H)==size(H, 1));
P=cell(1, K);
if (PARFOR_FLAG)
parfor i=1: K
P{i}=orth(rand(MAXSAMPLES, F));
end
else
for i=1: K
P{i}=orth(rand(MAXSAMPLES, F));
end
end
X = cell(1, K);
totalnnz = 0;
if (PARFOR_FLAG)
parfor i=1: K
X{i}=(A*diag(C(i,:))*(P{i}*H)')' ;
%sparsifier = sprand(MAXSAMPLES, J, sparsity);
%sparsifier = (sparsifier>0);
%X{i} = X{i}.*sparsifier;
%X{i} = sparse(X{i});
X{i} = X{i}(any(X{i}, 2), :);
totalnnz = totalnnz + nnz(X{i});
end
else
for i=1: K
X{i}=(A*diag(C(i,:))*(P{i}*H)')' ;
%sparsifier = sprand(MAXSAMPLES, J, sparsity);
%sparsifier = (sparsifier>0);
%X{i} = X{i}.*sparsifier;
%X{i} = sparse(X{i});
X{i} = X{i}(any(X{i}, 2), :);
totalnnz = totalnnz + nnz(X{i});
end
end