tmp commit - toward 0.0.1

This commit is contained in:
Your Name
2021-11-29 15:29:00 +01:00
parent beae301a58
commit fb16fc7f3a
38 changed files with 2790 additions and 1 deletions

29
pina/cube.py Normal file
View File

@@ -0,0 +1,29 @@
import numpy as np
from .chebyshev import chebyshev_roots
class Cube():
def __init__(self, bound):
self.bound = np.asarray(bound)
def discretize(self, n, mode='random'):
if mode == 'random':
pts = np.random.uniform(size=(n, self.bound.shape[0]))
elif mode == 'chebyshev':
pts = np.array([chebyshev_roots(n) *.5 + .5 for _ in range(self.bound.shape[0])])
grids = np.meshgrid(*pts)
pts = np.hstack([grid.reshape(-1, 1) for grid in grids])
elif mode == 'grid':
pts = np.array([np.linspace(0, 1, n) for _ in range(self.bound.shape[0])])
grids = np.meshgrid(*pts)
pts = np.hstack([grid.reshape(-1, 1) for grid in grids])
elif mode == 'lh' or mode == 'latin':
from scipy.stats import qmc
sampler = qmc.LatinHypercube(d=self.bound.shape[0])
pts = sampler.random(n)
# Scale pts
pts *= self.bound[:, 1] - self.bound[:, 0]
pts += self.bound[:, 0]
return pts