Author Message

Richard Levine writes on Friday, May 19:

Quote:
> ...
> Suppose the mean of the ROWS of m is given by
>      mean m
> What is an expression for the mean of the COLUMNS of m?  In general,
> what is the best expression for any function where you want to apply the
> function to the ROWS and the COLUMNS?
> One book suggests two methods in the particular case of "mean":

> (1) mean transpose m  (where transpose =. |: )
> (2) mean"1 m

f"r a  applies f to the rank r cells of array a, for all verbs f,
all ranks r, and all arrays a.  (See page 21, "J Introduction and
Dictionary".)  I find this description simpler and clearer than
"over the rows" or "over the columns" or (worse) "mean of the rows"
or "mean of the columns", or perhaps "means of the rows" or "means of
the columns".

For example, what exactly is "the mean of the columns of m"?
I can think of two interpretations:  (a) add column 0 to column
1 to column 2 ..., then divide by the number of columns.  (b)
for each column, add element 0 to element 1 to element 2 ...,
then divide by the number of elements.

Quote:
> ...
> I feel that method (2) is not general.  I feel it depends entirely on
> the internal definition of "mean".  Method (1) however, seems to me to
> be general; as long as the function under discussion gives the
> correct result for each row, method (1) will give the correct
> result for each column.

I disagree.  Method 1 is restricted to calculating means of vectors.
Method 2 is more general and can apply to cells of rank 2, 3, etc.

The paper is about rank in SHARP APL, but the concepts are the same
in J.

Sat, 08 Nov 1997 03:00:00 GMT

Quote:
>Richard Levine writes on Friday, May 19:
>> ...
>> Suppose the mean of the ROWS of m is given by
>>      mean m
>> What is an expression for the mean of the COLUMNS of m?  In general,
>> what is the best expression for any function where you want to apply the
>> function to the ROWS and the COLUMNS?
>> One book suggests two methods in the particular case of "mean":

>> (1) mean transpose m  (where transpose =. |: )
>> (2) mean"1 m

Roger Hui commented

Quote:
>f"r a  applies f to the rank r cells of array a, for all

verbs f,>all ranks r, and all arrays a.  (See page 21, "J Introduction and

Quote:
>Dictionary".)  I find this description simpler and clearer than
>"over the rows" or "over the columns" or (worse) "mean of the rows"
>or "mean of the columns", or perhaps "means of the rows" or "means of
>the columns".

I agree that mean"1 m  is clear and specific and the preferred form,
but for many users it will be just as clear if we define advervbs  ForRows
and  ForColumns  and write

mean  ForRows  m
mean  ForColumns  m

mean  is a rather special verb because all of the components in its definition

median  is naturally defined over a vector - and with a monadic rank of 1.
For such a verb the simple solution does not work so neatly.   Whereas
mean  m   automatically finds the mean of columns for a matrix  m
median  m  now will not work.  Of course  median "1 m still finds the medians
of the rows - making Roger's point but to find the median of the columns
requires

median "1 |: m

for objects with rank greater than two the first step must be a general
transposition to put the dimension across which the median is to be taken
last.   Thus to find the median across the first dimension of a rank 3 array
we need

median "1  (0)|: m

This structure is valuable for many functions which do not have infinite

Fraser Jackson

Mon, 10 Nov 1997 03:00:00 GMT

Fraser Jackson writes on Thursday, May 25:

Quote:
> I agree that mean"1 m  is clear and specific and the preferred form,
> but for many users it will be just as clear if we define advervbs  ForRows
> and  ForColumns  and write

> mean  ForRows  m
> mean  ForColumns  m

If mean"1 is clear and specific and preferred, and shorter, why have
the circumlocutory and less general ForRows and ForColumns?  Actually,
to me, ForRows and ForColumns are less clear, for reasons stated in
my original msg: to me, "ForColumns" is as ambiguous as "the mean of
the columns":

: For example, what exactly is "the mean of the columns of m"?
: I can think of two interpretations:  (a) add column 0 to column
: 1 to column 2 ..., then divide by the number of columns.  (b)
: for each column, add element 0 to element 1 to element 2 ...,
: then divide by the number of elements.

Quote:
> mean  is a rather special verb because all of the components in its definition

No.  The nice behaviour for "mean" is due to its having infinite rank;
the ranks of its components are irrelevant.  That is, "mean" is defined
to work on arrays of any rank, and that makes it possible to apply "mean"
to cells of any rank, through mean"r .

Quote:
> median  is naturally defined over a vector - and with a monadic rank of 1.
> For such a verb the simple solution does not work so neatly.   Whereas
> mean  m   automatically finds the mean of columns for a matrix  m
> median  m  now will not work.  Of course  median "1 m still finds the medians
> of the rows - making Roger's point but to find the median of the columns
> requires

> median "1 |: m

> for objects with rank greater than two the first step must be a general
> transposition to put the dimension across which the median is to be taken
> last.   Thus to find the median across the first dimension of a rank 3 array
> we need

> median "1  (0)|: m

If median indeed has a "natural" monadic rank of 1, with defn med1 (say),
I would make an infinite rank version of it thus:

Then "median" can be used the same way as "mean"; in particular,
median"r  applies median to the rank r cells.

Quote:
> This structure is valuable for many functions which do not have infinite

But many functions are easily defined to have infinite rank (i.e.
easily defined to work on arrays of any rank):  for example, variance,
standard deviation, sum of squares, average (mean), moving average,
maximum, minimum, range, etc.  For such functions  f"r  suffices, and
f"1|:a  has little to recommend it.

Fri, 14 Nov 1997 03:00:00 GMT

Robert Bernecky writes on Monday, May 29:

Quote:
> >a. Transpose implies a large movement of data and should be used
> >as last resort.  An application making extensive use of transpose
> >probably has a mistake in its data design.

> Nossir. Transpose implies a change in the view of the data.
> It need not imply ANY data movement. In fact, APL implementations
> that DO move data for a transpose [SHARP APL, IBM APL2, Dyalog APL,
> APL*PLUS III tm c etc -- did I miss any of them?] suffer dismal
> performance simply because they do NOT implement descriptor
> algebras that would permit ALL structual operations to be performed in
> fixed time, regardless of array size.

> Data movement is indeed expensive, and should be avoided, but
> good interpreter or compiler design can make the performance of
> transpose, etc., a non-issue.

If all the currently available APLs do move data for transpose,
then it seems unfair to deny that transpose implies a large movement
of data.  Transpose may also imply a change in view of the data,
but it can imply other things too, can it not?

In any case, we were discussing the merits of +/ and mean vs.

so certainly transpose implies a movement of data.

of the Bernecky interpreter/compiler employing good design may make the
performance of transpose a non-issue, but I'll continue to recommend

Quote:
> Now, as to Roger's second claim "mistake in its data design" presumes
> that the way data is accessed remains static thoughout the application.
> This simply isn't true in reality. The HPF fortran people made the
> same mistake.

You should not put words in my mouth.  I presumed no such thing.

Sat, 15 Nov 1997 03:00:00 GMT

Quote:

>Fraser Jackson writes on Thursday, May 25:
>> Of course  median "1 m still finds the medians
>> of the rows - making Roger's point but to find the median of the columns
>> requires

>> median "1 |: m

>> for objects with rank greater than two the first step must be a general
>> transposition to put the dimension across which the median is to be taken
>> last.   Thus to find the median across the first dimension of a rank 3 array
>> we need

>> median "1  (0)|: m

Roger Hui replied

Quote:
>If median indeed has a "natural" monadic rank of 1, with defn med1 (say),
>I would make an infinite rank version of it thus:

>Then "median" can be used the same way as "mean"; in particular,
>median"r  applies median to the rank r cells.
>> This structure is valuable for many functions which do not have infinite
>But many functions are easily defined to have infinite rank (i.e.
>easily defined to work on arrays of any rank):  for example, variance,
>standard deviation, sum of squares, average (mean), moving average,
>maximum, minimum, range, etc.  For such functions  f"r  suffices, and
>f"1|:a  has little to recommend it.

To work correctly Roger's solution needs to be modified to read

which seems to me to be exactly the original construction I proposed.
The user needs the construct in one place or another.  Anyone using J will
appreciate how much it simplifies code if the functions are defined to have
infinite rank.

Sat, 15 Nov 1997 03:00:00 GMT

Fraser Jackson writes on Tuesday, May 30:

Quote:
> To work correctly Roger's solution needs to be modified to read

No.  The preamble to the definition said that "If median indeed has
a "natural" rank of 1, with defn med1 ..."; this means that med1
is identical to med1"1.

Quote:
> which seems to me to be exactly the original construction I proposed.

I wasn't trying to quibble about whether one can use med1 or med1"1.
The point was this:  if I were the writer of the median function,

"median" can compute the median of arrays of any rank), and a
user of the function can simply say  median"r .  As far as
use of the function is concerned, "median" could have been defined
using transpose, sort, whatever.

Quote:
> The user needs the construct in one place or another.  ...

Not necessarily, not for the many functions I listed (variance,
standard deviation, etc.).  And where |: is not needed to define
the function, it makes little sense to introduce it in order to
apply the function to subarrays.  Certainly it makes little sense
for "mean" and "sum", the functions that started this discussion.

Quote:
>                                                    ... Anyone using J will
> appreciate how much it simplifies code if the functions are defined to have
> infinite rank.

Quite so.  Once so defined, the function can be applied to cells

Sun, 16 Nov 1997 03:00:00 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages
 11. profile.js