-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_damage_indices.m
28 lines (23 loc) · 1.29 KB
/
get_damage_indices.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
function sample = get_damage_indices(matrices_as_vector, dmg_size, net_size)
% returns random sample of indices to damage
% find returns indices of non-zero elements
non_zero_elements = find(matrices_as_vector);
% to save time in randperm, have two cases here:
if dmg_size <= .6
num_elements_to_damage = floor(dmg_size * net_size);
% return a k-length list of unique elements chosen from population sequence
fprintf('dmg_size is %f, num_elements_to_damage is %d out of %d options\n',dmg_size, ...
num_elements_to_damage, length(non_zero_elements));
linear_indices = randperm(length(non_zero_elements), ...
min(num_elements_to_damage, length(non_zero_elements)));
% min here because could have not enough non-zero elements
else
num_elements_to_skip = floor((1-dmg_size) * net_size);
fprintf('dmg_size is %f, num_elements_to_skip is %d out of %d options\n',dmg_size, ...
num_elements_to_skip, length(non_zero_elements));
indices_to_skip = randperm(length(non_zero_elements), ...
min(num_elements_to_skip, length(non_zero_elements)));
linear_indices = setdiff(1:length(non_zero_elements), indices_to_skip);
% min here because could have not enough non-zero elements
end
sample = non_zero_elements(linear_indices);