... and my last remark probably deals more with efficiency than effectiveness -- I sometimes fight for words even in my mother tongue.
-M

At 2016-08-31 06:33, you wrote:

Don -

That's been exacly the idea behind what I called "gm1" (taking the roots first) ...

The Log approach "gm2" however proves to be a little bit more effective:

   10000 timespacex 'gm1 >: ? 6 $~ 2^10'
0.000185607 50816
   10000 timespacex 'gm2 >: ? 6 $~ 2^10'
0.000110259 42752

-M


At 2016-08-31 03:24, you wrote:

How about this-it fits the definition of "nth root of product of n items"

gmean =: # %: */

(gmean,gm1)>: ? 6 $~ 637

2.98625 2.98625

(gm0,gm1,gm2,gmean)>:?6$~637

2.97123 2.97123 2.97123 2.97123

(gm0,gm1,gm2,gmean) >:?6$~637

_ 3.04854 3.04854 _

(gmean, gm1)s=:>:?6$~638

_ 3.06565

b=: 638 %: s

*/b

3.06565

(amean s) ^ 638



*/s



The problem appears when */ results in an overflow and is detected as infinite

*/ 638#3

2.5314e304

*/ 638#4




  638 %:638#4

1.00218 1.00218 1.00218 1.00218218 1.00218 1.00218 ...

*/ 638 %:638#4



The advantage lies with taking the roots first for numbers >1


Don Kelly


On 8/26/2016 4:38 AM, Martin Kreuzer wrote:
Hi all -

Sharing something I observed ...

While the definitions (for arithmetic and geometric mean)

   amean=: +/ % #
and
   gmean=: */ %:~ #

are nice to look at as a pair (because of symmetry) I prefer this definition of geometric mean

   gmean=: [: */ # %: ]
or
   NB. using the Log domain
   gmean=: [: ^ [: amean ^.

because, given these (intermediate) definitions

   NB. often found
   gm0=. */ %:~ #
   NB. taking the roots first, then multiply
   gm1=. [: */ # %: ]
   NB. definition found on (&.:) page of NuVoc
   gm2=. amean &.: ^.

I got these results (see gm0 failing while the other two hold)

   (gm0,gm1,gm2) >: ? 6 $~ 637
3.04409 3.04409 3.04409
   (gm0,gm1,gm2) >: ? 6 $~ 638
_ 3.05264 3.05264
   (gm0,gm1,gm2) >: ? 6 $~ 2^24
_ 2.99357 2.99357

under J v8.04 on a 32-bit Vista machine.

Thanks
-M

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

Reply via email to