Module: Rya::CoreExtensions::Math
- Defined in:
- lib/rya/core_extensions.rb
Instance Method Summary collapse
Instance Method Details
#scale(val, old_min, old_max, new_min, new_max) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rya/core_extensions.rb', line 55 def scale val, old_min, old_max, new_min, new_max # This can happen if you use the mean across non-zero samples. if old_max - old_min == 0 # TODO better default value than this? (new_min + new_max) / 2; else ((((new_max - new_min) * (val - old_min)) / (old_max - old_min).to_f) + new_min) end end |