bquast / rnn

Recurrent Neural Networks in R
https://qua.st/rnn
73 stars 28 forks source link

How to use formula method with this package? #12

Closed ghost closed 8 years ago

ghost commented 8 years ago

How can I use formula method with this package

library(rnn)
> x1=c(1:10)
> x2=c(11:20)
> y=x1+x2
> model=trainr(y~x1+x2)

but it returns this error

Error in trainr(y ~ x1 + x2) : argument "X" is missing, with no default

bquast commented 8 years ago

have you looked at the documentation / vignettes?

ghost commented 8 years ago

Yes I have read it but have doubt in this section of the code

# convert to binary
X1 <- int2bin(X1)
X2 <- int2bin(X2)
Y  <- int2bin(Y)

# Create 3d array: dim 1: samples; dim 2: time; dim 3: variables.
X <- array( c(X1,X2), dim=c(dim(X1),2) )
Y <- array( Y, dim=c(dim(Y),1) ) 

Is conversion to binary necessary? if yes cant it be automated that is can it be done in the background without the users intervention?.

And please forgive me if these are stupid questions but I am new to RNN itself?

bquast commented 8 years ago

No that is not necessary, this is just an example of the typical value of rnn over feed-forward nn (carrying the 1). But the point is that the inputs are combined into a single array, whether you turn it into binary or not.

ghost commented 8 years ago

sorry for the late reply;I have tried to convert input output variables into arrays

library(rnn)
x1=c(1:10)
x2=c(11:20)
y=x1+x2
x=cbind(x1,x2)
x=data.frame(x)
x=array( x, dim=c(dim(x1),2) ) 
y=array(y)
model=trainr(y,x)

but gets this error

Error in if (dim(X)[2] != dim(Y)[2]) { : missing value where TRUE/FALSE needed

bquast commented 8 years ago

I am sorry but this is not a help forum. You should post your question on stackoverflow. If you send me the link I will look at it there.