22 :m_maxiter(maxiter), m_codelen(codelen), m_pzero(pzero), m_pposone(pposone), m_pnegone(pnegone)
24 if (!check_probability(pzero, pposone, pnegone))
25 SG_ERROR(
"probability of 0, +1 and -1 must sum to one")
30 void CECOCRandomSparseEncoder::init()
41 if (!check_probability(pzero, pposone, pnegone))
42 SG_ERROR(
"probability of 0, +1 and -1 must sum to one")
57 int32_t best_dist = 0;
60 std::vector<int32_t> random_sel(num_classes);
67 for (int32_t i=0; i < codelen; ++i)
70 for (int32_t j=0; j < num_classes; ++j)
72 std::random_shuffle(random_sel.begin(), random_sel.end());
75 codebook(i, random_sel[0]) = +1;
76 codebook(i, random_sel[1]) = -1;
80 codebook(i, random_sel[0]) = -1;
81 codebook(i, random_sel[1]) = +1;
85 for (int32_t j=2; j < num_classes; ++j)
91 codebook(i, random_sel[j]) = -1;
93 codebook(i, random_sel[j]) = +1;
101 for (int32_t i=0; i < num_classes; ++i)
103 for (int32_t j=i+1; j < num_classes; ++j)
112 if (min_dist > best_dist)
114 best_dist = min_dist;
115 std::copy(codebook.
matrix, codebook.
matrix + codelen*num_classes,
123 return best_codebook;
static int32_t hamming_distance(T1 *c1, T2 *c2, int32_t len)
CECOCRandomSparseEncoder(int32_t maxiter=10000, int32_t codelen=0, float64_t pzero=0.5, float64_t pposone=0.25, float64_t pnegone=0.25)
void set_probability(float64_t pzero, float64_t pposone, float64_t pnegone)
virtual SGMatrix< int32_t > create_codebook(int32_t num_classes)
int32_t get_default_code_length(int32_t num_classes) const
T * get_column_vector(index_t col) const
all of classes and functions are contained in the shogun namespace
Matrix::Scalar max(Matrix m)