-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinitialize_cores.m
More file actions
35 lines (32 loc) · 953 Bytes
/
Copy pathinitialize_cores.m
File metadata and controls
35 lines (32 loc) · 953 Bytes
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
function cores = initialize_cores(sz, ranks, varargin)
%initialize_cores Initializes cores using Gaussian distribution
%
%cores = initialize_cores(sz, ranks) returns a length-N cell with N cores,
%each with entires drawn iid from the standard Gaussian distribution. sz is
%a length-N vector with the sizes, and ranks is a length-N vector with the
%outgoing ranks.
%
%cores = initialize_cores(___, 'init_zero', init_zero) will just initialize
%all cores to zero if init_zero is true. Default is false.
% Handle optional inputs
params = inputParser;
addParameter(params, 'init_zero', false, @isscalar);
parse(params, varargin{:});
init_zero = params.Results.init_zero;
% Main code
N = length(sz);
cores = cell(N,1);
for n = 1:N
R1 = ranks(n);
if n == 1
R0 = ranks(end);
else
R0 = ranks(n-1);
end
if init_zero
cores{n} = zeros(R0, sz(n), R1);
else
cores{n} = randn(R0, sz(n), R1);
end
end
end