Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function distro(n,lambda1,S,lambda2,int,std)
- #create a matrix for ideas and their authors
- I =[];
- L = 0;
- #for each individual in the network...
- for i = 1:n
- #calculate the amount of ideas they contribute...
- k = poissrnd(lambda1);
- if (k ~= 0)
- for j = 1:k
- #and for each idea, create a matrix entry linking it back to the author
- I = [I;L + j,i];
- endfor
- endif
- L = L + k;
- endfor
- #with the user-idea matrix, shuffle the rows
- k = rand(length(I),1);
- [garbage index] = sort(k);
- I_randomised = I(index);
- #now create a discrete distribution (V) from a segment of the normal distribution that was specified
- a = norminv(int + (1-int)/2,0,std)-norminv((1-int)/2,0,std);
- b = a/length(I);
- V = [];
- for i = 0:(length(I)-1)
- #with each step, calculate the norm CDF for that step, given an apportioned length
- V = [V;normcdf(-a/2 + b*(i+1),0,std)-normcdf(-a/2 + b*i,0,std)];
- endfor
- #adjust V so that sum(V) = 1
- V = V/int;
- #prepare some empty matrices for idea/author Edges and their Overflows
- IE = [];IO = [];AE = [];AO = [];
- #for each solution
- for i = 1:S
- #find the amount of ideas it contains. Do not permit 0.
- do
- k = poissrnd(lambda2);
- until (k ~= 0)
- #given some k, find the entry in the shuffled idea matrix given a discrete random variables positioning in V
- do
- K = sort(discrete_rnd(k,I_randomised,V));
- #do this until the solution contains unique ideas
- until (is_duplicate_entry (K) == 0)
- #for each idea in the solution
- for j = 1:k
- t = j + 1;
- while (t <= k)
- #go through the idea matrix and construct edges in a sequential fashion. Order is maintained due to sorting K earlier.
- KJ = K (j);
- KT = K (t);
- tf = ismember ([KJ,KT], IE, "rows");
- #assign it to the overflow if it already exists, if not, add it to the actual edges matrix
- if (any (tf) == 1)
- IO = [IO;KJ,KT];
- else
- IE = [IE;KJ,KT];
- endif
- #and perform the same operation but with the ideas authors.
- AJ = (I (KJ, :)) (2);
- AT = (I (KT, :)) (2);
- if (AJ ~= AT)
- tf = ismember ([AJ,AT], AE, "rows");
- if (any (tf) == 1)
- AO = [AO;AJ,AT];
- else
- AE = [AE;AJ,AT];
- endif
- endif
- #increment t so as to look at the next item in K
- t++;
- endwhile
- endfor
- endfor
- #output the data in a text file that can be uploaded into CFinder
- fIdea = sprintf("ideas_%d_%d_%d_%d_%4.2f_%4.2f",n,lambda1,S,lambda2,int,std)
- fAuthor = sprintf("authors_%d_%d_%d_%d_%4.2f_%4.2f",n,lambda1,S,lambda2,int,std)
- save("-text",fIdea, "IE")
- save("-text",fAuthor, "AE")
- endfunction
Add Comment
Please, Sign In to add comment