[
https://issues.apache.org/jira/browse/NUMBERS-156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17349805#comment-17349805
]
Alex Herbert commented on NUMBERS-156:
--------------------------------------
I found the bug. You cannot scale up for small numbers if you have big numbers.
The big numbers dominate the results and in this case small numbers are
insignificant.
This fails for the {{extLinearMod}} as previously listed as it would scale up
by 2^600 and 2^1050 is not possible:
{code:java}
@Test
void testLargeRange() {
final double[] v = new double[] {0x1.0p450, 0x1.0p-900};
Assertions.assertEquals(v[0], SafeNorm.value(v));
}
{code}
The code can be fixed using:
{code:java}
// Use scaling if required
double scale = 1;
double rescale = 1;
if (max > 0x1.0p500) {
// Too big so scale down
scale = 0x1.0p-600;
rescale = 0x1.0p600;
} else if (min < 0x1.0p-500 && max < 0x1.0p-100) {
// Too small so scale up.
// This is only done when the maximum will not overflow when scaled.
scale = 0x1.0p600;
rescale = 0x1.0p-600;
}
{code}
This method will now work for 100000000 random length 100 vectors with
exponents from -550 to 550.
It would be possible to compute the scaling dynamically using the exponent of
the maximum and Math.scalb(1.0, 500 - exponent) to create the scaling factor.
The maximum will then be scaled to have an exponent of 500. This may not effect
the accuracy or precision over the existing method with hard coded scaling.
However the scaling thresholds could be improved with better choices based on
the extreme values that can be fed into the system.
> SafeNorm 3D overload
> --------------------
>
> Key: NUMBERS-156
> URL: https://issues.apache.org/jira/browse/NUMBERS-156
> Project: Commons Numbers
> Issue Type: Improvement
> Reporter: Matt Juntunen
> Priority: Major
> Attachments: performance-all.png, performance-len-1-5.png,
> performance2-1-5.png, performance2-all.png, performance3-1-5.png,
> performance3-all.png
>
>
> We should create an overload of {{SafeNorm.value}} that accepts 3 arguments
> to potentially improve performance for 3D vectors.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)