Guest User

Untitled

a guest
Jan 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 2.63 KB | None | 0 0
  1. function distro(n,lambda1,S,lambda2,int,std)
  2. #create a matrix for ideas and their authors
  3. I =[];
  4. L = 0;
  5. #for each individual in the network... 
  6. for i = 1:n
  7.   #calculate the amount of ideas they contribute...
  8.   k = poissrnd(lambda1);
  9.     if (k ~= 0)
  10.       for j = 1:k
  11.         #and for each idea, create a matrix entry linking it back to the author
  12.         I = [I;L + j,i];
  13.       endfor
  14.     endif
  15.   L = L + k;
  16. endfor
  17. #with the user-idea matrix, shuffle the rows
  18. k = rand(length(I),1);
  19. [garbage index] = sort(k);
  20. I_randomised = I(index);
  21. #now create a discrete distribution (V) from a segment of the normal distribution that was specified
  22. a = norminv(int + (1-int)/2,0,std)-norminv((1-int)/2,0,std);
  23. b = a/length(I);
  24. V = [];
  25. for i = 0:(length(I)-1)
  26.   #with each step, calculate the norm CDF for that step, given an apportioned length
  27.   V = [V;normcdf(-a/2 + b*(i+1),0,std)-normcdf(-a/2 + b*i,0,std)];
  28. endfor
  29. #adjust V so that sum(V) = 1
  30. V = V/int;
  31. #prepare some empty matrices for idea/author Edges and their Overflows
  32. IE = [];IO = [];AE = [];AO = [];
  33. #for each solution
  34. for i = 1:S
  35.   #find the amount of ideas it contains. Do not permit 0.
  36.   do
  37.   k = poissrnd(lambda2);
  38.   until (k ~= 0)
  39.   #given some k, find the entry in the shuffled idea matrix given a discrete random variables positioning in V
  40.   do
  41.     K = sort(discrete_rnd(k,I_randomised,V));
  42.     #do this until the solution contains unique ideas
  43.   until (is_duplicate_entry (K) == 0)
  44.   #for each idea in the solution
  45.   for j = 1:k
  46.     t = j + 1;
  47.     while (t <= k)
  48.       #go through the idea matrix and construct edges in a sequential fashion. Order is maintained due to sorting K earlier.
  49.       KJ = K (j);
  50.       KT = K (t);
  51.       tf = ismember ([KJ,KT], IE, "rows");
  52.       #assign it to the overflow if it already exists, if not, add it to the actual edges matrix
  53.       if (any (tf) == 1)
  54.         IO = [IO;KJ,KT];
  55.       else
  56.         IE = [IE;KJ,KT];
  57.       endif
  58.       #and perform the same operation but with the ideas authors.
  59.       AJ = (I (KJ, :)) (2);
  60.       AT = (I (KT, :)) (2);
  61.       if (AJ ~= AT)
  62.         tf = ismember ([AJ,AT], AE, "rows");
  63.         if (any (tf) == 1)
  64.           AO = [AO;AJ,AT];
  65.         else
  66.           AE = [AE;AJ,AT];
  67.         endif
  68.       endif
  69.       #increment t so as to look at the next item in K
  70.       t++;
  71.     endwhile
  72.   endfor
  73. endfor
  74. #output the data in a text file that can be uploaded into CFinder
  75. fIdea = sprintf("ideas_%d_%d_%d_%d_%4.2f_%4.2f",n,lambda1,S,lambda2,int,std)
  76. fAuthor = sprintf("authors_%d_%d_%d_%d_%4.2f_%4.2f",n,lambda1,S,lambda2,int,std)
  77. save("-text",fIdea, "IE")
  78. save("-text",fAuthor, "AE")
  79. endfunction
Add Comment
Please, Sign In to add comment