根据上一个问题,有一个简单的例子:
/* Example*/
library('rnn')
# create training numbers
set.seed(1)
X1 = sample(0:127, 7000, replace=TRUE)
X2 = sample(0:127, 7000, replace=TRUE)
# create training response numbers
Y <- X1 + X2
# convert to binary
X1 <- int2bin(X1, length=8)
X2 <- int2bin(X2, length=8)
Y <- int2bin(Y, length=8)
# create 3d array: dim 1: samples; dim 2: time; dim 3: variables
X <- array( c(X1,X2), dim=c(dim(X1),2) )
# train the model
model <- trainr(Y=Y,
X=X,
learningrate = 0.1,
hidden_dim = 10,
start_from_end = TRUE )
/* End of Example*/
但是,我想问一下如何为trainr()定义多个变量的输入向量X.我的数据类型是:
Y = 1
T = 0 T = 1 T = 3 T = 4 T = 5
X1 = 1 0 1 0 1
X2 = 1 1 1 0 1
X3 = 0 0 0 0 1
X1 = 1 0 1 0 1
X2 = 0 1 1 1 1
X3 = 0 0 0 0 1
...
Y = 2
T = 0 T = 1 T = 3 T = 4 T = 5
X1 = 0 0 1 0 1
X2 = 1 1 0 0 1
X3 = 0 1 0 0 1
X1 = 1 0 1 0 1
X2 = 1 1 1 0 1
X3 = 0 1 0 0 1
...
Y = 3
T = 0 T = 1 T = 3 T = 4 T = 5
X1 = 1 0 1 0 1
X2 = 1 0 1 0 1
X3 = 0 1 0 0 1
X1 = 1 1 1 0 1
X2 = 1 0 1 0 1
X3 = 0 1 0 0 0
...
为了理解包的细节,我尝试了以下情况:
library(rnn)
set.seed(1)
X1 = sample(0:127, 5000, replace=TRUE)
X2 = sample(0:127, 5000, replace=TRUE)
X3 = sample(0:127, 5000, replace=TRUE)
X4 = sample(0:127, 5000, replace=TRUE)
Y <- X1 + X2 + X3 + X4
X1 <- int2bin(X1)
X2 <- int2bin(X2)
X3 <- int2bin(X3)
X4 <- int2bin(X4)
Y <- int2bin(Y)
X <- array( c(X1,X2,X3,X4), dim=c(dim(X1),4) )
Y <- array( Y, dim=c(dim(Y),1) )
model <- trainr(Y=Y,
X=X,
learningrate = 0.1,
hidden_dim = 10,
start_from_end = TRUE )
plot(colMeans(model$error),type='l',
xlab='epoch',
ylab='errors' )
A1 = int2bin( sample(0:127, 7000, replace=TRUE) )
A2 = int2bin( sample(0:127, 7000, replace=TRUE) )
A3 = int2bin( sample(0:127, 7000, replace=TRUE) )
A4 = int2bin( sample(0:127, 7000, replace=TRUE) )
A <- array( c(A1,A2,A3,A4), dim=c(dim(A1),4) )
B <- predictr(model,
A )
A1 <- bin2int(A1)
A2 <- bin2int(A2)
A3 <- bin2int(A3)
A4 <- bin2int(A4)
B <- bin2int(B)
hist( B-(A1+A2+A3+A4) )
然而,直方图显示正态分布,中心在-250。我认为分配不合理。可以详细说明结果吗?
实际上,我想知道如何创建所有时间的输入向量X以进行与Y值对应的分析。感谢您的回复