[Insight-users] Missing use of ReinitializeSeed in MutualInfo. metric?

Erik Harg Erik.Harg at idi.ntnu.no
Mon May 2 05:03:43 EDT 2005


On Sat, 30 Apr 2005, Karthik Krishnan wrote:

> Hi Erik,
>
> You may also include quasi-random initialization if you like as in
>
> metric->ReinitializeSeed(vcl_ctime(0));
>
Thanks for your reply, Karthik. I have included, now, a call to the 
seeding function of the metric in my program...

> A default seed is supplied during the first call to drand by most compilers 
> except the cygwin-gcc, which was why the function was added, so you could 
> call it explicitly from your code. The metric constructor doesn't use it to 
> ensure that testing is consitent.
>
I would have to confess that I had not thought about the test suite's 
requirements for consistent and deterministic results. However, I would 
still naïvely think that this could be obtained by a call to the 
ReinitializeSeed() in the metric constructor, and then (subsequently) do 
the crude fixed-number initialization of the random number generator 
*only* in the testing framework?

I should hurry to point out that I have not even looked at the ITK test 
suite, so I'm a little out on a limb here.

> The MersenneTwister was  added to ITK recently and is generally 1-6 times 
> faster than its vnl counterpart (except on the SGIs ?? ) and it exhibits more 
> randomness too.
>
And that, I guess, is for the internal use in e.g. the 
ImageRandomConstIteratorWithIndex?

Thanks again, Karthik, for your reply.

Regards,
Erik


> Erik Harg wrote:
>
>> Hi,
>> 
>> I have a question regarding the randomness (or, rather, the lack of it) of 
>> the random number generator in ImageRandomConstIteratorWithIndex, as used 
>> in the MutualInformationImageToImageMetric.
>> 
>> In my experience, with the same number of sample points, and the same 
>> fixed/moving images, the Iterator always chooses the same sample points, 
>> and the resulting MI metric values are always identical. This is occurring 
>> both under Mac OS X and Linux, using itk versions from 1.8 to 2.0.
>> 
>> As far as I can tell, when the MutualInformationImageToImageMetric calls 
>> the ++randIter, the increment operator of the ImageConstIteratorWithIndex 
>> calls RandomJump(), which in turn uses vnl_sample_uniform(). However, I 
>> have not been able to find any preceding call to the reseed function of 
>> the iterator, nor directly to the vnl_sample_reseed() functions. [1]
>> 
>> In the almost 6 months I have been watching this list, some threads 
>> related to this issue have emerged, but (I believe) not covering exactly 
>> what I am thinking about...
>> 
>> My question then, is this: Am I correct in noticing that the 
>> MutualInformation Metric does not seed the random number generator, and is 
>> there a good reason for it not to use its own ReinitializeSeed() function 
>> (or the one in the Iterator)?
>> 
>> I notice that in some of the RegistrationExamples included with the itk 
>> source, there are specific calls to vnl_sample_reseed(int seed), using 
>> seed=8775070 or 76926294. However, wouldn't it be a more general approach 
>> to let the MI metric, or even the Iterator, handle the seeding, to ensure 
>> that the correct function is called?
>> 
>> There is probably a good answer to this, and I am looking forward to 
>> hearing it! Thank you.
>> 
>> Regards,
>> 
>> Erik
>> 
>> 
>> [1]
>> Looking at the source code for the vnl (vnl_sample.cxx in the 
>> Utilities/vxl/core/vnl directory of the itk source tree), it seems that 
>> this function will either use the drand48() stdlib function if available, 
>> or use a simple congruential random number generator. As far as my 
>> understanding of (pseudo-)random number generators go, both of these need 
>> a decent seed to provide anything close to random numbers. The 
>> congruential generator that is built into the vnl has a static seed of 
>> 12345, unless a call to vnl_sample_reseed() or vnl_sample_reseed(int seed) 
>> precedes the vnl_sample_uniform() function call. However, when vnl is 
>> using the drand48(), no default seeding (using srand48()) is done, and I 
>> believe the last system provided seed is used(?). Thus, any call to 
>> vnl_sample_uniform() should be preceded by a call to vnl_sample_reseed() 
>> (which uses the vcl_time(0) as seed to srand48()), or to 
>> vnl_sample_reseed(int seed) using some user defined seed. Only this will 
>> ensure a basic pseudo-random behaviour of the uniform random number 
>> generator, I believe.
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>

-- 
       *----------------------------------------------------------*
       | Erik Harg         924 98 541       Erik.Harg at idi.ntnu.no |
       |                NTNU - Trondheim                          |
       *----------------------------------------------------------*



More information about the Insight-users mailing list