Class: AgeHierarchyTree
- Inherits:
-
AlgorithmBase
- Object
- AlgorithmBase
- AgeHierarchyTree
- Defined in:
- ../algorithm/age_hierarchy_tree.rb
Instance Attribute Summary (collapse)
-
- (Object) age_gap
Returns the value of attribute age_gap.
-
- (Object) aging_scheme
Returns the value of attribute aging_scheme.
-
- (Object) deme_size
Returns the value of attribute deme_size.
-
- (Object) dominance
readonly
Returns the value of attribute dominance.
-
- (Object) elite_size
Returns the value of attribute elite_size.
-
- (Object) layer_diagnostic
Returns the value of attribute layer_diagnostic.
-
- (Object) max_layers
Returns the value of attribute max_layers.
-
- (Object) report
Returns the value of attribute report.
Attributes inherited from AlgorithmBase
#init, #population_size, #probabilities, #termination
Instance Method Summary (collapse)
- - (Object) breeding(parents)
- - (Object) init_deme
- - (Object) setup(config)
- - (Object) sort_spea2(unsorted)
- - (Object) step
Methods inherited from AlgorithmBase
Instance Attribute Details
- (Object) age_gap
Returns the value of attribute age_gap
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def age_gap @age_gap end |
- (Object) aging_scheme
Returns the value of attribute aging_scheme
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def aging_scheme @aging_scheme end |
- (Object) deme_size
Returns the value of attribute deme_size
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def deme_size @deme_size end |
- (Object) dominance (readonly)
Returns the value of attribute dominance
92 93 94 |
# File '../algorithm/age_hierarchy_tree.rb', line 92 def dominance @dominance end |
- (Object) elite_size
Returns the value of attribute elite_size
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def elite_size @elite_size end |
- (Object) layer_diagnostic
Returns the value of attribute layer_diagnostic
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def layer_diagnostic @layer_diagnostic end |
- (Object) max_layers
Returns the value of attribute max_layers
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def max_layers @max_layers end |
- (Object) report
Returns the value of attribute report
91 92 93 |
# File '../algorithm/age_hierarchy_tree.rb', line 91 def report @report end |
Instance Method Details
- (Object) breeding(parents)
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File '../algorithm/age_hierarchy_tree.rb', line 174 def breeding( parents ) layer = sort_spea2( parents ) # xover, mutations children = [] while children.size + @elite_size < @deme_size parent1 = tournament(layer) # assuming the layer is sorted if rand < @probabilities['crossover'] parent2 = tournament(layer) child1, child2 = @crossover.crossover( parent1.genotype, parent2.genotype, parent1.track_support, parent2.track_support ) individual = @cfg.factory( 'individual', @mapper, child1 ) individual.parents( parent1, parent2 ) @invalid_individuals += 1 unless individual.valid? children << individual if individual.valid? individual = @cfg.factory( 'individual', @mapper, child2 ) individual.parents( parent1, parent2 ) @invalid_individuals += 1 unless individual.valid? children << individual if individual.valid? end if rand < @probabilities['mutation'] child = @mutation.mutation( parent1.genotype, parent1.track_support ) individual = @cfg.factory( 'individual', @mapper, child ) individual.parents( parent1 ) @invalid_individuals += 1 unless individual.valid? children << individual if individual.valid? end end @evaluator.run children if defined? @evaluator children end |
- (Object) init_deme
170 171 172 |
# File '../algorithm/age_hierarchy_tree.rb', line 170 def init_deme init_population( [], @deme_size ) end |
- (Object) setup(config)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File '../algorithm/age_hierarchy_tree.rb', line 94 def setup config super AlpsIndividual.age_gap @age_gap AlpsIndividual.aging_scheme @aging_scheme AlpsIndividual.layers @max_layers @report['age_limits'] << AlpsIndividual.age_limits.inspect SubPopulation.set_algo self @dominance = Dominance.new @population = [] @parents_stats = [] @layers = [[ SubPopulation.new ]] @report.next return @report end |
- (Object) sort_spea2(unsorted)
222 223 224 225 226 227 228 229 230 |
# File '../algorithm/age_hierarchy_tree.rb', line 222 def sort_spea2 unsorted # sort a layer by pareto strength layer = @dominance.rank_count( unsorted ).sort {|a,b| a.spea <=> b.spea } # extract individuals from dominance's shell layer.map! { |fields| fields.original } layer end |
- (Object) step
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File '../algorithm/age_hierarchy_tree.rb', line 114 def step @report << "--------- step #{@steps}" if AlpsIndividual.age_limits.include? @steps @report << "--------- opening a new layer" @layers.flatten.each { |deme| deme.level += 1 } new_layer = [] @layers.first.each do |parent| new_layer << SubPopulation.new(parent) new_layer << SubPopulation.new(parent) end @layers.unshift new_layer elsif @steps>0 reminder = @steps.divmod(@age_gap).last @layers.first.each_with_index do |deme,index| next unless reminder == index.divmod(@age_gap).last @report << "--------- restarting a deme #{deme.name}, index=#{index}" deme.restart end end # reporting @population = [] @layers.flatten.each { |deme| @population.concat deme.current } @report.report @population # breeding @layers.flatten.each { |deme| deme.breed } # pde, copying... @layers.flatten.each { |deme| deme.environmental } # layer diagnostic @report['deme_sizes'] << (@layers.flatten.map { |layer| layer.current.size }).inspect @layers.flatten.each_with_index do |deme,index| current = deme.current current.first.objective_symbols.each do |objective| values = current.map { |individual| individual.send(objective) } min, max, avg, n = Util.statistics values @report["deme_#{deme.name}_#{objective}"] << "min: #{min} max: #{max} avg: #{avg} n: #{n}" end end if @layer_diagnostic @report['numof_evaluations'] << @evaluator.jobs_processed if defined? @evaluator @report['individuals_generated'] << @mapper.mapped_count @steps += 1 @report.next return @report end |