Agglomeration model that clusters cell barycenters with K-Means.
More...
#include <kmeans_agglomeration.hpp>
|
| | KMeansAgglomeration (KMeansAlgType alg_t=KMeansAlgType::Base, size_t max_iter=1e6, ClassFloatType tol=1e-6, size_t seed=0) |
| | Construct a K-Means agglomerator.
|
| std::vector< MeshType > | agglomerate (const MeshType &mesh, MethodType method_type, ParamType params, bool return_hierarchy=true, const std::string &segregated_tag="", const IndVec &subset={}) override |
| | Agglomerate a mesh using a selected high-level strategy.
|
| void | directKWay (const MeshType &mesh, std::size_t n_groups, IndexTrackerType &indicator, const std::vector< bool > &agglomerate) override |
| | Direct k-way partition via K-Means on barycenters.
|
| std::vector< IndVec > | multFactor (const MeshType &mesh, const float_t target_h, IndexTrackerType &indicator, const std::vector< bool > &agglomerate) |
| | Partitions the mesh based on a multiplicative factor strategy.
|
| std::vector< IndVec > | bisectNRef (const MeshType &mesh, const index_t n_refs, IndexTrackerType &indicator, const std::vector< bool > &agglomerate) |
| | Applies recursive bisection n_refs times.
|
template<typename MeshType>
class vulpes::geometry::KMeansAgglomeration< MeshType >
Agglomeration model that clusters cell barycenters with K-Means.
Implements the low-level split primitive bisectSubGraph() via 2-means and a direct directKWay() partition via k-means on the selected cells. High-level strategies (e.g., BisectNRef, MultFactor) are inherited from AbstractAgglomerationModel.
- See also
- AbstractAgglomerationModel, MethodType, KMeansAlgType, vulpes::geometry::kmeans
◆ CellType
template<typename MeshType>
◆ ClassFloatType
template<typename MeshType>
◆ ClassIndexType
template<typename MeshType>
◆ float_t
template<typename MeshType>
◆ index_t
template<typename MeshType>
◆ IndexTrackerType
template<typename MeshType>
Initial value:
datastructure::IndexTracker< index_t > IndexTrackerType
Definition abs_agg_model.hpp:78
◆ IndVec
template<typename MeshType>
◆ MapType
template<typename MeshType>
◆ MatType
template<typename MeshType>
Initial value:
Eigen::Matrix<ClassFloatType, MeshType::self_dim, Eigen::Dynamic>
◆ MeshFloatType
template<typename MeshType>
◆ MeshIndexType
template<typename MeshType>
◆ ParamType
template<typename MeshType>
◆ KMeansAgglomeration()
template<typename MeshType>
Construct a K-Means agglomerator.
- Parameters
-
| alg_t | Algorithm variant (Base or Parallel). Default: Parallel. |
| max_iter | Maximum k-means iterations (1e6 by default). |
| tol | Convergence tolerance on centroid updates. |
| seed | RNG seed for centroid initialization. |
◆ agglomerate()
template<typename MeshType>
Agglomerate a mesh using a selected high-level strategy.
Delegates to the base-class dispatcher and uses K-Means for the underlying splits/partitions.
- Parameters
-
| mesh | Input mesh. |
| method_type | Strategy to apply (see MethodType). |
| params | Strategy parameter (k, n_refs, or mult_fact). |
| return_hierarchy | If true, returns all intermediate meshes from recursive strategies. If false, returns only the final agglomerated mesh. |
| segregated_tag | If non-empty, specifies the mesh tag for segregated agglomeration, where each tagged region is processed independently. |
| subset | Optional list of cell IDs to agglomerate. If empty, the entire mesh is processed. |
- Returns
- Agglomerated mesh.
- See also
- AbstractAgglomerationModel::agglomerate()
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
◆ bisectNRef()
template<typename MeshType>
Applies recursive bisection n_refs times.
This method takes an initial partitioning and refines it by applying the bisectSubGraph() primitive recursively for n_refs levels. Each step splits a partition into two. The base cases are finalized by ensuring connectivity via connectedComponents().
- Parameters
-
| mesh | The input mesh. |
| n_refs | The number of recursive bisection levels to apply ( \(n_{refs} \ge 0\)). |
| [in,out] | indicator | The label tracker, which is updated with the results. |
| agglomerate | A boolean vector indicating which initial classes in indicator are eligible for bisection. |
- Returns
- A hierarchy of label vectors, capturing the state of partitioning at each level of bisection.
- See also
- bisectSubGraph(), connectedComponents()
◆ bisectSubGraph()
template<typename MeshType>
Bisect a subgraph by clustering barycenters with 2-means.
Computes the barycenter matrix for subset and runs k-means with k=2. One class is assigned to new_id, the other retains the previous id in indicator.
- Parameters
-
| mesh | The input mesh. |
| subgraph | A vector of cell IDs to be split. |
- Returns
- A vector of binary labels (e.g., 0s and 1s) of the same size as subgraph, assigning each cell to one of the two new partitions.
- Precondition
- subgraph.size() >= 2.
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
◆ connectedComponents()
template<typename MeshType>
Splits a set of cells into its connected components.
This function examines the dual graph restricted to the cells in subset. If the subgraph is disconnected, each connected component is assigned a new, unique label. This is often used as a finalization step in recursive strategies.
- Parameters
-
| subset | The set of cell IDs to process. |
| [in,out] | indicator | The global label tracker, which will be updated. |
| [in,out] | max_id | The last used label ID; it is incremented for each new component found. |
◆ directKWay()
template<typename MeshType>
Direct k-way partition via K-Means on barycenters.
Runs k-means with k=k on the barycenters of subset (or all cells) and returns a dense label vector.
- Parameters
-
| mesh | The input mesh. |
| n_groups | The target number of partitions. |
| [in,out] | indicator | The label tracker. It can be pre-filled to provide a warm start. It will be updated with the final labels. |
| agglomerate | A boolean vector where the i-th element indicates if the i-th class in the initial indicator should be re-partitioned. |
Implements vulpes::geometry::AbstractAgglomerationModel< MeshType >.
◆ groupToBisection()
template<typename MeshType>
Post-processes a binary labeling to ensure two connected partitions.
Given a provisional two-class labeling for a subset of cells, this method refines the labels to ensure that the resulting two partitions are each internally connected. It can relabel "islands" of cells to join the surrounding partition.
- Parameters
-
| subset | The set of cell IDs under consideration. |
| classes | A vector of provisional binary labels for the cells in subset. |
| [in,out] | indicator | The global label tracker to update with the final bisection. |
| new_id | The fresh label ID to be assigned to one of the two final partitions. |
◆ invokeMethod()
template<typename MeshType>
Dispatches to the correct agglomeration method to compute cell labels.
This is a wrapper function typically used by agglomerate(). It selects the appropriate backend method based on method_type and restricts the computation to subset if it is non-empty.
- Parameters
-
| mesh | The input mesh. |
| method_type | The strategy to apply. |
| params | The parameters for the chosen strategy. |
| segregation_tag | If non-empty, the mesh tag to use for segregated processing. |
| subset | An optional subset of cell IDs to operate on. |
- Returns
- A hierarchy of label vectors. For cells not in subset, the label is typically unchanged or set to a sentinel value (e.g., -1).
◆ multFactor()
template<typename MeshType>
Partitions the mesh based on a multiplicative factor strategy.
This method recursively bisects any group whose vertex-vertex diameter exceeds the target_h. After geometric splitting, each resulting group is finalized by splitting it into its connected components. It uses bisectSubGraph() as the core splitting primitive.
- Parameters
-
| mesh | The input mesh. |
| target_h | The target characteristic length. Any group with a diameter larger than this will be split. |
| [in,out] | indicator | The label tracker, which is updated with the results. |
| agglomerate | A boolean vector indicating which initial classes in indicator are eligible for splitting. |
- Returns
- A hierarchy of label vectors, where each vector represents the partitioning at a successive level of refinement.
- Precondition
- target_h must be a positive value.
- See also
- connectedComponents(), bisectSubGraph()
◆ splitSubsetKWay()
template<typename MeshType>
◆ dim
template<typename MeshType>
◆ m_alg_t
template<typename MeshType>
Selected K-Means algorithm family.
◆ m_barycenters_mat
template<typename MeshType>
Cached barycenter matrix used in the current call.
◆ m_dual_map
template<typename MeshType>
The dual graph of the mesh, cached for performance.
◆ m_max_iter
template<typename MeshType>
Maximum number of iterations.
◆ m_seed
template<typename MeshType>
Random seed for initialization.
◆ m_tol
template<typename MeshType>
Convergence tolerance on centroids.
The documentation for this class was generated from the following files: