amarorn / models /math_utils.py
beAnalytic's picture
feat: sync main with feature/superbet-live-inplay
16c19b8 verified
Raw
History Blame Contribute Delete
448 Bytes
import math
def sigmoid(x: float) -> float:
if x >= 0:
return 1.0 / (1.0 + math.exp(-x))
exp_x = math.exp(x)
return exp_x / (1.0 + exp_x)
def softmax(values: list[float]) -> list[float]:
if not values:
return []
max_v = max(values)
exps = [math.exp(v - max_v) for v in values]
total = sum(exps)
if total <= 0:
return [1.0 / len(values)] * len(values)
return [e / total for e in exps]