Class: Biopsy::Distribution

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#sdObject (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

#drawObject

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_distributionObject

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_sdObject



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_minObject

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