代码拉取完成,页面将自动刷新
"""
Generator to read in scraped profiles and return batches.
Returns:
- X: Curve data (BATCH_SIZE, POINTS, 2, 1) in cartesian coordinates
- y: Parameters (3, 1) (normalized to mean and stddev (cd was scaled by log to get normal distribution))
"""
"""
生成器读取报废的配置文件并返回批次。
退货:
-X:笛卡尔坐标中的曲线数据(BATCH_SIZE,POINTS,2,1)
-y:参数(3,1)(归一化为平均值和标准偏差(cd按对数缩放以获得正态分布))
"""
################################################################################
# %% 引入包
################################################################################
import glob
import numpy as np
################################################################################
# %% 定义发电机功能
################################################################################
def profile_generator(BATCH_SIZE=512, POINTS=64, DTYPE='float32'):
fimg = sorted(glob.glob(f'01-prep-data/{POINTS}/X_*.npy'))
#print(f'----> Reading {fimg[0]} <----')
X = np.load(fimg[0])
y = np.load(fimg[0].replace('X', 'y'))
idx = np.random.permutation(len(X))
X = X[idx]
y = y[idx]
i = 0
while True:
if len(X) < BATCH_SIZE:
if i<len(fimg)-1:
i += 1
else:
i = 0
#print(f'----> Reading {fimg[i]} <----')
X = np.concatenate((X, np.load(fimg[i])), axis=0)
y = np.concatenate((y, np.load(fimg[i].replace('X', 'y'))), axis=0)
idx = np.random.permutation(len(X))
X = X[idx]
y = y[idx]
else:
##### SHIFT/SCALE TO -1.0 ... 1.0
X[:BATCH_SIZE,: ,0, 0] = (X[:BATCH_SIZE,:, 0, 0] - 0.5)*2.0
X[:BATCH_SIZE,: ,1, 0] = (X[:BATCH_SIZE,:, 1, 0])*2.0
##### CL
ymean = 0.5
ystd = 0.7
y[:BATCH_SIZE, 0] = (y[:BATCH_SIZE, 0]-ymean)/ystd
##### CD
ymean = -3.6
ystd = 0.7
y[:BATCH_SIZE, 1] = (np.log(y[:BATCH_SIZE, 1])-ymean)/ystd
ymean = 0.085
ystd = 0.025
y[:BATCH_SIZE, 2] = (y[:BATCH_SIZE, 2]-ymean)/ystd
yield X[:BATCH_SIZE].astype(DTYPE), y[:BATCH_SIZE].astype(DTYPE)
X = np.delete(X, range(BATCH_SIZE), axis=0)
y = np.delete(y, range(BATCH_SIZE), axis=0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。