-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurrogate.py
More file actions
82 lines (57 loc) · 2.3 KB
/
Copy pathsurrogate.py
File metadata and controls
82 lines (57 loc) · 2.3 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
import equinox as eqx
import jax
import jax.numpy as jnp
class LiftSurrogateModel(eqx.Module):
layers: list
def __init__(self, in_size, out_size, width_size, depth, activation, key):
keys = jax.random.split(key, depth + 2)
input_key = keys[0]
output_key = keys[-1]
hidden_keys = keys[1:-1]
input_layer = eqx.nn.Linear(in_size, width_size, key=input_key)
output_layer = eqx.nn.Linear(width_size, out_size, key=output_key)
self.layers = [
jax.nn.standardize, #Standardize -1 to 1
input_layer,
activation
]
for key in hidden_keys:
self.layers.append(eqx.nn.Linear(width_size, width_size, key=key))
self.layers.append(activation)
self.layers.append(output_layer)
def __call__(self, x):
for layer in self.layers:
x = layer(x)
return x
#Define the structure for the neural network
class DragSurrogateModel(eqx.Module):
layers: list
def __init__(self, in_size, out_size, width_size, depth, activation, key):
keys = jax.random.split(key, depth + 2)
input_key = keys[0]
output_key = keys[-1]
hidden_keys = keys[1:-1]
input_layer = eqx.nn.Linear(in_size, width_size, key=input_key)
output_layer = eqx.nn.Linear(width_size, out_size, key=output_key)
#Make Reynolds number on log10 scale
@jax.jit
def normalize_reynolds_number(x):
Re = x[-1]
Re = jnp.log10(Re)
#Set maximum of Re=10^6
Re = jnp.min(jnp.hstack((Re, 6)))
return jnp.hstack((x[:-1], Re))
self.layers = [
normalize_reynolds_number,
jax.nn.standardize, #Standardize -1 to 1
input_layer,
activation
]
for key in hidden_keys:
self.layers.append(eqx.nn.Linear(width_size, width_size, key=key))
self.layers.append(activation)
self.layers.append(output_layer)
def __call__(self, x):
for layer in self.layers:
x = layer(x)
return x