Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //script simulates encounter selection with a range of user-specified values for # of encounters, length of queue, and rejection rate and records the distribution of queue states for 1m trials with each set of parameters.
- for i from 1 to 10 print("fix line 24");
- int[int] value_count;
- int[int] buffer_queue;
- void select(int n, int k, int p, int q, int epsilon){
- int selection = -1;
- boolean in_queue;
- int rejection_roll = q;
- while(selection == -1){
- selection = random(n+epsilon);
- if(selection > (n-1) ){
- selection = n-1;
- }
- in_queue = false;
- for i from 1 to k{
- if(selection == buffer_queue[i]){
- in_queue = true;
- }
- }
- if(in_queue && selection != (n-1) ){
- rejection_roll = random(q);
- if(rejection_roll < p){
- selection = -1;
- }
- }
- }
- for i from 2 to k {
- buffer_queue[i-1] = buffer_queue[i];
- }
- value_count[selection]++;
- buffer_queue[k] = selection;
- }
- void generate_and_save_some_queue_data(int n, int k, int p, int q, int epsilon){
- //rolls will take values 0,...,n-1
- //the values 0,...,n-2 have weight 1
- //the value n-1 has weight 1+epsilon.
- //queue will remember last k rolls.
- //rejection rolls will take values 0,...,q-1 and will reject selections if less than p.
- //rejection rate is effectively p/q
- //seed selection process with uniform distibution queue
- //let's see how long this takes to run
- print("starting simulation with n="+n+" k="+k+" p="+p+" q="+q+" epsilon="+epsilon);
- int starting_gun = gametime_to_int();
- for i from 1 to k{
- buffer_queue[i] = random(n);
- }
- //seed queue with more queueily selected things
- for i from 1 to k*k {
- select(n,k,p,q,epsilon);
- }
- //let's count some queues for some numerical analysis of steady state distributions
- float[string] queue_frequency;
- int progress = 0;
- buffer queuey_string ;
- for i from 1 to 1000000{
- select(n,k,p,q,epsilon);
- queuey_string.set_length(0);
- for j from 1 to k{
- if(j == 1){
- queuey_string.append(buffer_queue[j].to_string());
- }
- else{
- queuey_string.append(","+buffer_queue[j].to_string());
- }
- }
- queue_frequency[queuey_string.to_string()] += 1;
- if(i%100000 == 0){
- progress++;
- int butts = (gametime_to_int()-starting_gun)/1000;
- print("we're "+i/100000+"/10 done after "+butts+" seconds.");
- }
- }
- foreach i in queue_frequency{
- queue_frequency[i] /= 1000000;
- }
- //let's label the file in a way that is good.
- map_to_file(queue_frequency,"queue frequency data with n="+n+" k="+k+" p="+p+" q="+q+" epsilon="+epsilon+".txt");
- print_html("and we're done");
- }
- void condense_some_queue_data(int n, int k, int p, int q, int epsilon){
- float[string] foreign_import_data;
- //string[string] queue_correspondences;
- float[boolean][int][int] condensed_data;
- file_to_map("queue frequency data with n="+n+" k="+k+" p="+p+" q="+q+" epsilon="+epsilon+".txt",foreign_import_data);
- float[int][int] counting_queues;
- boolean[int] queue_contents;
- int queue_content_count;
- int epsilon_count;
- foreach i in foreign_import_data{
- //reset counting.
- queue_content_count = 0;
- epsilon_count = 0;
- for j from 0 to n-1{
- queue_contents[j] = false;
- }
- //split queue at commas.
- string[int] queue = split_string(i,",");
- for j from 0 to k-1{
- //count number of unique things in queue.
- if(!queue_contents[queue[j].to_int()]){
- queue_contents[queue[j].to_int()] = true;
- queue_content_count++;
- }
- //count number of occurrences of the higher probability outcome.
- if(queue[j].to_int() == (n-1)){
- epsilon_count++;
- }
- }
- //reindex simulation results by those counts.
- condensed_data[false][queue_content_count][epsilon_count] += foreign_import_data[i];
- //keep track of how many queue states are in this category.
- counting_queues[queue_content_count][epsilon_count] += 1.0;
- }
- foreach i,j in condensed_data[false]{
- //normalize by number of queue states in each category.
- condensed_data[true][i][j] = condensed_data[false][i][j]/counting_queues[i][j];
- }
- //save reindexed data to file.
- map_to_file(condensed_data,"condensed queue frequency data with n="+n+" k="+k+" p="+p+" q="+q+" epsilon="+epsilon+".txt");
- }
- /*
- generate_and_save_some_queue_data(3,4,1,10,1);
- generate_and_save_some_queue_data(3,4,5,10,1);
- generate_and_save_some_queue_data(3,4,9,10,1);
- condense_some_queue_data(3,4,1,10,1);
- condense_some_queue_data(3,4,5,10,1);
- condense_some_queue_data(3,4,9,10,1);
- */
- for a from 11 to 13{
- generate_and_save_some_queue_data(2,5,3,4,a);
- condense_some_queue_data(2,5,3,4,a);
- foreach i in value_count{
- print(i+": "+value_count[i]);
- }
- clear(value_count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement