The method of random disturbance of training samples in matlab, matlab Samples

Source: Internet
Author: User

The method of random disturbance of training samples in matlab, matlab Samples

Use randperm () to generate random seeds, and then swap locations for random sample extraction.

Official content:

The built-in function randperm (n) of Matlab generates random orders of integers ranging from 1 to n without duplicates. Then, we can use it to obtain random numbers without duplicates.
Function p = randperm (n );
% RANDPERM Random permutation.
% RANDPERM (n) is a random permutation of the integers from 1 to n.
% For example, RANDPERM (6) might be [2 4 5 6 1 3].
%
% Note that randperm cils rand and therefore changes RAND's state. %
% See also PERMUTE. % Copyright 1984-2002 The MathWorks, Inc.
% $ Revision: 5.10 $ Date: 2002/04/09 00:26:14 $
[Ignore, p] = sort (rand (1, n ));


Principle:
1. rand (1, n) generates a random number matrix within 0-1 of n columns in 1 row.
2. sort () sorts this matrix. The returned ignore is the sorted sequence, and p is the original index of the number of sorted sequences. This index must be random, and there is no repeated integer between 1 and n.


Code:

> A = rand (10, 4) a = 0.9516 0.3015 0.0326 0.6448 0.9203 0.7011 0.5612 0.3763 0.0527 0.6663 0.8819 0.1909 0.7379 0.5391 0.6692 0.4283 0.2691 0.6981 0.1904 0.4820 0.4228 0.6665 0.3689 0.1206 0.5479 0.1781 0.4607 0.5895 0.9427 0.1280 0.9816 0.2262 0.4177 0.9991 0.1564 0.3846 0.9831 0.1711 0.8555 0.5830> RandIndex = randperm (length ()); % then the array index a = a (RandIndex ,:); % create an array with new indexes> aa = 0.9831 0.1711 0.8555 0.5830 0.9516 0.3015 0.0326 0.6448 0.7379 0.5391 0.6692 0.4283 0.9203 0.7011 0.5612 0.3763 0.9427 0.1280 0.9816 0.2262 0.4177 0.9991 0.1564 0.3846 0.0527 0.6663 0.8819 0.1909 0.5479 0.1781 0.4607 0.5895 0.2691 0.6981 0.1904 0.4820 0.4228 0.6665 0.3689 0.1206


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.