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
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rya/core_extensions.rb', line 23 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 |