00001 #ifndef Impala_Core_Matrix_MatDrawRandomRows_h
00002 #define Impala_Core_Matrix_MatDrawRandomRows_h
00003
00004 #include "Core/Matrix/MatFunc.h"
00005 #include "Core/Matrix/Mat.h"
00006 #include "Core/Matrix/MatKeepSpecificRows.h"
00007 #include "Util/RandomGenerator.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Matrix
00014 {
00015
00016
00017 Mat*
00018 MatDrawRandomRows(Mat* data, int requestedSize)
00019 {
00020
00021 int n = MatNrRow(data);
00022 int d = MatNrCol(data);
00023 std::vector<int> indices;
00024 for(int j = 0; j < n; j++)
00025 {
00026 indices.push_back(j);
00027 }
00028 Util::RandomGenerator::GetInstance().PermutateVector(indices);
00029
00030 std::vector<int> keepers;
00031 for(int j = 0; j < requestedSize; j++)
00032 {
00033 keepers.push_back(indices[j]);
00034 }
00035 std::sort(keepers.begin(), keepers.end());
00036
00037
00038 return MatKeepSpecificRows(data, keepers);
00039 }
00040
00041
00042 }
00043 }
00044 }
00045
00046 #endif