-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathGeneratorPoints.py
50 lines (44 loc) · 1.85 KB
/
GeneratorPoints.py
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
import numpy as np
import sobol_seq
import torch
def generator_points(samples, dim, random_seed, type_of_points, boundary):
if type_of_points == "random":
torch.random.manual_seed(random_seed)
return torch.rand([samples, dim]).type(torch.FloatTensor)
# elif type_of_points == "lhs":
# return torch.from_numpy(lhs(dim, samples=samples, criterion='center')).type(torch.FloatTensor)
elif type_of_points == "gauss":
if samples != 0:
x, _ = np.polynomial.legendre.leggauss(samples)
x = 0.5 * (x.reshape(-1, 1) + 1)
if dim == 1:
return torch.from_numpy(x).type(torch.FloatTensor)
if dim == 2:
x = x.reshape(-1, )
x = np.transpose([np.repeat(x, len(x)), np.tile(x, len(x))])
return torch.from_numpy(x).type(torch.FloatTensor)
else:
return torch.zeros([0, dim])
elif type_of_points == "grid":
if samples != 0:
x = np.linspace(0, 1, samples + 2)
x = x[1:-1].reshape(-1, 1)
if dim == 1:
return torch.from_numpy(x).type(torch.FloatTensor)
if dim == 2:
x = x.reshape(-1, )
if not boundary:
x = np.transpose([np.tile(x, len(x)), np.repeat(x, len(x))])
else:
x = np.concatenate([x.reshape(-1, 1), x.reshape(-1, 1)], 1)
print(x)
return torch.from_numpy(x).type(torch.FloatTensor)
else:
return torch.zeros([0, dim])
elif type_of_points == "sobol":
skip = random_seed
data = np.full((samples, dim), np.nan)
for j in range(samples):
seed = j + skip
data[j, :], next_seed = sobol_seq.i4_sobol(dim, seed)
return torch.from_numpy(data).type(torch.FloatTensor)