Skip to content

Commit

Permalink
Add scale_exp_lin()
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Aug 9, 2024
1 parent 09ee319 commit ca2f4cb
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions isobar/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,29 @@ def scale_lin_lin(value: float,
Returns:
The scaled value.
"""
norm = float(value - from_min) / (from_max - from_min)
return norm * float(to_max - to_min) + to_min
norm = (value - from_min) / (from_max - from_min)
return norm * (to_max - to_min) + to_min

def scale_exp_lin(value: float,
from_min: float,
from_max: float,
to_min: float,
to_max: float) -> float:
"""
Map a value on an exponential scale to a linear scale.
Args:
value: The value
from_min: The lower bound of the input range
from_max: The upper bound of the input range
to_min: The lower bound of the output range
to_max: The upper bound of the output range
Returns:
The scaled value.
"""
norm = (math.log(value / from_min)) / (math.log(from_max / from_min))
return norm * (to_max - to_min) + to_min

def bipolar_diverge(maximum: int) -> list[int]:
"""
Expand Down

0 comments on commit ca2f4cb

Please sign in to comment.