33 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_LATTICE 34 #define SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_LATTICE 52 std::size_t sumlength(std::size_t
const n, std::size_t
const sum);
54 void pointLattice_helper(
55 UIntMatrix & pointMatrix,
56 std::size_t
const rowidx,
57 std::size_t
const colidx,
58 std::size_t
const sum_rest);
61 template <
typename Iterator>
62 bool isLatticeCorner(Iterator begin, Iterator end){
63 std::size_t nonzero = 0;
64 for(
auto iter = begin; iter != end; ++iter)
89 template <
typename Matrix,
typename randomType = shark::random::rng_type>
91 randomType & rng, Matrix
const & matrix,
93 bool const keep_corners =
true 96 if(matrix.size1() <= n){
99 Matrix sampledMatrix(n, matrix.size2());
100 std::set<std::size_t> added_rows;
103 for(std::size_t row = 0; row < matrix.size1(); ++row){
104 if(detail::isLatticeCorner(matrix.row_begin(row), matrix.row_end(row))){
105 added_rows.insert(row);
109 while(added_rows.size() < n){
111 added_rows.insert(
random::discrete(rng, std::size_t(0), matrix.size1() - 1));
114 for(std::size_t row_idx : added_rows)
117 matrix.row_begin(row_idx), matrix.row_end(row_idx),
118 sampledMatrix.row_begin(i)
122 return sampledMatrix;
142 std::size_t
const sum,
143 std::vector<Preference>
const & preferences);
149 std::size_t
const sum,
150 std::vector<Preference>
const & preferences);
160 std::size_t
const n, std::size_t
const target_count
164 RealMatrix
weightLattice(std::size_t
const n, std::size_t
const sum);
174 template <
typename Matrix>
176 Matrix
const & m, std::size_t
const n){
177 const RealMatrix distances = distanceSqr(m, m);
178 UIntMatrix neighbourIndices(m.size1(), n);
180 for(std::size_t i = 0; i < m.size1(); ++i)
183 std::vector<std::size_t> indices(distances.size2());
184 std::iota(indices.begin(), indices.end(), 0);
186 std::sort(indices.begin(), indices.end(),
187 [&](std::size_t a, std::size_t b)
189 return distances(i, a) < distances(i, b);
192 std::copy_n(indices.begin(), n, neighbourIndices.row_begin(i));
194 return neighbourIndices;
200 #endif // SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_LATTICE