Class: Biopsy::Hood
- Inherits:
-
Object
- Object
- Biopsy::Hood
- Defined in:
- lib/biopsy/optimisers/tabu_search.rb
Overview
a Hood represents the neighbourhood of a specific location in the parameter space being explored. It is generated using the set of Distributions, which together define the neighbourhood structure.
Instance Attribute Summary collapse
-
#best ⇒ Object
readonly
Returns the value of attribute best.
Instance Method Summary collapse
-
#generate_neighbour ⇒ Object
generate a single neighbour.
-
#initialize(distributions, max_size, tabu) ⇒ Hood
constructor
A new instance of Hood.
-
#is_tabu?(location) ⇒ Boolean
true if location is tabu.
-
#last? ⇒ Boolean
returns true if the current neighbour is the last one in the Hood.
-
#next ⇒ Object
return the next neighbour from this Hood.
-
#populate ⇒ Object
generate the population of neighbours.
-
#update_best?(current) ⇒ Boolean
update best?.
Constructor Details
#initialize(distributions, max_size, tabu) ⇒ Hood
Returns a new instance of Hood.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 91 def initialize(distributions, max_size, tabu) # tabu @tabu = tabu # neighbourhood @max_size = max_size @members = [] @best = { :parameters => nil, :score => 0.0 } # probabilities @distributions = distributions self.populate end |
Instance Attribute Details
#best ⇒ Object (readonly)
Returns the value of attribute best.
89 90 91 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 89 def best @best end |
Instance Method Details
#generate_neighbour ⇒ Object
generate a single neighbour
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 107 def generate_neighbour n = 0 begin if n >= 100 # taking too long to generate a neighbour, # loosen the neighbourhood structure so we explore further # debug("loosening distributions") @distributions.each do |param, dist| dist.loosen end end # preform the probabilistic step move for each parameter neighbour = Hash[@distributions.map { |param, dist| [param, dist.draw] }] n += 1 end while self.is_tabu?(neighbour) @tabu << neighbour @members << neighbour end |
#is_tabu?(location) ⇒ Boolean
true if location is tabu
132 133 134 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 132 def is_tabu? location @tabu.member? location end |
#last? ⇒ Boolean
returns true if the current neighbour is the last one in the Hood
150 151 152 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 150 def last? @members.empty? end |
#next ⇒ Object
return the next neighbour from this Hood
144 145 146 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 144 def next @members.pop end |
#populate ⇒ Object
generate the population of neighbours
137 138 139 140 141 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 137 def populate @max_size.times do |i| self.generate_neighbour end end |
#update_best?(current) ⇒ Boolean
update best?
127 128 129 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 127 def update_best? current @best = current.clone if current[:score] > @best[:score] end |