[PYTHON MATRIX-SIG] Final conventions for alpha2
Konrad HINSEN
hinsenk@ere.umontreal.ca
Mon, 19 Aug 1996 12:16:52 -0400
> In wanting to write generic GA code, where the structures that
> characterize the individual typically have known dimensions (fitness is a
> scalar, performance is at most a vector (in multiobjective optimization),
> but the structure of the population is a decision of who actually puts the
> GA together, the code must be written relative the last dimension of the
> array. Thus, -1 are -2 the axes that end up making sense.
> If the population was assumed to be unstructured, then one of these would
> equivalent to 0, but not in general.
I readily believe that, but this is the same example that you have given
before. My question was not about this one data object, but about the
frequency of axes other than 0 in a complete program. I guess the
only thing that will convince me is such a program...
> But suppose I have to arrays, a and b, both aligned and three dimensional,
> and that there is a ono to one correspondence between the elements of a
> and those of b. I need to sort a and, at the same time, rearrange b so
> that the original relationship is retained:
>
> ix=argsort(a)
> A=take(a,ix)
> B=take(b,ix)
Well, in this case you would need an explicit axis specification.
And I don't see what would be so bad about it. You can always come
up with an example which shows than axis=n should be the default,
probably for any n ;-) (the proof is left as an exercise for the
reader). For deciding which is the best default argument for each
function, I'd apply the following criteria:
1) What is the most common axis for each individual function?
2) How can the resulting list best be approximated by a sufficiently
simple rule?
> > Using take() makes sense e.g. if
> > you only want a subset of the elements, but I can't believe that this
> > is a frequent operation.
>
> This is called "selection" (one of the 3 main operators) operators.
I am not sure what you are referring to. Is that a special term from
GA applications?
> My experience is different. But Matlab doesn't let me write something
> like the above even for 2d arrays, so I end up using a for-loop.
Which is terribly inefficient. I have long given up Matlab due to
such limitations...
> How can I achieve
>
> rank = argsort(argsort(cost))
>
> without having to call argsort twice? Something like an inverted take
> (ekat below :-)
>
> rank = ekat(arange(n),argsort(cost))
Unless your array is very big, this variant might actually be more
expensive than the first one, because it involves three interpreted
function calls. The best solution for such applications would be
a special function that inverts a permutation (which is O(N), unlike
sorting). Than you would write
rank = inv_permutation(argsort(cost))
This function would potentially be more generally useful than your
ekat().
Konrad.
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal | Fax: +1-514-343-7586
C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7 | Francais (phase experimentale)
-------------------------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================