Keras CNN自动编码器潜在空间表示意义

Keras CNN自动编码器潜在空间表示意义,keras,conv-neural-network,convolution,autoencoder,Keras,Conv Neural Network,Convolution,Autoencoder,我正在使用CNN自动编码器去噪一些我产生的合成噪声数据。本练习的目的是测试去噪自动编码器的去噪能力。 这一部分我还想做一些特征降维。因此,我将30个特征编码到一个三维潜在空间中。 我附上代码,关于我得到的输出,我的问题如下。到目前为止,噪声已大大降低,但我得到的分量与原始信号不同步。 那么,这种潜在空间的表现是什么意思呢 R代码: # Core Tidyverse library(tidyverse) library(glue) library(forcats) # Time Series l

我正在使用CNN自动编码器去噪一些我产生的合成噪声数据。本练习的目的是测试去噪自动编码器的去噪能力。 这一部分我还想做一些特征降维。因此,我将30个特征编码到一个三维潜在空间中。 我附上代码,关于我得到的输出,我的问题如下。到目前为止,噪声已大大降低,但我得到的分量与原始信号不同步。 那么,这种潜在空间的表现是什么意思呢

R代码:

# Core Tidyverse
library(tidyverse)
library(glue)
library(forcats)
# Time Series
library(timetk)
library(tidyquant)
library(tibbletime)
# Visualization
library(cowplot)
# Preprocessing
library(recipes)
# Sampling / Accuracy
library(rsample)
library(yardstick) 
# Modeling
library(keras)
library(tfruns)
library(abind)


### Equation: y=a*sin(b*t)+c.unif*amp
# variables
n <- 20000 # number of data points
t <- seq(0,4*pi,,n)
a <- 3
b <- 100
c.unif <- runif(n)
c.norm <- rnorm(n)
amp <- 2

# generate data and calculate "x"
set.seed(1)

x_features = c()
for(i in 1:10) {
  x1 <- a*sin(b*t)+c.unif*amp # uniform error
  x2 <- a*sin(b*t)+c.norm*amp # Gaussian/normal error
  x3 <- jitter(a*sin(b*t), amount=1.25)
  x_features <- cbind(x_features,x1,x2,x3)
}

str(x_features)


# plot results
matplot(t[1:400], x_features[1:400,], t="l", ylim=range(x_features))
legend("top", legend=c("x_features"), bty="n")

# functions used
BuildTensor <- function(X,w)
{
  aperm(abind(do.call('c',apply(X, 2, function(x) list(apply(embed(x,w),1,rev)))),along=3),c(2,1,3))
}

build_matrix <- function(tseries, overall_timesteps) {
  t(sapply(1:(length(tseries) - overall_timesteps + 1), function(x) 
    tseries[x:(x + overall_timesteps - 1),]))
}
reshape_X_3d <- function(X) {
  dim(X) <- c(dim(X)[1], dim(X)[2], 1)
  X
}

n_timesteps = 128

X <- BuildTensor(x_features, n_timesteps)

N = 19000
x_train <- X[1:N,,]
x_test <- X[N:dim(X)[1],,]


str(x_train)
n_features = 30

encoder_inputs  <- layer_input(shape=list(n_timesteps,n_features))
encoded <- layer_conv_1d(filters = 8, kernel_size = n_features, activation = 'relu', dilation_rate=2)(encoder_inputs)
encoded <- layer_max_pooling_1d(pool_size = 2)(encoded)
encoded <- layer_conv_1d(filters = 4, kernel_size = n_features, activation = 'relu', dilation_rate=2)(encoded) 
encoded <- layer_max_pooling_1d(pool_size = 2)(encoded)
encoded <- layer_global_average_pooling_1d()(encoded)
encoded <- layer_flatten()(encoded)
encoded <- layer_dense(units=3)(encoded)

decoded <- layer_dense(units=64)(encoded)
decoded <- layer_reshape(target_shape=c(16,4))(decoded)
decoded <- layer_conv_1d(filters=4,kernel_size=1,strides=1, activation='relu',padding='same')(decoded)
decoded <- layer_upsampling_1d(size=2)(decoded)
decoded <- layer_conv_1d(filters=8,kernel_size=1,strides=1, activation='relu',padding='same')(decoded)
decoded <- layer_upsampling_1d(size=2)(decoded)
decoded <- layer_upsampling_1d(size=2)(decoded)
decoded <- layer_conv_1d(filters=n_features,kernel_size=n_features,strides=1, activation='relu',padding='same')(decoded)

autoencoder <- keras_model(encoder_inputs, decoded)
model_den <- keras_model(encoder_inputs,encoded)

autoencoder

autoencoder %>% compile(
    loss = 'mse',
    optimizer = 'adam'
)

autoencoder %>% fit(x_train, x_train, batch_size = 16, epochs = 100)

x_train_den <- model_den %>% predict(x_train, batch_size = 16)

str(x_train_den)

par(mfrow=c(2,1))
matplot(x_train_den[1:500,],type="l")
matplot(x_train[1:500,dim(x_train)[2],],type="l")


x_test_den <- model_den %>% predict(x_test, batch_size = 16)

matplot(x_test_den[1:500,],type="l")
matlines(x_test[1:500,dim(x_test)[2],],type="l")

#核心Tidyverse
图书馆(tidyverse)
图书馆(胶水)
图书馆(供猫用)
#时间序列
图书馆(timetk)
图书馆(tidyquant)
图书馆(藏书时代)
#形象化
图书馆(cowplot)
#预处理
图书馆(食谱)
#取样/准确度
图书馆(rsample)
图书馆(尺度)
#造型
图书馆(keras)
图书馆(tfruns)
图书馆(abind)
###方程:y=a*sin(b*t)+c.unif*amp
#变数

n对序列或时间序列数据使用LSTM自动编码器


您的输入数据是有噪声的正弦波数据。序列数据不应使用卷积自动编码器。

序列或时间序列数据应使用LSTM自动编码器


您的输入数据是有噪声的正弦波数据。序列数据不能使用卷积自动编码器。

感谢您的见解@Pallavi。然而,我已经使用LSTM自动编码器很长一段时间了,我现在想使用CNN自动编码器和可能的FCN 1D ResNet自动编码器。有一些研究声称它们对时间序列更稳定。你能给我指一下那些推荐cnn时间序列数据模型的研究论文吗?我最感兴趣的是金融时间序列。以下是一篇使用1D FCN ResNet自动编码器对多变量时间序列进行去噪,然后使用这些特征预测价格值的文章。你怎么认为?另一篇非常有趣的论文如下。我更感兴趣的是用于时间序列去噪和特征减少的1D ResNet自动编码器。看来可能会有好结果。但是模型太多了,我都弄糊涂了。这是一个2D Unet图像示例:感谢您的见解@Pallavi。然而,我已经使用LSTM自动编码器很长一段时间了,我现在想使用CNN自动编码器和可能的FCN 1D ResNet自动编码器。有一些研究声称它们对时间序列更稳定。你能给我指一下那些推荐cnn时间序列数据模型的研究论文吗?我最感兴趣的是金融时间序列。以下是一篇使用1D FCN ResNet自动编码器对多变量时间序列进行去噪,然后使用这些特征预测价格值的文章。你怎么认为?另一篇非常有趣的论文如下。我更感兴趣的是用于时间序列去噪和特征减少的1D ResNet自动编码器。看来可能会有好结果。但是模型太多了,我都弄糊涂了。这是图像的2D Unet示例: