require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
require 'rubygems' require 'faster_csv' population_size = 20 sample_size = 0.. population_size - 1 iteration_size = 100000 FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv | sample_size. each do | size | is_best_choice_count = 0 iteration_size. times do # population = ( 0.. population_size - 1 ) . to_a . sort_by { rand } # - sample = population. slice ( 0.. size - 1 ) rest_of_population = population [ size.. population_size - 1 ] # -? best_sample = sample. sort . last # best_next = rest_of_population. find { | i | i > best_sample } best_population = population. sort . last # ? is_best_choice_count + = 1 if best_next == best_population end best_probability = is_best_choice_count. to_f / iteration_size. to_f csv << [ size, best_probability ] end end
- require 'rubygems'
- require 'faster_csv'
- population_size = 20
- sample_size = 0 .. population_size - 1
- iteration_size = 100000
- top = ( population_size - 5 ) .. ( population_size - 1 )
- FasterCSV. open ( 'optimal.csv' , 'w' ) do | csv |
- sample_size. each do | size |
- is_best_choice_count = 0
- is_top_choice_count = 0
- iteration_size. times do
- population = ( 0 .. population_size - 1 ) . to_a . sort_by { rand }
- sample = population. slice ( 0 .. size - 1 )
- rest_of_population = population [ size .. population_size - 1 ]
- best_sample = sample. sort . last
- best_next = rest_of_population. find { | i | i > best_sample }
- best_population = population. sort . last
- top_population = population. sort [ top ]
- is_best_choice_count + = 1 if best_next == best_population
- is_top_choice_count + = 1 if top_population. include ? best_next
- end
- best_probability = is_best_choice_count. to_f / iteration_size. to_f
- top_probability = is_top_choice_count. to_f / iteration_size. to_f
- csv << [ size, best_probability, top_probability ]
- end
- end
Source: https://habr.com/ru/post/285334/
All Articles