本文整理汇总了Python中pyDOE.lhs方法的典型用法代码示例。如果您正苦于以下问题:Python pyDOE.lhs方法的具体用法?Python pyDOE.lhs怎么用?Python pyDOE.lhs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyDOE
的用法示例。
在下文中一共展示了pyDOE.lhs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_samples
# 需要导入模块: import pyDOE [as 别名]
# 或者: from pyDOE import lhs [as 别名]
def get_samples(self, point_count: int) -> np.ndarray:
"""
Generates requested amount of points.
:param point_count: Number of points required.
:return: A numpy array of generated samples, shape (point_count x space_dim)
"""
bounds = self.parameter_space.get_bounds()
X_design_aux = pyDOE.lhs(len(bounds), point_count, criterion='center')
ones = np.ones((X_design_aux.shape[0], 1))
lower_bound = np.asarray(bounds)[:, 0].reshape(1, len(bounds))
upper_bound = np.asarray(bounds)[:, 1].reshape(1, len(bounds))
diff = upper_bound - lower_bound
X_design = np.dot(ones, lower_bound) + X_design_aux * np.dot(ones, diff)
samples = self.parameter_space.round(X_design)
return samples
示例2: _lhs_init
# 需要导入模块: import pyDOE [as 别名]
# 或者: from pyDOE import lhs [as 别名]
def _lhs_init(par_names, bounds, samples, criterion='c'):
"""
Returns LHS samples.
:param par_names: List of parameter names
:type par_names: list(str)
:param bounds: List of lower/upper bounds,
must be of the same length as par_names
:type bounds: list(tuple(float, float))
:param int samples: Number of samples
:param str criterion: A string that tells lhs how to sample the
points. See docs for pyDOE.lhs().
:return: DataFrame
"""
lhs = doe.lhs(len(par_names), samples=samples, criterion='c')
par_vals = {}
for par, i in zip(par_names, range(len(par_names))):
par_min = bounds[i][0]
par_max = bounds[i][1]
par_vals[par] = lhs[:, i] * (par_max - par_min) + par_min
# Convert dict(str: np.ndarray) to pd.DataFrame
par_df = pd.DataFrame(columns=par_names, index=np.arange(samples))
for i in range(samples):
for p in par_names:
par_df.loc[i, p] = par_vals[p][i]
logger = logging.getLogger(GA.__name__)
logger.info('Initial guess based on LHS:\n{}'.format(par_df))
return par_df
示例3: main_loop
# 需要导入模块: import pyDOE [as 别名]
# 或者: from pyDOE import lhs [as 别名]
def main_loop(N_u, N_f, num_layers, num_neurons):
nu = 0.01/np.pi
layers = np.concatenate([[2], num_neurons*np.ones(num_layers), [1]]).astype(int).tolist()
data = scipy.io.loadmat('../Data/burgers_shock.mat')
t = data['t'].flatten()[:,None]
x = data['x'].flatten()[:,None]
Exact = np.real(data['usol']).T
X, T = np.meshgrid(x,t)
X_star = np.hstack((X.flatten()[:,None], T.flatten()[:,None]))
u_star = Exact.flatten()[:,None]
# Doman bounds
lb = X_star.min(0)
ub = X_star.max(0)
xx1 = np.hstack((X[0:1,:].T, T[0:1,:].T))
uu1 = Exact[0:1,:].T
xx2 = np.hstack((X[:,0:1], T[:,0:1]))
uu2 = Exact[:,0:1]
xx3 = np.hstack((X[:,-1:], T[:,-1:]))
uu3 = Exact[:,-1:]
X_u_train = np.vstack([xx1, xx2, xx3])
X_f_train = lb + (ub-lb)*lhs(2, N_f)
X_f_train = np.vstack((X_f_train, X_u_train))
u_train = np.vstack([uu1, uu2, uu3])
idx = np.random.choice(X_u_train.shape[0], N_u, replace=False)
X_u_train = X_u_train[idx, :]
u_train = u_train[idx,:]
model = PhysicsInformedNN(X_u_train, u_train, X_f_train, layers, lb, ub, nu)
start_time = time.time()
model.train()
elapsed = time.time() - start_time
print('Training time: %.4f' % (elapsed))
u_pred, f_pred = model.predict(X_star)
error_u = np.linalg.norm(u_star-u_pred,2)/np.linalg.norm(u_star,2)
return error_u
示例4: latin_sampler
# 需要导入模块: import pyDOE [as 别名]
# 或者: from pyDOE import lhs [as 别名]
def latin_sampler(locator, num_samples, variables):
"""
This script creates a matrix of m x n samples using the latin hypercube sampler.
for this, it uses the database of probability distribtutions stored in locator.get_uncertainty_db()
:param locator: pointer to locator of files of CEA
:param num_samples: number of samples to do
:param variables: list of variables to sample
:return:
1. design: a matrix m x n with the samples
2. pdf_list: a dataframe with properties of the probability density functions used in the excercise.
"""
# get probability density function PDF of variables of interest
variable_groups = ('ENVELOPE', 'INDOOR_COMFORT', 'INTERNAL_LOADS')
database = pd.concat([pd.read_excel(locator.get_uncertainty_db(), group, axis=1)
for group in variable_groups])
pdf_list = database[database['name'].isin(variables)].set_index('name')
# get number of variables
num_vars = pdf_list.shape[0] #alternatively use len(variables)
# get design of experiments
design = lhs(num_vars, samples=num_samples)
for i, variable in enumerate(variables):
distribution = pdf_list.loc[variable, 'distribution']
min = pdf_list.loc[variable,'min']
max = pdf_list.loc[variable,'max']
mu = pdf_list.loc[variable,'mu']
stdv = pdf_list.loc[variable,'stdv']
if distribution == 'triangular':
loc = min
scale = max - min
c = (mu - min) / (max - min)
design[:, i] = triang(loc=loc, c=c, scale=scale).ppf(design[:, i])
elif distribution == 'normal':
design[:, i] = norm(loc=mu, scale=stdv).ppf(design[:, i])
else: # assume it is uniform
design[:, i] = uniform(loc=min, scale=max).ppf(design[:, i])
return design, pdf_list