8 #ifndef META_OCEAN_MATH_SUCCESSION_SUBSET_H
9 #define META_OCEAN_MATH_SUCCESSION_SUBSET_H
33 template <
typename T,
size_t tDimensions>
58 typedef std::vector<unsigned char>
Flags;
84 inline size_t size()
const;
141 explicit inline operator bool()
const;
170 T
distance(
const size_t a,
const size_t b)
const;
198 template <
typename T,
size_t tDimensions>
204 template <
typename T,
size_t tDimensions>
207 setObjects(objects, size);
210 template <
typename T,
size_t tDimensions>
216 template <
typename T,
size_t tDimensions>
219 return successionObjects.size();
222 template <
typename T,
size_t tDimensions>
225 ocean_assert(successionObjects.size() == successionFlags.size());
227 size_t index = size_t(-1);
229 if (successionSubset.size() == successionObjects.size())
234 ocean_assert(successionSubset.size() < successionObjects.size());
236 if (successionSubset.size() == 0)
238 index = smallestMaximalDistance();
242 index = largestMinimalDistanceWithSubset();
245 if (index ==
size_t(-1))
250 ocean_assert(index < successionFlags.size());
251 successionFlags[index] = 1;
252 successionSubset.push_back(index);
257 template <
typename T,
size_t tDimensions>
260 ocean_assert(successionObjects.size() == successionFlags.size());
262 if (
object >= successionObjects.size() || successionFlags[
object] != 0)
267 successionFlags[object] = 1;
268 successionSubset.push_back(
object);
273 template <
typename T,
size_t tDimensions>
276 ocean_assert(index < successionObjects.size());
277 return successionObjects[index];
280 template <
typename T,
size_t tDimensions>
283 return successionSubset;
286 template <
typename T,
size_t tDimensions>
289 while (successionSubset.size() < objects && successionSubset.size() < successionObjects.size())
291 const size_t index = incrementSubset();
292 ocean_assert_and_suppress_unused(index < successionObjects.size(), index);
295 return successionSubset;
298 template <
typename T,
size_t tDimensions>
303 for (
size_t n = 0; n < size; ++n)
305 for (
size_t i = 0; i < tDimensions; ++i)
307 variances[i].add(objects[n][i]);
312 successionObjects.resize(size);
313 successionFlags =
Flags(size, 0u);
314 successionSubset.clear();
322 for (
size_t i = 0; i < tDimensions; ++i)
324 normalizationFactors[i] = variances[i].deviation() > 0 ? (T(1) / variances[i].deviation()) : T(1);
327 for (
size_t n = 0; n < size; ++n)
329 for (
size_t i = 0; i < tDimensions; ++i)
331 successionObjects[n][i] = objects[n][i] * normalizationFactors[i];
336 template <
typename T,
size_t tDimensions>
339 return successionObjects.empty();
342 template <
typename T,
size_t tDimensions>
345 ocean_assert(successionObjects.size() == successionFlags.size());
346 return successionSubset.size() < successionObjects.size();
349 template <
typename T,
size_t tDimensions>
354 for (
size_t n = 0; n < indices.size(); ++n)
357 result[n] =
Index32(indices[n]);
363 template <
typename T,
size_t tDimensions>
366 ocean_assert(successionSubset.size() < successionObjects.size());
368 size_t smallestIndex = size_t(-1);
370 for (
size_t n = 0; n < successionObjects.size(); ++n)
372 if (successionFlags[n] == 0)
380 T smallestDistance = maximalDistance(smallestIndex);
383 for (
size_t n = smallestIndex + 1; n < successionObjects.size(); ++n)
385 if (successionFlags[n] == 0)
387 const T localDistance = maximalDistance(n);
389 if (localDistance < smallestDistance)
391 smallestDistance = localDistance;
397 return smallestIndex;
400 template <
typename T,
size_t tDimensions>
403 ocean_assert(successionSubset.size() < successionObjects.size());
405 size_t largestIndex = size_t(-1);
407 for (
size_t n = 0; n < successionObjects.size(); ++n)
409 if (successionFlags[n] == 0)
417 T largestDistance = minimalDistanceWithSubset(largestIndex);
420 for (
size_t n = largestIndex + 1; n < successionObjects.size(); ++n)
422 if (successionFlags[n] == 0)
424 const T localDistance = minimalDistanceWithSubset(n);
426 if (localDistance > largestDistance)
428 largestDistance = localDistance;
437 template <
typename T,
size_t tDimensions>
440 ocean_assert(a < successionObjects.size());
441 ocean_assert(b < successionObjects.size());
445 for (
size_t i = 0; i < tDimensions; ++i)
447 result +=
NumericT<T>::sqr(successionObjects[a][i] - successionObjects[b][i]);
453 template <
typename T,
size_t tDimensions>
456 ocean_assert(index < successionObjects.size());
457 ocean_assert(successionObjects.size() >= 2);
462 for (
size_t n = 0; n < successionObjects.size(); ++n)
466 const T localDistance = distance(n, index);
468 if (localDistance > maxDistance)
469 maxDistance = localDistance;
477 template <
typename T,
size_t tDimensions>
480 ocean_assert(index < successionObjects.size());
481 ocean_assert(successionSubset.size() >= 1);
486 for (
size_t n = 0; n < successionSubset.size(); ++n)
488 ocean_assert(index != successionSubset[n]);
489 const T localDistance = distance(successionSubset[n], index);
491 if (localDistance < minDistance)
493 minDistance = localDistance;
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr T minValue()
Returns the min scalar value.
Definition: Numeric.h:3250
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition: Numeric.h:1495
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
This class implements a static buffer that has a fixed capacity.
Definition: StaticBuffer.h:24
This class implements a data container for abstract data objects with several dimensions.
Definition: SuccessionSubset.h:35
SuccessionSubset()
Creates an empty container object.
Definition: SuccessionSubset.h:199
size_t largestMinimalDistanceWithSubset() const
Returns the elements of this container that is not part of the subset and that has the largest minima...
Definition: SuccessionSubset.h:401
T distance(const size_t a, const size_t b) const
Determines the distance between two objects of this container.
Definition: SuccessionSubset.h:438
T maximalDistance(const size_t index) const
Returns the maximal distance between a specified object of this container and all remaining objects o...
Definition: SuccessionSubset.h:454
std::vector< Object > Objects
Definition of a vector holding abstract objects.
Definition: SuccessionSubset.h:53
Indices successionSubset
The indices of all objects inside the subset.
Definition: SuccessionSubset.h:195
static size_t dimensions()
Returns the dimension of each object of this container.
Definition: SuccessionSubset.h:211
void setObjects(const Object *objects, const size_t size)
Overwrites all objects of this container and resets the current subset of the previous object to zero...
Definition: SuccessionSubset.h:299
size_t smallestMaximalDistance() const
Returns the elements of this container that is not part of the subset and that has the smallest maxim...
Definition: SuccessionSubset.h:364
Flags successionFlags
Objects flags, for a fast check whether an objects is part of the internal subset.
Definition: SuccessionSubset.h:192
const Object & object(const size_t index)
Returns one object of this container.
Definition: SuccessionSubset.h:274
size_t size() const
Returns the number of objects that are managed by this container.
Definition: SuccessionSubset.h:217
bool isEmpty() const
Returns whether this container is empty and thus does not store any object.
Definition: SuccessionSubset.h:337
size_t incrementSubset()
Determines the next object of this container that has the largest distance to all remaining objects t...
Definition: SuccessionSubset.h:223
StaticBuffer< T, tDimensions > Object
The definition of an abstract object of this constainer.
Definition: SuccessionSubset.h:41
std::vector< unsigned char > Flags
Definition of a vector holding flags.
Definition: SuccessionSubset.h:58
T minimalDistanceWithSubset(const size_t index) const
Returns the smallest distance between a specified object of this container and all subset objects of ...
Definition: SuccessionSubset.h:478
static Indices32 indices2indices32(const Indices &indices)
Converts the indices of this object to 32 bit indices.
Definition: SuccessionSubset.h:350
Objects successionObjects
All objects of this container.
Definition: SuccessionSubset.h:189
std::vector< size_t > Indices
Definition of a vector holding indices.
Definition: SuccessionSubset.h:46
const Indices & subset() const
Returns the current object subset of this container.
Definition: SuccessionSubset.h:281
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15