## #53 DoubleGene.setToRandomValue does not support large bounds

next JGAP version
open
Klaus
7
2014-08-18
2009-11-17
Anonymous
No

The generation of random alleles for genes represented by real numbers is:

public void setToRandomValue (randomGenerator a_numberGenerator) (
setAllele (new Double ((m_upperBound - m_lowerBound) *
a_numberGenerator.nextDouble () + m_lowerBound));
)

If the bounds which we want are [0, Double.MAX_VALUE], where Double.MAX_VALUE = 1.7976931348623157E308 occurs:

setAllele (new Double ((Double.MAX_VALUE - 0) *
a_numberGenerator.nextDouble () + 0));

The values generated by a_numberGenerator.nextDouble () are between 0 and 1 following a uniform distribution.

Conclusion:

To generate coherent real numbers, the numbers generated by a_numberGenerator.nextDouble () should be of order E-308, and that never happens.

Easy solution:

private Double valueIn(Double v1, Double v2, RandomGenerator rnd) {

Double max=Math.max(v1, v2);
Double min=Math.min(v1, v2);

int den=Math.abs(rnd.nextInt());
if(den==0) den=2;

Double shift=(max-min)/den;

Double v=min+shift;

return v;
}

## Discussion

• Comment has been marked as spam.
Undo

You can see all pending comments posted by this user  here

Anonymous - 2009-11-17

The generation of random alleles for genes represented by real numbers is:

public void setToRandomValue (randomGenerator a_numberGenerator) (
setAllele (new Double ((m_upperBound - m_lowerBound) *
a_numberGenerator.nextDouble () + m_lowerBound));
)

If the bounds which we want are [0, Double.MAX_VALUE], where
Double.MAX_VALUE = 1.7976931348623157E308 occurs:

setAllele (new Double ((Double.MAX_VALUE - 0) *
a_numberGenerator.nextDouble () + 0));

The values generated by a_numberGenerator.nextDouble () are between 0 and 1
following a uniform distribution.

Conclusion:

To generate coherent real numbers, the numbers generated by
a_numberGenerator.nextDouble () should be of order E-308, and that never
happens.

• Comment has been marked as spam.
Undo

You can see all pending comments posted by this user  here

Anonymous - 2009-11-17

Sorry, but the proposed solution doesn't work correctly. Ignore the last lines please. Thanks

• Comment has been marked as spam.
Undo

You can see all pending comments posted by this user  here

Anonymous - 2009-11-17

A possible solution?

private Double valueIn(Double v1, Double v2, RandomGenerator rnd) {

Double max=Math.max(v1, v2);
Double min=Math.min(v1, v2);

Double v=0d;
do{
Double v01=rnd.nextDouble(); //generates a value between 0 and 1
double pow=Math.log10(max);
double powBetween=rnd.nextInt((int)pow);
double block=Math.pow(10d, powBetween); //generates 10^1, 10^2,...
v=v01*block; //places the value in a block
}while(v<min);

return v;
}

• Klaus - 2009-12-15
• milestone: 734231 --> next JGAP version
• priority: 5 --> 7
• assigned_to: nobody --> klausikm

• Klaus - 2009-12-15

I cannot fully follow the problem described. After adding some test cases to the DoubleGeneTest class, I do not see the problem. Could you kindly send me a test case where the problem occurs?
PS: Sorry for the late reply, you haven't been forgotten