Class: Experiment::Factorial

Inherits:
Base
  • Object
show all
Defined in:
lib/experiment/factorial.rb

Defined Under Namespace

Modules: DistributedFactorial

Instance Attribute Summary collapse

Attributes inherited from Base

#current_cv, #cvs, #dir, #output_file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

after_completion, #analyze_result!, #benchmark, #data_set, #done?, #measure, #run!, #test_data, #training_data

Constructor Details

#initialize(*args) ⇒ Factorial

Returns a new instance of Factorial.



45
46
47
48
# File 'lib/experiment/factorial.rb', line 45

def initialize(*args)
  super(*args)
  @params ||= {}
end

Instance Attribute Details

#parent_dirObject

Returns the value of attribute parent_dir.



43
44
45
# File 'lib/experiment/factorial.rb', line 43

def parent_dir
  @parent_dir
end

Class Method Details

.param(name, value = nil, &block) ⇒ Object Also known as: independent_variable

Specify a parameter that will be used as a factor in the experiment

Examples:

param :decay_rate, [0.1, 0.3, 0.7]
param :photons, [5, 10]
# runs these 6 experiments:
# | decay_rate | photons
# |        0.1 |   5
# |        0.1 |  10
# |        0.3 |   5
# |        0.3 |  10
# |        0.7 |   5
# |        0.7 |  10

Contrived example of block usage

param :user_iq do
  mean = gets "How much is 1 + 1?"
  if mean == '2'
    (100..160).to_a
  else
    (20..30).to_a
  end
end

See Also:



31
32
33
34
35
36
37
38
# File 'lib/experiment/factorial.rb', line 31

def param(name, value = nil, &block)
  @@params ||= {}
  if block_given?
    @@params[name] = block.call
  else
    @@params[name] = value
   end
end

Instance Method Details

#normal_run!(cv) ⇒ Object

runs the whole experiment



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/experiment/factorial.rb', line 52

def normal_run!(cv)
	@cvs = cv || 1
   @results = {}
   puts "Running #{@experiment} with #{param_grid.length} experiments at #{cv} cross validations each..."
	#experiments = Notify.total / cv
	#Notify.total = (experiments - 1) * cv + cv * param_grid.length
	#
   Notify::init param_grid.length * @options.cv, STDOUT, Experiment::Config::get(:growl_notifications, false)
   split_up_data
	write_dir!
   param_grid.each do |paramset|
     Params.set paramset
     results = {}
     Notify.started @experiment + ' ' + param_string(paramset, ", ")
     @cvs.times do |cv_num|
 			@bm = []
 			@current_cv = cv_num
 			File.open(@dir + "/raw-#{param_string(paramset)}-#{cv_num}.txt", "w") do |output|
 			  @ouptut_file = output
 			    run_the_experiment(@data[cv_num], output)
 			end
 			array_merge results, analyze_result!(@dir + "/raw-#{param_string(paramset)}-#{cv_num}.txt", @dir + "/analyzed-#{param_string(paramset)}-#{cv_num}.txt")
 			write_performance!

 			Notify.cv_done @experiment + ' ' + param_string(paramset, ", "), cv_num
 			#Notify.inc step
 			
 		end
 		#print '.'
 		Notify.completed @experiment + ' ' + param_string(paramset, ", ")
 		
 		@results[paramset] = results
   end
	Notify::done
	specification!
	summarize_performance!
	summarize_results! @results
	cleanup!
	
	puts File.read(@dir + "/summary.mmd") if @options.summary
end