feldtruby 0.3.18 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +11 -1
- data/lib/feldtruby/array/basic_stats.rb +5 -0
- data/lib/feldtruby/logger.rb +22 -10
- data/lib/feldtruby/optimize/differential_evolution.rb +8 -8
- data/lib/feldtruby/optimize/objective.rb +361 -334
- data/lib/feldtruby/optimize/optimizer.rb +7 -8
- data/lib/feldtruby/version.rb +1 -1
- data/spikes/comparing_samplers_on_classic_optimization_functions/compare_samplers.rb +0 -76
- data/test/helper.rb +7 -2
- data/test/long_running/multi_objective_problems.rb +58 -0
- data/test/long_running/single_objective_problems.rb +163 -0
- data/test/long_running/test_single_objective_optimization.rb +112 -0
- data/test/test_array_basic_stats.rb +20 -12
- data/test/test_logger.rb +4 -4
- data/test/test_optimize_objective.rb +175 -119
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d26d52d618b786234ccdce29a35965776806697c
|
4
|
+
data.tar.gz: 7df492becb40e830a2dfc72099a0f00b14321803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3780f3a073bfd81db3c25afcd28b464bf04df82445e37ac00a6117eec023b09fa424001cc9aff66a0fc9b0ba3939aeacadf558c118798e7db3f5d18c985a6bc1
|
7
|
+
data.tar.gz: 704149c43950a6893da57311593edbd77dc392a27ef83979cf2b88d62d8a495c1878e9748f36f7cb206f74fbdcd12a567c0621003d13c409e869ae1dd54f7de4
|
data/Rakefile
CHANGED
@@ -21,8 +21,18 @@ task :test_sep do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
desc "Run all tests"
|
24
|
+
desc "Run all normal tests"
|
25
25
|
task :test do
|
26
|
+
run_tests Dir["test/test*.rb"]
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Run long-running tests"
|
30
|
+
task :testlong do
|
31
|
+
run_tests Dir["test/long_running/test*.rb"]
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run all tests"
|
35
|
+
task :testall do
|
26
36
|
run_tests Dir["test/**/test*.rb"]
|
27
37
|
end
|
28
38
|
|
@@ -129,6 +129,11 @@ module BasicStatistics
|
|
129
129
|
sum
|
130
130
|
end
|
131
131
|
|
132
|
+
# Root mean square from another vector
|
133
|
+
def rms_from(other)
|
134
|
+
Math.sqrt(sum_squared_error(other))
|
135
|
+
end
|
136
|
+
|
132
137
|
# Return summary stats for an array of numbers.
|
133
138
|
def summary_stats
|
134
139
|
return "" if length == 0
|
data/lib/feldtruby/logger.rb
CHANGED
@@ -8,8 +8,8 @@ module FeldtRuby
|
|
8
8
|
# Simplest possible logger only prints to STDOUT.
|
9
9
|
class Logger
|
10
10
|
DefaultParams = {
|
11
|
-
:verbose =>
|
12
|
-
:
|
11
|
+
:verbose => false,
|
12
|
+
:printFrequency => 0.0 # Minimum seconds between consecutive messages printed for the same event type
|
13
13
|
}
|
14
14
|
|
15
15
|
UnixEpoch = Time.at(0)
|
@@ -24,7 +24,7 @@ class Logger
|
|
24
24
|
|
25
25
|
self.verbose = @params[:verbose]
|
26
26
|
|
27
|
-
self.print_frequency = @params[:
|
27
|
+
self.print_frequency = @params[:printFrequency]
|
28
28
|
|
29
29
|
@ios = []
|
30
30
|
|
@@ -62,7 +62,7 @@ class Logger
|
|
62
62
|
|
63
63
|
# Set the minimum time between printing successive messages of the same type.
|
64
64
|
def print_frequency=(seconds = 1.0)
|
65
|
-
@print_frequency = @params[:
|
65
|
+
@print_frequency = @params[:printFrequency] = seconds
|
66
66
|
end
|
67
67
|
|
68
68
|
# Add one more _io_ stream to which events are logged.
|
@@ -113,7 +113,11 @@ class Logger
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# Log a data event.
|
116
|
-
def log_data eventType, data, message = nil
|
116
|
+
def log_data eventType, data, message = nil, tagWithData = false
|
117
|
+
if tagWithData
|
118
|
+
dstr = data.keys.map {|k| "#{k}: #{data[k]}"}.join("\n ")
|
119
|
+
message += "\n #{dstr}"
|
120
|
+
end
|
117
121
|
log_event eventType, {"d" => data}, message
|
118
122
|
end
|
119
123
|
|
@@ -157,7 +161,7 @@ class Logger
|
|
157
161
|
|
158
162
|
elapsed_str = Time.human_readable_timestr elapsed_time(time)
|
159
163
|
|
160
|
-
s = time.strftime("\n%H:%M.%S
|
164
|
+
s = time.strftime("\n%H:%M.%S (#{elapsed_str}), ") + message
|
161
165
|
|
162
166
|
@ios.each {|io| io.puts s}
|
163
167
|
|
@@ -171,7 +175,15 @@ end
|
|
171
175
|
module Logging
|
172
176
|
attr_accessor :logger
|
173
177
|
|
174
|
-
def setup_logger_and_distribute_to_instance_variables(
|
178
|
+
def setup_logger_and_distribute_to_instance_variables(loggerOrOptions = nil)
|
179
|
+
|
180
|
+
if Hash === loggerOrOptions
|
181
|
+
options = loggerOrOptions
|
182
|
+
logger = nil
|
183
|
+
else
|
184
|
+
options = {}
|
185
|
+
logger = loggerOrOptions
|
186
|
+
end
|
175
187
|
|
176
188
|
# Precedence for loggers if several has been setup:
|
177
189
|
# 1. One specified as parameter to this method
|
@@ -179,7 +191,7 @@ module Logging
|
|
179
191
|
# 3. First one found on an instance var
|
180
192
|
# 4. Create a new standard one
|
181
193
|
self.logger = logger || self.logger || __find_logger_set_on_instance_vars() ||
|
182
|
-
new_default_logger()
|
194
|
+
new_default_logger(options)
|
183
195
|
|
184
196
|
# Now distribute the preferred logger to all instance vars, recursively.
|
185
197
|
self.instance_variables.each do |ivar_name|
|
@@ -195,8 +207,8 @@ module Logging
|
|
195
207
|
end
|
196
208
|
|
197
209
|
# Override to use another logger as default if no logger is found.
|
198
|
-
def new_default_logger
|
199
|
-
FeldtRuby::Logger.new
|
210
|
+
def new_default_logger(options = {})
|
211
|
+
FeldtRuby::Logger.new(STDOUT, options)
|
200
212
|
end
|
201
213
|
|
202
214
|
# Find a logger if one has been set on any of my instance vars or their
|
@@ -60,20 +60,20 @@ class DEOptimizerBase < EvolutionaryOptimizer
|
|
60
60
|
|
61
61
|
best, worst = objective.rank_candidates([target, trial])
|
62
62
|
|
63
|
-
# Supplant the target vector with the trial vector if better
|
63
|
+
# Supplant the target vector with the trial vector if trial vector is better.
|
64
64
|
if best != target
|
65
65
|
logger.log_data :better_candidate_found, {
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
"Trial" => trial,
|
67
|
+
"Trial Quality" => @objective.quality_of(trial),
|
68
|
+
"Target" => target,
|
69
|
+
"Target Quality" => @objective.quality_of(target)
|
70
|
+
}, "DE (step #{@num_optimization_steps}): Trial vector was better than target vector"
|
69
71
|
update_candidate_in_population(target_index, trial)
|
72
|
+
feedback_on_trial_vs_target(trial, target, true)
|
70
73
|
else
|
71
|
-
|
74
|
+
feedback_on_trial_vs_target(trial, target, false)
|
72
75
|
end
|
73
76
|
|
74
|
-
# Give feedback to strategy since some strategies use this to self-adapt
|
75
|
-
feedback_on_trial_vs_target(trial, target, trial_better)
|
76
|
-
|
77
77
|
[best]
|
78
78
|
end
|
79
79
|
|