maddin79 / darch

Create deep architectures in the R programming language
GNU General Public License v3.0
71 stars 31 forks source link

darch - Error in (function (classes, fdef, mtable) : unable to .... #11

Closed AliyuAziz closed 8 years ago

AliyuAziz commented 8 years ago

Hello,

I am learning Bayesian Models in R for the first time using darch package. However, I am getting an error which I am not sure whether it's due to R or the package. Kindly help.

The simple code is as follows:

library(darch) 
darch <- newDArch(c(2,4,1),batchSize = 2,genWeightFunc         
         = generateWeights) 
inputs <- matrix(c(0,0,0,1,1,0,1,1),ncol=2,byrow=TRUE) 
outputs <- matrix(c(0,1,1,0),nrow=4) 
darch <- preTrainDArch(darch,cats,maxEpoch=1000)

and the error:

> darch <- preTrainDArch(darch,cats,maxEpoch=1000)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘validateDataSet’ for signature ‘"data.frame"’
> 
> sessionInfo()
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] MASS_7.3-45     caret_6.0-64    ggplot2_2.1.0   lattice_0.20-33
[5] darch_0.10.0   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3          nloptr_1.0.4         futile.logger_1.4.1 
 [4] plyr_1.8.3           GenomeInfoDb_1.4.1   XVector_0.8.0       
 [7] futile.options_1.0.0 iterators_1.0.8      tools_3.2.4         
[10] lme4_1.1-11          bit_1.1-12           gtable_0.2.0        
[13] nlme_3.1-126         ff_2.2-13            mgcv_1.8-12         
[16] Matrix_1.2-4         foreach_1.4.3        parallel_3.2.4      
[19] SparseM_1.7          stringr_1.0.0        MatrixModels_0.4-1  
[22] S4Vectors_0.6.2      IRanges_2.2.5        stats4_3.2.4        
[25] grid_3.2.4           nnet_7.3-12          minqa_1.2.4         
[28] reshape2_1.4.1       lambda.r_1.1.7       car_2.1-2           
[31] magrittr_1.5         scales_0.4.0         codetools_0.2-14    
[34] BiocGenerics_0.14.0  GenomicRanges_1.20.5 splines_3.2.4       
[37] pbkrtest_0.4-6       colorspace_1.2-6     quantreg_5.21       
[40] stringi_1.0-1        munsell_0.4.3       
> 

Best regards Aziz

saviola777 commented 8 years ago

Hello,

thanks for your feedback. You are using the old darch 0.9.1 interface functions which have changed in 0.10.0 and are only used internally now. Please use the darch function to create and train your networks, e.g.

library(darch) 
inputs <- matrix(c(0,0,0,1,1,0,1,1),ncol=2,byrow=TRUE) 
outputs <- matrix(c(0,1,1,0),nrow=4) 
darch <- darch(inputs, outputs, c(2,4,1), rbm.batchSize = 2, rbm.genWeightFunc = generateWeights, rbm.numEpochs = 1000, darch.numEpochs = 0)

Feel free to ask further questions if anything is unclear.

AliyuAziz commented 8 years ago

Hello saviola777,

Many thanks for your quick response. I have been trying to the example script you provider but I am still getting new error in rbm@ messages as follows:

> library(darch) 
> inputs <- matrix(c(0,0,0,1,1,0,1,1),ncol=2,byrow=TRUE) 
> outputs <- matrix(c(0,1,1,0),nrow=4) 
> darch <- darch(inputs, outputs, c(2,4,1), rbm.batchSize = 2, 
+          rbm.genWeightFunc = generateWeights, rbm.numEpochs = 1000, 
+          darch.numEpochs = 0)
WARN [2016-03-30 21:06:46] gputools package not available, using CPU matrix multiplication.
INFO [2016-03-30 21:06:46] Constructing a darch with 3 layers.
INFO [2016-03-30 21:06:46] Generating RBMs.
INFO [2016-03-30 21:06:46] Construct new RBM instance with 2 visible and 4 hidden units.
INFO [2016-03-30 21:06:46] Construct new RBM instance with 4 visible and 1 hidden units.
INFO [2016-03-30 21:06:46] Start DArch pre-training
INFO [2016-03-30 21:06:46] Starting the training of the rbm with 2 visible and 4 hidden units.
Error in rbm@hiddenUnitFunction(rbm, getVisibleUnitStates(rbm), hiddenBiases,  : 
  unused argument (rbm.genWeightFunc = function (numUnits1, numUnits2) 
{
    ret <- matrix(rnorm(numUnits1 * numUnits2) * 0.1, numUnits1, numUnits2)
    return(ret)
})
> 
>

Kindly assist.

saviola777 commented 8 years ago

Ah yes, my bad, the parameter is actually called rbm.genWeightFunction, so it should be

darch <- darch(inputs, outputs, c(2,4,1), rbm.batchSize = 2, rbm.genWeightFunction = generateWeights, rbm.numEpochs = 1000, darch.numEpochs = 0)

But since generateWeights is the default value anyway, you can also leave this parameter out.

AliyuAziz commented 8 years ago

Many thanks saviola777, you are the best! Everything works fine now. Best regards