Name

specfun_combinerepeat — Returns repeated combinations with replacement.

Calling Sequence

   c = specfun_combinerepeat ( x , k )
   
   

Parameters

x :

a m-by-n matrix, the matrix to produce combination from.

k :

a 1-by-1 matrix of floating point integers, the number of repeted combinations, must be greater than 1.

c :

a (k*m)-by-(n^k) matrix, same type as x

Description

Uses a fast algorithm to produce repeated combinations of x with itself.

  • If k=1, then returns x.
  • If k=2, then returns combinations of x and x.
  • If k=3, then returns combinations of x and x and x.
  • etc...

For performance reasons, the combinations are stored column-by-column, that is, the combination #k is in c(:,k), with k=1,2,...,n^k.

Can process x if x is double, strings boolean and integer (signed,unsigned, 8-bits, 16-bits, 32-bits).

The algorithm makes use of the Kronecker product for good performances.

Examples

// Compute repeated combinations of x:
x = [1 2 3];
specfun_combinerepeat ( x , 1 )
specfun_combinerepeat ( x , 2 )
specfun_combinerepeat ( x , 3 )
specfun_combinerepeat ( x , 4 )

// Compare to specfun_combine
// Same as k=2
specfun_combine ( x , x )
// Same as k=3
specfun_combine ( x , x , x )
// Same as k=4
specfun_combine ( x , x , x , x )


// Repeated combinations of booleans
computed = specfun_combinerepeat ( [%t %f] , 2 )
// Repeated combinations of strings
computed = specfun_combinerepeat ( ["A" "C" "T" "G"] , 2 )
// Repeated combinations of integers
computed = specfun_combinerepeat ( uint8(1:3) , 2 )

// Compare combinerepeat, perms and subset
// Scilab/perms compute permutations without replacement
perms ( 1:3 )
// specfun_combinerepeat compute combinations with replacement
specfun_combinerepeat(1:3,3)'
// specfun_subset compute subsets with k elements
specfun_subset(1:3,3)'

   

Authors

Copyright (C) 2009 - Michael Baudin
Copyright (C) 2009-2010 - DIGITEO - Michael Baudin