PointSampler library (C++)
Loading...
Searching...
No Matches
halton.hpp
Go to the documentation of this file.
1/* Copyright (c) 2025 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4#pragma once
5#include <optional>
6
9
10namespace ps
11{
12
13template <typename T, size_t N>
14std::vector<Point<T, N>> halton_sequence(size_t count, size_t shift)
15{
16 auto halton = [](size_t index, size_t base) -> T
17 {
18 T result = 0;
19 T f = 1;
20 while (index > 0)
21 {
22 f = f / base;
23 result += f * (index % base);
24 index = index / base;
25 }
26 return result;
27 };
28
29 constexpr size_t primes[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
30 constexpr size_t n_primes = 15;
31
32 std::vector<Point<T, N>> points(count);
33 for (size_t i = 0; i < count; ++i)
34 {
35 for (size_t d = 0; d < N; ++d)
36 points[i][d] = halton(i + 1 + shift, primes[std::min(n_primes - 1, d)]);
37 }
38 return points;
39}
40
69template <typename T, size_t N>
70std::vector<Point<T, N>> halton(size_t count,
71 const std::array<std::pair<T, T>, N> &axis_ranges,
72 std::optional<unsigned int> seed = std::nullopt)
73{
74 // seed-like effect...
75 size_t shift = seed ? *seed : 0;
78 return points;
79}
80
81} // namespace ps
Definition dbscan_clustering.hpp:11
std::vector< Point< T, N > > random(size_t count, const std::array< std::pair< T, T >, N > &axis_ranges, std::optional< unsigned int > seed=std::nullopt)
Generates a specified number of uniformly distributed random points in N-dimensional space.
Definition random.hpp:66
void rescale_points(std::vector< Point< T, N > > &points, const std::array< std::pair< T, T >, N > &ranges)
Rescales normalized points (in [0, 1]) to specified axis-aligned ranges.
Definition range.hpp:207
std::vector< Point< T, N > > halton(size_t count, const std::array< std::pair< T, T >, N > &axis_ranges, std::optional< unsigned int > seed=std::nullopt)
Generates a set of quasi-random points using the Halton sequence in N dimensions.
Definition halton.hpp:70
std::vector< Point< T, N > > halton_sequence(size_t count, size_t shift)
Definition halton.hpp:14