当前位置:网站首页>Paddle implementation, multidimensional time series data enhancement, mixup (using beta distribution to make continuous random numbers)
Paddle implementation, multidimensional time series data enhancement, mixup (using beta distribution to make continuous random numbers)
2022-07-23 19:37:00 【Lee Meier】
# Data to enhance
def data_augment(X, y, p=0.8, alpha=0.5, beta=0.5):
"""Regression SMOTE
1. Put the data x It is divided into fix_X and X
2. Yes X To remodel
For random uniform distribution less than 0.8 The index of idx_to_change Reshape the data part .
X2 It's after disordering the order X
beta The value is np.random.beta(alpha, beta, batch_size) / 2 + 0.5 ####beta value >0.5 Make sure that most of the reshaped data is the original value
X[idx_to_change] = beta value *X[idx_to_change] +(1-beta value )*X2[idx_to_change]
3. Merge fix_X and X New data x
4. For input y In the same way
"""
fix_X, X = X[:, :, :, :2], X[:, :, :, 2:]#[32, 134, 144, 2] [32, 134, 144, 10]
fix_y, y = y[:, :, :, :2], y[:, :, :, 2:]#[32, 134, 288, 2] [32, 134, 288, 10]
# print('fix_X, X:',fix_X.shape, X.shape)
batch_size = X.shape[0]#32
random_values = paddle.rand([batch_size]) # Returns uniformly distributed , The scope is [0, 1) Of Tensor shape:[32]
idx_to_change = random_values < p #32 A value of , Less than 0.8 For the False, Others are True
# ensure that first element to switch has probability > 0.5
np_betas = np.random.beta(alpha, beta, batch_size) / 2 + 0.5
random_betas = paddle.to_tensor(
np_betas, dtype="float32").reshape([-1, 1, 1, 1]) # [32, 1, 1, 1]
index_permute = paddle.randperm(batch_size)# returns a 1-D Tensor filled with random permutation values from 0 to n-1# Used to disrupt data numbers
X[idx_to_change] = random_betas[idx_to_change] * X[idx_to_change]
X[idx_to_change] += (
1 - random_betas[idx_to_change]) * X[index_permute][idx_to_change]
y[idx_to_change] = random_betas[idx_to_change] * y[idx_to_change]
y[idx_to_change] += (
1 - random_betas[idx_to_change]) * y[index_permute][idx_to_change]
return paddle.concat([fix_X, X], -1), paddle.concat([fix_y, y], -1)
边栏推荐
- 《自适应机器人交互白皮书》
- PowerCLi 添加esxi主机到vCenter
- Publish the local image to Alibaba cloud warehouse
- H7-TOOL的I2C接口方式脱机烧录操作方法,已经发布(2022-07-16)
- Summarize some recent tricks
- Read data from txt and convert it to Yolo format data
- 界面设计四大原则
- 移动语义和完美转发浅析
- Atcoder regular contest 144 [VP record]
- Challenges of decentralized storage
猜你喜欢
随机推荐
ACM MM 2022 Oral | DIG: 自监督文字识别的新框架,刷新11个公开场景文字数据集的识别性能,平均提升5%...
Leetcode daily question (1514. path with maximum probability)
Boundschecker usage "recommended collection"
Tree learning summary
You must execute multiple requests and catch errors. Using try catch is not elegant
Exch:POP3 和 IMAP4 操作指南
二、MFC窗口和消息
Talk about the parental delegation mechanism in detail (often asked in interviews) [easy to understand]
Understand chisel language. 21. Chisel sequential circuit (I) -- detailed explanation of chisel register
Weights & Biases (一)
GPS北斗时钟服务器(NTP网络时钟系统)施工部署方案
H7-TOOL串口脱机烧录操作说明,支持TTL串口,RS232和RS485(2022-06-30)
吃透Chisel语言.21.Chisel时序电路(一)——Chisel寄存器(Register)详解
树莓派ssh登录
Lendingclub loan status business details current, charge off, issued, full paid, grace period
有向图之求两点之间所有路径
【pm2】pm2常用命令
MySQL中 8 种常见的 SQL 错误用法
Codeforces Round #805-#808【部分题解】
界面设计四大原则








![[machine learning] Wu Enda: lifelong learning](/img/f2/a729c026ed55506e63878d0d317676.jpg)
