20 :m_maxiter(maxiter), m_codelen(codelen), m_pposone(pposone)
22 if (!check_probability(pposone))
23 SG_ERROR(
"invalid probability of +1")
28 void CECOCRandomDenseEncoder::init()
37 if (!check_probability(pposone))
38 SG_ERROR(
"probability of 0, +1 and -1 must sum to one")
51 int32_t best_dist = 0;
59 for (int32_t i=0; i < codelen; ++i)
61 for (int32_t j=0; j < num_classes; ++j)
72 for (int32_t i=0; i < codelen; ++i)
74 bool p1_occur =
false, n1_occur =
false;
75 for (int32_t j=0; j < num_classes; ++j)
76 if (codebook(i, j) == 1)
78 else if (codebook(i, j) == -1)
81 if (!p1_occur || !n1_occur)
93 for (int32_t i=0; i < num_classes; ++i)
95 for (int32_t j=i+1; j < num_classes; ++j)
104 if (min_dist > best_dist)
106 best_dist = min_dist;
107 std::copy(codebook.
matrix, codebook.
matrix + codelen*num_classes,
117 return best_codebook;
int32_t m_codelen
code length
int32_t m_maxiter
max number of iterations
static int32_t hamming_distance(T1 *c1, T2 *c2, int32_t len)
CECOCRandomDenseEncoder(int32_t maxiter=10000, int32_t codelen=0, float64_t pposone=0.5)
int32_t get_default_code_length(int32_t num_classes) const
T * get_column_vector(index_t col) const
float64_t m_pposone
probability of +1
all of classes and functions are contained in the shogun namespace
virtual SGMatrix< int32_t > create_codebook(int32_t num_classes)
Matrix::Scalar max(Matrix m)
void set_probability(float64_t pposone)