Skip to content

Commit

Permalink
Port more of my math methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Nov 3, 2022
1 parent 74b10c8 commit 5ddf96b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pymanifold/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@ def number_to_prob_cpmm1(current: float, start: float, end: float, isLogScale: b
if isLogScale:
return log10(current - start + 1) / log10(end - start + 1)
return (current - start) / (end - start)


def pool_to_prob_cpmm1(yes: float, no: float, p: float) -> float:
"""Go from a pool of YES/NO to a probability using Maniswap."""
if yes <= 0 or no <= 0 or not (0 < p < 1):
raise ValueError()
pno = p * no
return pno / ((1 - p) * yes + pno)


def pool_to_number_cpmm1(yes: float, no: float, p: float, start: float, end: float, isLogScale: bool = False) -> float:
"""Go from a pool of probability to a numeric answer."""
if start >= end:
raise ValueError()
probability = pool_to_prob_cpmm1(yes, no, p)
return prob_to_number_cpmm1(probability, start, end, isLogScale)


def prob_to_number_cpmm1(probability: float, start: float, end: float, isLogScale: bool = False) -> float:
"""Go from a probability to a numeric answer."""
if isLogScale:
ret: float = (end - start + 1)**probability + start - 1
else:
ret = start + (end - start) * probability
ret = max(start, min(end, ret))
return ret

0 comments on commit 5ddf96b

Please sign in to comment.