SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PermutationMatrix.cpp
Go to the documentation of this file.
1 #include "PermutationMatrix.h"
2 
3 #ifdef HAVE_EIGEN3
4 
7 
8 using namespace shogun;
9 using namespace Eigen;
10 
12 {
14 
15  // scale
16  for(int t = 0; t < mat.cols(); t++)
17  mat.col(t) /= mat.col(t).cwiseAbs().maxCoeff();
18 
19  // round
20  for (int i = 0; i < mat.rows(); i++)
21  {
22  for (int j = 0; j < mat.cols(); j++)
23  {
24  if (CMath::abs(CMath::round(mat(i,j))) >= 1.0)
25  mat(i,j) = 1.0;
26  else
27  mat(i,j) = 0.0;
28  }
29  }
30 
31  // check only a single 1 per row
32  for (int i = 0; i < mat.rows(); i++)
33  {
34  int num_ones = 0;
35  for (int j = 0; j < mat.cols(); j++)
36  {
37  if (mat(i,j) >= 1.0)
38  num_ones++;
39  }
40 
41  if (num_ones != 1)
42  return false;
43  }
44 
45  // check only a single 1 per col
46  for (int j = 0; j < mat.cols(); j++)
47  {
48  int num_ones = 0;
49  for (int i = 0; i < mat.rows(); i++)
50  {
51  if (mat(i,j) >= 1.0)
52  num_ones++;
53  }
54 
55  if (num_ones != 1)
56  return false;
57  }
58 
59  return true;
60 }
61 #endif //HAVE_EIGEN3
Definition: SGMatrix.h:20
bool is_permutation_matrix(SGMatrix< float64_t > m)
index_t num_cols
Definition: SGMatrix.h:378
index_t num_rows
Definition: SGMatrix.h:376
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static float64_t round(float64_t d)
Definition: Math.h:398
static T abs(T a)
Definition: Math.h:179

SHOGUN Machine Learning Toolbox - Documentation