forked from WHU-SNA/OpMaxInSTN
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinitIO.m
30 lines (30 loc) · 977 Bytes
/
initIO.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
function [internalOpinion] = initIO(d, numNodes, mode)
if strcmp(mode, 'degree')
mind = min(d);
maxd = max(d);
internalOpinion = zeros(numNodes, 1);
for i = 1: numNodes
internalOpinion(i) = (d(i) - mind) / (maxd - mind);
if rand(1) > 0.5
internalOpinion(i) = -internalOpinion(i);
end
end
elseif strcmp(mode, 'normal')
internalOpinion = randn(round(numNodes * 1.5), 1);
internalOpinion = internalOpinion(internalOpinion >= -1 & internalOpinion <= 1);
internalOpinion = internalOpinion(1:numNodes);
elseif strcmp(mode, 'pow')
alpha = 2;
smin = 0;
alpha2 =alpha-1;
a = randn(numNodes,1);
b = normcdf(abs(a));
b = 2 - 2 * b;
internalOpinion = b.^(-1/alpha2);
internalOpinion = internalOpinion * smin;
elseif strcmp(mode, 'uniform')
internalOpinion = (rand(numNodes, 1) - 0.5) * 2;
else
internalOpinion = (rand(numNodes, 1) - 0.5) * 2;
end
end