⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permutegroups.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
function [X, y] = permuteGroups(X, y, groupSize)

% inputs
% X is an (m x n) matrix whose rows are the training inputs
% y is (m x 1) vector containing the corresponding output labels
% groupSize is the size of the group you wish to permute 

% outputs
% X permuted X
% y permuted y

num_groups = floor(size(X, 1)/groupSize); 

%Randomly permute the data matrix using Knuth's shuffling algorithm
for i=1:num_groups
   random_index = ceil(rand*(num_groups-i))+i; 
   
   %swap the current example with a random one later in the sequence
   current_example_indices = (i-1)*groupSize+1:i*groupSize; 
   random_example_indices = (random_index-1)*groupSize+1:random_index*groupSize; 
   
   temp_example  = X(current_example_indices, :); 
   X(current_example_indices, :) = X(random_example_indices,:);  
   X(random_example_indices, :) = temp_example;
   
   temp_label = y(current_example_indices); 
   y(current_example_indices) = y(random_example_indices); 
   y(random_example_indices) = temp_label; 
end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -