Skip to content

Commit

Permalink
relocate min_max_scale function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-harder committed Dec 16, 2024
1 parent 1ca5dde commit e44cecb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
15 changes: 15 additions & 0 deletions assume/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,3 +682,18 @@ def calculate_content_size(content: list | dict) -> int:
calculate_content_size(item) for item in content
)
return sys.getsizeof(content)


def min_max_scale(x, min_val: float, max_val: float):
"""
Min-Max scaling of a value x to the range [0, 1]
Args:
x: value(s) to scale
min_val: minimum value of the parameter
max_val: maximum value of the parameter
"""
# Avoid division by zero
if min_val == max_val:
return x
return (x - min_val) / (max_val - min_val)
15 changes: 0 additions & 15 deletions assume/reinforcement_learning/learning_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,6 @@ def polyak_update(params, target_params, tau: float):
th.add(target_param.data, param.data, alpha=tau, out=target_param.data)


def min_max_scale(x, min_val: float, max_val: float):
"""
Min-Max scaling of a value x to the range [0, 1]
Args:
x: value(s) to scale
min_val: minimum value of the parameter
max_val: maximum value of the parameter
"""
# Avoid division by zero
if min_val == max_val:
return x
return (x - min_val) / (max_val - min_val)


def linear_schedule_func(
start: float, end: float = 0, end_fraction: float = 1
) -> Schedule:
Expand Down
3 changes: 1 addition & 2 deletions assume/strategies/learning_advanced_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from assume.common.base import SupportsMinMax
from assume.common.market_objects import MarketConfig, Orderbook, Product
from assume.common.utils import get_products_index
from assume.reinforcement_learning.learning_utils import min_max_scale
from assume.common.utils import get_products_index, min_max_scale
from assume.strategies.learning_strategies import RLStrategy


Expand Down
6 changes: 2 additions & 4 deletions assume/strategies/learning_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

from assume.common.base import LearningStrategy, SupportsMinMax, SupportsMinMaxCharge
from assume.common.market_objects import MarketConfig, Orderbook, Product
from assume.common.utils import min_max_scale
from assume.reinforcement_learning.algorithms import actor_architecture_aliases
from assume.reinforcement_learning.learning_utils import (
NormalActionNoise,
min_max_scale,
)
from assume.reinforcement_learning.learning_utils import NormalActionNoise

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit e44cecb

Please sign in to comment.