[ 
https://issues.apache.org/jira/browse/NUMBERS-156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17340823#comment-17340823
 ] 

Alex Herbert commented on NUMBERS-156:
--------------------------------------

{quote}Huh? Direct computation ignoring overflow/underflow was the fastest in 
the benchmark.
{quote}
You are correct. I missed a digit when looking at the numbers.

How are you generating the random vectors? Roughly what is the power of 2 
exponent for each double, and the range of exponents over the numbers that are 
summed?

I find it odd that the scaled version has lower error than the unsafe version 
(when the numbers are non-finite). I assume we are not comparing exactly the 
same numbers as the scaled version error will include the 10534 computations 
that the unsafe version has not counted.

Could it be that when the result of the unsafe version is non-finite that the 
sum is easier as one large term dominates the result and effectively the other 
numbers can be ignored, e.g.
{noformat}
2^800 + 2^100 + 2^99 + ...
{noformat}
Here the smaller terms can be ignored.

Basically the random numbers input to the computation should all have an 
exponent within a factor of 2^26 such that summing their squares actually 
requires the two numbers be added (i.e. the squares are within a factor less 
than 2^53).

Note that this is a query out of interest rather than necessity. I think your 
benchmark shows that the new method is an improvement over that in SafeNorm.

So following on from above we could add (names TBD):
{code:java}
public static final Norms {
    // Manhattan norm (L1-norm). Sum of the absolutes.
    public double l1(double x, double y);
    public double l1(double x, double y, double z);
    public double l1(double[] x);
    // Euclidean norm (L2-norm). Sqrt of the sum of the squares
    public double l2(double x, double y);
    public double l2(double x, double y, double z);
    public double l2(double[] x);
    // Maximum norm (Linf-norm?). Maximum absolute value.
    public double max(double x, double y);
    public double max(double x, double y, double z);
    public double max(double[] x);
}
{code}
For the 1D case all three are the same as {{Math.abs}}. Adding this does not 
seem required. The class then computes norms for the n-dimensional space.

The maximum norm is not referred to as the Linfinite norm on Wikipedia. So some 
of the names could be:
||Manhatten||Euclidean||Maximum||
|l1|l2|linf|
|manhatten|euclidean|maximum|
|taxicab|squareNorm|max|
|l1distance|l2distance| |

I would favour the verbose manhatten, euclidian and maximum.

 

> 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
>
> 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)

Reply via email to