move a couple math functions into their own file

This commit is contained in:
Connor Olding 2023-05-07 06:55:46 -07:00
parent 258c42d963
commit c36aead212
5 changed files with 27 additions and 25 deletions

View File

@ -1,5 +1,6 @@
from .closures import *
from .colors import *
from .math import *
from .prog80 import prog
from .scoring import *
from .utils import *

View File

@ -1,4 +1,4 @@
from .utils import scalar_softplus
from .math import scalar_softplus
from .utils_np import do_bounding
check = object() # secret "key" to pass to wrap_untrustworthy to extract feval_count

View File

@ -0,0 +1,23 @@
import math
feps = 2.0**-23.0
tiniest = 2.0**-1022.0
def scalar_softplus(x):
if x >= 33.276435657655455:
return float(x)
elif x <= -745.13330078125:
return 0.0
else:
return math.log1p(math.exp(x))
def phi(d):
# phi(1) = golden ratio
# phi(2) = plastic constant
# phi(3) = the positive real root of x**4-x-1
x = 2.0
for i in range(30 if d == 1 else max(10, 28 - d)):
x = pow(1 + x, 1 / (d + 1))
return x

View File

@ -1,27 +1,4 @@
from dataclasses import dataclass
import math
feps = 2.0**-23.0
tiniest = 2.0**-1022.0
def scalar_softplus(x):
if x >= 33.276435657655455:
return float(x)
elif x <= -745.13330078125:
return 0.0
else:
return math.log1p(math.exp(x))
def phi(d):
# phi(1) = golden ratio
# phi(2) = plastic constant
# phi(3) = the positive real root of x**4-x-1
x = 2.0
for i in range(30 if d == 1 else max(10, 28 - d)):
x = pow(1 + x, 1 / (d + 1))
return x
@dataclass

View File

@ -1,6 +1,7 @@
# i've separated numpy-dependent methods from the rest of the utils.
from .colors import m33, m34, m93
from .utils import AcquireForWriting, merge_summaries, feps
from .math import feps
from .utils import AcquireForWriting, merge_summaries
from time import time
import numpy as np