This project has moved and is read-only. For the latest updates, please go here.

On the subject of permutations...

Jun 2, 2014 at 2:29 AM
Perhaps I've missed it but I don't believe Numerics has a create random permutation function.
I've had need of randomly permuting columns/rows in matrices and so I wrote this short little function to create the random permutations.
It is an implementation of the Fisher-Yates shuffle.
 Public Function RandPermutation(ByVal length As Integer) As Permutation
    'This function returns a random permutation mapping of length 'length'.
    'For use in the permute rows/columns matrix functions
    Dim series(length - 1) As Integer
    Dim randint, temp As Integer
    For x = 0 To length - 1
        series(x) = x
    For i = length - 1 To 1 Step -1
        randint = Int(Rnd() * (i) + 0.5)
        temp = series(i)
        series(i) = series(randint)
        series(randint) = temp
    Return Permutation.FromInversions(series)
End Function
It is nice that you can store this permutation and then use it again for another matrix.
For example if you have 2 matrices with corresponding rows/columns you can permute each with the same permutation and the matrices will still correspond.
This is useful for me in that I have matrices of input variables and corresponding matrices of target values. When doing mini-batch gradient descent I can use the random permutation function without losing the correspondence between input and target.
Jun 2, 2014 at 8:56 PM
Indeed: Iridium did have routines to shuffle and sample random variations or combinations, but we have never ported them over to Math.NET Numerics. Would be nice if we could bring that to Math.NET Numerics.