org.apache.mahout.math
Class GenericPermuting

java.lang.Object
  extended by org.apache.mahout.math.GenericPermuting

Deprecated. until unit tests are in place. Until this time, this class/interface is unsupported.

@Deprecated
public class GenericPermuting
extends java.lang.Object


Method Summary
static int[] permutation(long p, int N)
          Deprecated. Returns the p-th permutation of the sequence [0,1,...,N-1].
static void permute(int[] list, int[] indexes)
          Deprecated. A non-generic variant of reordering, specialized for int[], same semantics.
static void permute(int[] indexes, Swapper swapper, int[] work)
          Deprecated.  
static void permute(int[] indexes, Swapper swapper, int[] work1, int[] work2)
          Deprecated. Generically reorders arbitrary shaped generic data g such that g[i] == g[indexes[i]].
static void permute(java.lang.Object[] list, int[] indexes)
          Deprecated. A non-generic variant of reordering, specialized for Object[], same semantics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

permutation

public static int[] permutation(long p,
                                int N)
Deprecated. 
Returns the p-th permutation of the sequence [0,1,...,N-1]. A small but smart and efficient routine, ported from Cernlib. The Fortran source. A sequence of N distinct elements has N! permutations, which are enumerated in lexicographical order 1 .. N!.

This is, for example, useful for Monte-Carlo-tests where one might want to compute k distinct and random permutations of a sequence, obtaining p from org.apache.mahout.math.jet.random.sampling without replacement or a random engine like MersenneTwister.
Note: When N! exceeds the 64-bit range (i.e. for N > 20), this method has different behaviour: it makes a sequence [0,1,...,N-1] and randomizes it, seeded with parameter p.

Examples:

 http://www.hep.net/wwwmirrors/cernlib/CNASDOC/shortwrups_html3/node255.html
 // exactly lexicographically enumerated (ascending)
 permutation(1,3) --> [ 0,1,2 ]
 permutation(2,3) --> [ 0,2,1 ]
 permutation(3,3) --> [ 1,0,2 ]
 permutation(4,3) --> [ 1,2,0 ]
 permutation(5,3) --> [ 2,0,1 ]
 permutation(6,3) --> [ 2,1,0 ]
 permutation(1      ,20) --> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
 permutation(2      ,20) --> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 18]
 permutation(1000000,20) --> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 17, 18, 13, 19, 11, 15, 14, 16, 10]
 permutation(20! -2 ,20) --> [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 2, 0]
 permutation(20! -1 ,20) --> [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 0, 1]
 permutation(20!    ,20) --> [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
 
// not exactly enumerated, rather randomly shuffled permutation(1,21) --> [18, 20, 11, 0, 15, 1, 19, 13, 3, 6, 16, 17, 9, 5, 12, 4, 7, 14, 8, 10, 2] permutation(2,21) --> [1, 9, 4, 16, 14, 13, 11, 20, 10, 8, 18, 0, 15, 3, 17, 5, 12, 2, 6, 7, 19] permutation(3,21) --> [12, 0, 19, 1, 20, 5, 8, 16, 6, 14, 2, 4, 3, 17, 11, 13, 9, 10, 15, 18, 7]

Parameters:
p - the lexicographical ordinal number of the permutation to be computed.
N - the length of the sequence to be generated.
Returns:
the p-th permutation.
Throws:
java.lang.IllegalArgumentException - if p < 1 || N < 0 || p > N!.

permute

public static void permute(int[] list,
                           int[] indexes)
Deprecated. 
A non-generic variant of reordering, specialized for int[], same semantics. Quicker than generic reordering. Also for convenience (forget about the Swapper object).


permute

@Deprecated
public static void permute(int[] indexes,
                                      Swapper swapper,
                                      int[] work)
Deprecated. 

Deprecated. Generically reorders arbitrary shaped generic data g such that g[i] == g[indexes[i]]. (The generic data may be one array, a 2-d matrix, two linked lists or whatever). This class swaps elements around, in a way that avoids stumbling over its own feet.

Example:

 Reordering
 [A,B,C,D,E] with indexes [0,4,2,3,1] yields
 [A,E,C,D,B]
 In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[2], g[3]<--g[3], g[4]<--g[1].

 Reordering
 [A,B,C,D,E] with indexes [0,4,1,2,3] yields
 [A,E,B,C,D]
 In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[1], g[3]<--g[2], g[4]<--g[3].
 

Parameters:
indexes - the permutation indexes.
swapper - an object that knows how to swap two indexes a,b.
work - the working storage, must satisfy work.length >= indexes.length; set work==null if you don't care about performance.

permute

public static void permute(int[] indexes,
                           Swapper swapper,
                           int[] work1,
                           int[] work2)
Deprecated. 
Generically reorders arbitrary shaped generic data g such that g[i] == g[indexes[i]]. (The generic data may be one array, a 2-d matrix, two linked lists or whatever). This class swaps elements around, in a way that avoids stumbling over its own feet.

Example:

 Reordering
 [A,B,C,D,E] with indexes [0,4,2,3,1] yields
 [A,E,C,D,B]
 In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[2], g[3]<--g[3], g[4]<--g[1].

 Reordering
 [A,B,C,D,E] with indexes [0,4,1,2,3] yields
 [A,E,B,C,D]
 In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[1], g[3]<--g[2], g[4]<--g[3].
 

Parameters:
indexes - the permutation indexes.
swapper - an object that knows how to swap two indexes a,b.
work1 - some working storage, must satisfy work1.length >= indexes.length; set work1==null if you don't care about performance.
work2 - some working storage, must satisfy work2.length >= indexes.length; set work2==null if you don't care about performance.

permute

public static void permute(java.lang.Object[] list,
                           int[] indexes)
Deprecated. 
A non-generic variant of reordering, specialized for Object[], same semantics. Quicker than generic reordering. Also for convenience (forget about the Swapper object).



Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.