-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
100 lines (94 loc) · 2.87 KB
/
utils.py
File metadata and controls
100 lines (94 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import numpy as np
kappa_hat=1
# FUNCTIONS
def heaviside(x):
return np.heaviside(x,1)
def m1(x):
return min(x,1-x)
def r2(p):
return float('%.2g' % p)
def r3(p):
return float('%.3g' % p)
def m3(p):
if p==1.0:
return 1
else:
return float('%.3g' % min(p,1-p))
minn=np.vectorize(min)
def ramp(x):
#return minn(1,x)
return x*(x<1)+(x>1)
def relu(x):
return x*heaviside(x)
def rampup(x):
return heaviside(x)*minn(1,x)
def signs(P_list):
say=''.join([P_rims[i][P_list[i]] for i in range(len(P_list))])
if say.strip()=='':
return 'au naturale'
else:
return say
def stamp(L):
if not isinstance(L,np.ndarray):
return L
s = list(L.shape)
#if len(s)==1:
# l = L[0]
#elif len(s)==2:
# l = L[0][0]
l = np.mean(L)
if type(l)!=np.float64:
l = np.mean(l)
return tuple(s+[l])
def cachewrap(f):
cachedict=dict()
def fwrap(*args):
T=tuple([str(f)]+
[stamp(k) for k in args])
T = tuple([t if not isinstance(t,np.ndarray)
else np.mean(t) for t in T])
if T in cachedict:
return cachedict[T]
else:
O = f(*args)
cachedict[T] = O
return O
return fwrap
P_primes=[[' ',' photo','yellow'],
[' ',' TL',' ~TL'],
[' ',' conv'],
[' ',' bio'],
[' ',' plates'],
[' ',' HJ','hj-pd'],
[' ',' GI',' iso'],
[' ',' temp'],
[' ',' time'],
[' ',' area'],
[' ',' S',' C',' min(S,C)'],
[' ',' O2down',' O2up',' O2both'],
[' ',' setback',' IDH',' reset'],
[' ',' comets',],
[' ',' grbs'],
[' ',' glac'],
[' ',' vol'],
[' ',' metal'],
[' ',' C/O',' Mg/Si'],
[' ',' nitrogen',' phosphorus',' sulfur'],
[' ',' iron'],
[' ',' eccentricity'],
[' ',' obliquity'],
[' ',' h2o(asteroids)',' h2o(grand tack)',
' h2o(comets)',' h2o(magma ocean)'],
[' ',' atm',' slow rot'],
[' ',' B'],
['',' lightning', ' SEP', ' XUV', ' vents', ' IDP',' comets',
' asteroids', ' moneta',' plan pans',' stel pans'],
['',' K/Na/Cl pumps', ' ice floats', ' viscosity increased 23%',
' viscosity + ice', ' al26', ' water weight'],
[' ',' binary'],
[' ',' icy moons'],
[' ',' rogue'],
[' ',' sfr'],
[' ',' disrupt',' SN',' agn'],
[' ',' guest',' tseug']]
P_rims = [[p[0].strip()]+p[1:] for p in P_primes]