Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RcppShark Random Forest example throws exception about the random number generator

I followed this example:

https://www.2021.ai/randsharkmachinelearning/

when running this command on R:

sharkFit <- SharkRFTrain(X, Y, nTrees = 100)

I get:

Error in SharkRFTrain(X, Y, nTrees = 100) : 
  Should not call this. Fix the random numbers generator if you need this. 478

This exception is thrown from this "cpp" line:

trainer.train(model, trainData);

I suspect the reason is written here:

https://github.com/aydindemircioglu/RcppShark#notes

The random number generator was replaced, as R packages must use the random generator from R and not the C/C++ internal one. Thereffore, a direct comparison of results of algorithms that depend on (pseudo) random numbers cannot be done.

Is there a way to mitigate this?

tried both R versions: 3.4.1, 3.3.2

like image 507
Ophir Carmi Avatar asked Oct 29 '22 04:10

Ophir Carmi


1 Answers

I have investigated this and was able to narrow it down to some degree:

  • The error message is produced here: https://github.com/aydindemircioglu/RcppShark/blob/master/src/shark/Rng/Runif.h#L71
  • The calling code is here: https://github.com/aydindemircioglu/RcppShark/blob/master/src/src/Algorithms/RFTrainer.cpp#L178

Since I was not able to fix it, I have opened an issue here: https://github.com/aydindemircioglu/RcppShark/issues/1

like image 177
Ralf Stubner Avatar answered Nov 15 '22 06:11

Ralf Stubner