SHOGUN  4.2.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 
6 
7 using namespace shogun;
8 using namespace Eigen;
9 
11 {
13 
14  // scale
15  for(int t = 0; t < mat.cols(); t++)
16  mat.col(t) /= mat.col(t).cwiseAbs().maxCoeff();
17 
18  // round
19  for (int i = 0; i < mat.rows(); i++)
20  {
21  for (int j = 0; j < mat.cols(); j++)
22  {
23  if (CMath::abs(CMath::round(mat(i,j))) >= 1.0)
24  mat(i,j) = 1.0;
25  else
26  mat(i,j) = 0.0;
27  }
28  }
29 
30  // check only a single 1 per row
31  for (int i = 0; i < mat.rows(); i++)
32  {
33  int num_ones = 0;
34  for (int j = 0; j < mat.cols(); j++)
35  {
36  if (mat(i,j) >= 1.0)
37  num_ones++;
38  }
39 
40  if (num_ones != 1)
41  return false;
42  }
43 
44  // check only a single 1 per col
45  for (int j = 0; j < mat.cols(); j++)
46  {
47  int num_ones = 0;
48  for (int i = 0; i < mat.rows(); i++)
49  {
50  if (mat(i,j) >= 1.0)
51  num_ones++;
52  }
53 
54  if (num_ones != 1)
55  return false;
56  }
57 
58  return true;
59 }
Definition: SGMatrix.h:20
bool is_permutation_matrix(SGMatrix< float64_t > m)
index_t num_cols
Definition: SGMatrix.h:376
index_t num_rows
Definition: SGMatrix.h:374
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