Ahmedserag777 / randomforest-matlab

Automatically exported from code.google.com/p/randomforest-matlab
0 stars 0 forks source link

random number generator initialization #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Initialize random number generator with srand() in classRF.cpp, otherwise
seedMT is seeded deterministically.

#include <time.h> 
srand ( time(NULL) ); 

prior to:

seedMT(2*rand()+1);

Original issue reported on code.google.com by jeby...@gmail.com on 5 Jan 2010 at 7:54

GoogleCodeExporter commented 8 years ago
yup, this was done just to get reproducible results over multiple runs with same
parameters.

I guess i will set a parameter in the next version to allow setting for a 
random seed.

Thanks.

Original comment by abhirana on 10 Jan 2010 at 11:28

GoogleCodeExporter commented 8 years ago
Has a random number seed been added?  Is there any way of getting around this?  
I need to run multiple times, and I keep getting the same output...

Thanks!

Michael

Original comment by oswald...@gmail.com on 19 Feb 2011 at 10:58

GoogleCodeExporter commented 8 years ago
hi Michael

i havent added that yet in. though the code just needs a line

like the first poster suggested add a line srand(time(NULL)); before this line
(CLASSIFICATION CODE) 
http://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Class_C/src/
classRF.cpp#210

file is RF_Class_C/src/classRF.cpp

(REGRESSION CODE) 
http://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Reg_C/src/re
g_RF.cpp#291

file is RF_Reg_C/src/reg_RF.cpp

and make sure that time.h is one of the include file at the top.

Then you just need to recompile, those compile_* scripts. 

Original comment by abhirana on 19 Feb 2011 at 11:04

GoogleCodeExporter commented 8 years ago
Thanks so much, I appreciate the quick response.  Unfortunately I don't know 
C++, or have a C compiler.  I'll see what I can do, though.  If I can download 
a free compiler, I should be able to fight my way through it.

Thanks again.  It's a great package, and has really helped a lot.

Michael

Original comment by oswald...@gmail.com on 19 Feb 2011 at 11:45

GoogleCodeExporter commented 8 years ago
Hi Michael

if you installed matlab, then it should have a compiler in. if not i can always 
send you the compiled files

I guess you are using one of the precompiled package for windows.

are you using windows 32-bit or 64-bit? i can send you the compiled files at ur 
gmail address, if thats fine.

Original comment by abhirana on 19 Feb 2011 at 11:53

GoogleCodeExporter commented 8 years ago
Yeah, I'm using the precompiled package right now. If it's not too much of a 
hassle for  you, I would definitely appreciate if you would generate the 
compiled files for me.  It would be a WHOLE lot easier for me, and probably 
involve a lot less swearing at the computer.

I'm using both 64-bit and 32-bit computers, so I'd need both.  Thanks so much 
for your help, I really appreciate it.

Michael

Original comment by oswald...@gmail.com on 21 Feb 2011 at 5:12

GoogleCodeExporter commented 8 years ago
Hi Michael

Attached is the version that supports windows 32/64 with random seed based on 
time(). It will print out random seed initialized in the command prompt.

Everything in the interface is same as before.

thanks!

Original comment by abhirana on 21 Feb 2011 at 7:41

Attachments:

GoogleCodeExporter commented 8 years ago
You might have to install the vc+ 2010 redistributables.
(32-bit) 
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a
423-37bf0912db84

and 

(64-bit) 
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bd512d9e-43c8-4655-8
1bf-9350143d5867

long story short, the 32-bit version was compiled using vc+ 2010 + matlab 2010b 
and the 64-bit with vc+ 2008 + matlab 2009a

Original comment by abhirana on 21 Feb 2011 at 7:46

GoogleCodeExporter commented 8 years ago
That worked perfectly.  Thanks so much for all of your help, I really 
appreciate it.

Michael

Original comment by m2osw...@gmail.com on 21 Feb 2011 at 10:02

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
hi,

your code is very useful. thanks for sharing.

i am using 5-fold cross validation, (although i read about the internal oob 
error rate, that is similar to cross validation). 

Although, I have fixed the seed (global seed setting), but using multiple runs 
i get a different output? i want to have same results each time. Keeping 
everything else same, I want to play with the parameters. 

regards,
Ihtesham.

Original comment by ihtesham...@gmail.com on 29 Nov 2012 at 12:12

GoogleCodeExporter commented 8 years ago
Ihtesham

what version of code are you using? svn or download? 

i dont remember if the code in download has the srand() or not
http://code.google.com/p/randomforest-matlab/source/browse/trunk/RF_Class_C/src/
classRF.cpp#204

if you comment it out then you should get reproducible values

Original comment by abhirana on 29 Nov 2012 at 7:05

GoogleCodeExporter commented 8 years ago
i am using the downloaded version. (i search and it doesn't contain the call to 
srand function), but still i'm getting different results for multiple runs... I 
am using the following code for my 5 fold cross validation to reset the global 
seed. (matlab code)

stream = RandStream.getGlobalStream;
reset(stream);
CVO=cvpartition(Labels,'kfold',5);

Original comment by ihtesham...@gmail.com on 29 Nov 2012 at 12:40

GoogleCodeExporter commented 8 years ago
@ihtesham

attached code will give you reproducible code. All what is changed from the 
uploaded version is recompiling the code with a fixed seed (both for 
classifcation and regression, changed two lines which said seedMT(2*rand()+1) 
to seedMT(77) )

do tell me if you have any issues.

Original comment by abhirana on 11 Dec 2012 at 11:11

Attachments: