加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
generator.py 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
yangLiu 提交于 2022-10-11 14:58 . 初始化
"""
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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化