-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgetnewloc.m
More file actions
37 lines (27 loc) · 1.01 KB
/
Copy pathgetnewloc.m
File metadata and controls
37 lines (27 loc) · 1.01 KB
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
% This is a function that updates the location
% It takes a "fake cdf" and then compares this to a random number to see
% what cluster each user moves to. You can think of this as taking the line
% 0 to 1 and partitioning it into k (nonzero) intervals. Then each cluster with
% nonzero probability gets a piece according to its probility. We generate
% a random number from U[0,1] and map it to each one of these pieces in the
% obvious way.
%
% If current is 0, then we assign the user to another location randomly
function current = getnewloc(current, fakecdf)
newloc = zeros(size(current,1), 1);
for i = 1:size(current,1)
num = rand(1);
if current(i) ~= 0
indices = find(fakecdf(current(i),:) > num);
else
indices = randi(length(fakecdf),1);
end
%You get problems if you go to a singleton cluster -- this keeps you
%out of there
if isempty(indices) == 1
indices = randi(length(fakecdf),1);
end
newloc(i) = min(indices);
end
current = newloc;
end