Only positive numbers are in the domain of logarithmic mean.
Henry rich
On 4/20/2014 4:39 PM, Linda Alvord wrote:
Previews of coming attractions:
L4=: (]*=) + - % (^.%)
L4~ i.10
|NaN error: L4
| L4~i.10
|[-10]
Linda
-----Original Message-----
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry Rich
Sent: Sunday, April 20, 2014 3:28 PM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Logarithmic Mean
This has trouble when the numbers are close.
3 ((]*=) + - % ^.@:%) 3.000000000000001
5.66667
3 ((]*=!.0) + - % ^.@:%) 3.000000000000001
2.66667
3 ((]*=) + - % ^.@:%) 3.00000000000001
5.96774
3 ((]*=!.0) + - % ^.@:%) 3.00000000000001
2.96774
3 ((]*=) + - % ^.@:%) 3.0000000000001
6
3 ((]*=!.0) + - % ^.@:%) 3.0000000000001
3
3 ((]*=) + - % ^.@:%) 3.000000000001
2.99967
3 ((]*=!.0) + - % ^.@:%) 3.000000000001
2.99967
3 ((]*=) + - % ^.@:%) 3.00000000001
3
3 ((]*=!.0) + - % ^.@:%) 3.00000000001
3
Henry Rich
On 4/20/2014 1:52 PM, Roger Hui wrote:
Actually, according to the Wikipedia page you quoted, the log mean is
defined to be the difference divided by the log of their quotient. In
your
L function, if I replace the difference of the logs by the (equivalent)
log
of the quotient,
L =: (]*=) + - % -&^.
L3=: (]*=) + - % ^.@:%
The problem of equal arguments is finessed, and is more efficient for
having to compute only one log instead of two.
10 ts '(L |.)i.1e5'
0.0360588 5.24506e6
10 ts '(L3 |.)i.1e5'
0.00544869 5.24506e6
0 L3 i.10
0 0 0 0 0 0 0 0 0 0
(i.10) L3 0
0 0 0 0 0 0 0 0 0 0
L3~ i.10
0 1 2 3 4 5 6 7 8 9
On Sat, Apr 19, 2014 at 8:53 PM, Raul Miller <rauldmil...@gmail.com>
wrote:
https://en.wikipedia.org/wiki/Logarithmic_mean defines logarithmic
mean as the the limit of difference of two numbers divided by the
difference of their (natural) logs. The limit is to deal with the case
where the two numbers are equal - in this case, we want an identity
function.
I was tempted to implement logarithmic mean as
Lm=: (- % -&^.)^:~:
But this has a problem with rank:
2 Lm 2
2
2 3 Lm 3 2
2.4663 2.4663
2.4663 2.4663
I could solve this with ("0) but that strikes me as inefficient.
L2=: (- % -&^.)^:~:"0
So, instead:
L=: (]*=) + - % -&^.
((L-:L2) |.) i.1e5
1
Is that worth it?
timespacex '(L |.) i.1e5'
0.0365999 5.24506e6
timespacex '(L2 |.) i.1e5'
0.0828581 3.14982e6
Probably...
A caution, though:
0 L 0
|NaN error: L
Because:
^. 0
__
So maybe the explicit rank implementation isn't such a bad idea after
all?
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm