MCPcopy Index your code
hub / github.com/mne-tools/mne-python / random_permutation

Function random_permutation

mne/utils/numerics.py:273–307  ·  view source on GitHub ↗

Emulate the randperm matlab function. It returns a vector containing a random permutation of the integers between 0 and n_samples-1. It returns the same random numbers than randperm matlab function whenever the random_state is the same as the matlab's random seed. This function

(n_samples, random_state=None)

Source from the content-addressed store, hash-verified

271
272@fill_doc
273def random_permutation(n_samples, random_state=None):
274 """Emulate the randperm matlab function.
275
276 It returns a vector containing a random permutation of the
277 integers between 0 and n_samples-1. It returns the same random numbers
278 than randperm matlab function whenever the random_state is the same
279 as the matlab's random seed.
280
281 This function is useful for comparing against matlab scripts
282 which use the randperm function.
283
284 Note: the randperm(n_samples) matlab function generates a random
285 sequence between 1 and n_samples, whereas
286 random_permutation(n_samples, random_state) function generates
287 a random sequence between 0 and n_samples-1, that is:
288 randperm(n_samples) = random_permutation(n_samples, random_state) - 1
289
290 Parameters
291 ----------
292 n_samples : int
293 End point of the sequence to be permuted (excluded, i.e., the end point
294 is equal to n_samples-1)
295 %(random_state)s
296
297 Returns
298 -------
299 randperm : ndarray, int
300 Randomly permuted sequence between 0 and n-1.
301 """
302 rng = check_random_state(random_state)
303 # This can't just be rng.permutation(n_samples) because it's not identical
304 # to what MATLAB produces
305 idx = rng.uniform(size=n_samples)
306 randperm = np.argsort(idx)
307 return randperm
308
309
310@verbose

Callers 3

test_random_permutationFunction · 0.90
infomaxFunction · 0.85

Calls 1

check_random_stateFunction · 0.85