Class: Biopsy::Distribution
- Inherits:
-
Object
- Object
- Biopsy::Distribution
- Defined in:
- lib/biopsy/optimisers/tabu_search.rb
Overview
a Distribution represents the probability distribution from which the next value of a parameter is drawn. The set of all distributions acts as a probabilistic neighbourhood structure.
Instance Attribute Summary collapse
-
#sd ⇒ Object
readonly
Returns the value of attribute sd.
Instance Method Summary collapse
-
#draw ⇒ Object
draw from the distribution.
-
#generate_distribution ⇒ Object
generate the distribution.
-
#initialize(mean, range, sd_increment_proportion, sd) ⇒ Distribution
constructor
create a new Distribution.
- #limit_sd ⇒ Object
-
#loosen(factor = 1) ⇒ Object
loosen the distribution by increasing the sd and regenerating.
-
#set_sd_min ⇒ Object
set standard deviation to the minimum possible value.
-
#tighten(factor = 1) ⇒ Object
tighten the distribution by reducing the sd and regenerating.
Constructor Details
#initialize(mean, range, sd_increment_proportion, sd) ⇒ Distribution
create a new Distribution
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 24 def initialize(mean, range, sd_increment_proportion, sd) @mean = mean @maxsd = range.size * 0.66 @minsd = 0.5 @sd = sd self.limit_sd @range = range @sd_increment_proportion = sd_increment_proportion self.generate_distribution rescue raise "generation of distribution with mean: #{@mean}, sd: #{@sd} failed." end |
Instance Attribute Details
#sd ⇒ Object (readonly)
Returns the value of attribute sd.
21 22 23 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 21 def sd @sd end |
Instance Method Details
#draw ⇒ Object
draw from the distribution
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 69 def draw r = @dist.rng.to_i raise "drawn number must be an integer" unless r.is_a? Integer # keep the value inside the allowed range r = 0 - r if r < 0 if r >= @range.size diff = 1 + r - @range.size r = @range.size - diff end @range[r] end |
#generate_distribution ⇒ Object
generate the distribution
38 39 40 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 38 def generate_distribution @dist = Rubystats::NormalDistribution.new(@mean, @sd) end |
#limit_sd ⇒ Object
42 43 44 45 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 42 def limit_sd @sd = @sd > @maxsd ? @maxsd : @sd @sd = @sd < @minsd ? @minsd : @sd end |
#loosen(factor = 1) ⇒ Object
loosen the distribution by increasing the sd and regenerating
49 50 51 52 53 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 49 def loosen(factor=1) @sd += @sd_increment_proportion * factor * @range.size self.limit_sd self.generate_distribution end |
#set_sd_min ⇒ Object
set standard deviation to the minimum possible value
64 65 66 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 64 def set_sd_min @sd = @minsd end |
#tighten(factor = 1) ⇒ Object
tighten the distribution by reducing the sd and regenerating
57 58 59 60 61 |
# File 'lib/biopsy/optimisers/tabu_search.rb', line 57 def tighten(factor=1) @sd -= @sd_increment_proportion * factor * @range.size unless (@sd <= 0.01) self.limit_sd self.generate_distribution end |