Class: EncodingEstimator::RangeScale

Inherits:
Object
  • Object
show all
Defined in:
lib/encoding_estimator/detector.rb

Overview

Represent a function the maps a value between min and max to 0..1

Instance Method Summary collapse

Constructor Details

#initialize(min, max) ⇒ RangeScale

Initialize a new object from the range minimum and maximum

Parameters:

  • min (Float)

    The range’s minimum

  • max (Float)

    The range’s maximum



16
17
18
19
20
21
22
23
# File 'lib/encoding_estimator/detector.rb', line 16

def initialize( min, max )
  @min = min
  @max = max

  if max == min
    @min = min - 1.0
  end
end

Instance Method Details

#scale(value) ⇒ Float

Map the given value to a range between 0 and 1 (min is 0, max is 1)

Parameters:

  • value (Float)

    Value to map between 0 and 1

Returns:

  • (Float)

    The mapped value between 0 and 1



30
31
32
# File 'lib/encoding_estimator/detector.rb', line 30

def scale( value )
  ( value - @min ) / ( @max - @min )
end