Comments (2)
if somebody likes to randomly shuffle a Matrix, I have added a method to that in my latest commit.
ShuffleColumns() and ShuffleRows(). It also returns the Permuation so another matrix can be shuffled in the same order if it has the same size in the corresponding dimenesion.
Have also created a RandomPermuation method in Sorting as part of an extension class called SortingExtensions.
Perhaps the person requesting this ,can borrow that for now.
This can be used similary to how I used it in Matlab before.
from mathnet-numerics.
The code below generates random Permutations. Not sure what the original post is requiring.
''''
static readonly System.Random random = new System.Random(555);
/// <summary>
/// Creates a Random Permutation of lenght len (indexes 0 to len -1). Internally uses System.Random with the same seed.
/// using RandomPermutation(int len, AbstractRandomNumberGenerator rnd) can give better randomness.
/// </summary>
/// <param name="len">the length of the Permuation</param>
/// <returns></returns>
public static Permutation RandomPermutation(int len)
{
int[] keys = new int[len];
int[] items = new int[len];
for (int i = 0; i < keys.Length; i++)
{
items[i] = i;
lock (SortingExtensions.random)//System Random is not thread save!
{
keys[i] = SortingExtensions.random.Next();
}
}
Sorting.Sort(keys, items);
//although not neccessary here, the inverse of a Permutation corrseponds to a given sort order, if that Permuation was to be used to sort a matrix in the same order as the List.
return new Permutation(items).Inverse();
}
/// <summary>
/// Creates a Random Permutation of lenght len (indexes 0 to len -1) using a supplied random Number Generator
/// </summary>
/// <param name="len">the lenght of the permuation</param>
/// <param name="rnd">The Random number Generator</param>
/// <returns>The requested Permutation</returns>
public static Permutation RandomPermutation(int len, AbstractRandomNumberGenerator rnd)
{
int[] keys = new int[len];
int[] items = new int[len];
for (int i = 0; i < keys.Length; i++)
{
items[i] = i;
keys[i] = rnd.Next();
}
Sorting.Sort(keys, items);
// The inverse of a Permutation corrseponds to a given sort order,
// if that Permuation were to be used to sort a matrix in the same order as the random List above.
// Although it is neccessary here , since we are generating a random Permuation,
// for consistancy the Permuation is also inversed.
return new Permutation(items).Inverse();
}
}
''''
from mathnet-numerics.
Related Issues (20)
- Adler32 checksum no work
- Using the Levenberg-Marquardt to solve a set of non-linear equations
- Beta distribution Sample method can return NaN HOT 1
- Is mono still required on Linux?
- Is it still impossible to read a 10 x 1 cell array of 3D arrays?
- Sparse MapIndexedInplace starts with incorrect indices
- Question: Building mathnet-numerics
- Marcum Q Function not implemented correctly. HOT 1
- Question: scipy splprep and splev
- DenseMatrix.OfRowArrays().LU() Memory Leak HOT 1
- I want use MKL under AOT publish,But cant HOT 2
- Polynomial fit returns infinity and NaN as parameters
- Incorrect condition for stopping the LevenbergMarquardtMinimizer's Minimum() by parameter tolerance. HOT 1
- Feature Request: Support for `ReadOnlyMemory<T>` and `ReadOnlySpan<T>` in Vector Creation HOT 2
- Modify NewtonMinimizer so that it forces Hessian to be positive definite HOT 1
- MKL_CBWR environment variable does not seem to be respected when running?
- Bug in SpecialFunctions.Hypotenuse HOT 1
- Docs out of date?
- [Feature Request] Support for Reading Higher-Dimensional Arrays with MatlabReader
- MathNet.Numerics 4.15.0 high memory consumption Frobenius on Windows Docker linux container HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathnet-numerics.