@Beta @PublicAPI public final class IDBasedHierarchicClusterBuidler extends Object
Licensing: this class is part of the JKlustor suite; it can be used with valid
JKlustor
license.
Please note that this class is marked with @Beta annotation, so it can be subject of incompatible changes or removal in later releases.
Constructor and Description |
---|
IDBasedHierarchicClusterBuidler(HierarchicClustering.Alignment alignemnt)
New builder instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addChildCluster(int childClusterID,
int parentClusterID)
Add a cluster to another cluster as a child cluster.
|
int |
addNewCluster()
Allocate a new cluster.
|
void |
addStructureToCluster(int structureID,
int parentClusterID)
Add a structure to a cluster as an immediate leaf.
|
IDBasedHierarchicClustering |
build()
Build the immutable clustering representation.
|
IDBasedHierarchicClustering |
build(IDBasedAssignerBuilder assignerBuilder)
Build an immutable snapshot of the clustering.
|
IDBasedClusterBuilderSpec |
cluster(int representedClusterId)
A spec for a clusterId.
|
int |
clusterOf(int structureID)
Look up immediate parent of a structure present in the clustering.
|
void |
detachToRootCluster(int clusterID)
Remove a cluster from its current parent cluster.
|
int[] |
getAllLeaves(int clusterID)
Return the IDs of all immediate and transitive leaves.
|
int[] |
getChildClusters(int clusterID)
Return the IDs of child cluster IDs.
|
int |
getClusterRepresentant(int clusterID)
Retrieve cluster representant ID.
|
int[] |
getImmediateLeaves(int clusterID)
Return the IDs of immediate leaves.
|
int |
getParentClusterID(int clusterID)
Looks up a clusters parent cluster ID.
|
int |
getStructureImmediateParentCluster(int structureID)
Look up structure's immediate parent cluster ID.
|
boolean |
hasParent(int clusterID)
Check if a cluster has parent cluster id set.
|
boolean |
isClusterRepresentantSet(int clusterID)
Check if cluster representant is present.
|
boolean |
isEmpty()
Check if the tree is empty.
|
boolean |
isStructurePresent(int structureId)
Check if a given structure ID is present in the clustering.
|
IDBasedClusterBuilderSpec |
newCluster()
Allocates a new cluster and returns a spec to it.
|
static IDBasedHierarchicClusterBuidler |
newRootAlignedIdDBasedHierarchicClusterBuilder()
Convenience method.
|
IDBasedClusterBuilderSpec |
newRootCluster()
Allocates a new cluster and returns a spec to it.
|
void |
removeStructure(int structureID)
Remove a structure from its current parent cluster.
|
void |
setClusterPreferredLevel(int clusterID,
double level)
Set cluster level of preferred level assigner.
|
void |
setClusterRepresentant(int structureID,
int clusterID)
Set cluster representant ID.
|
void |
setLeafPreferredLevel(int leafID,
double level)
Set leaf level of preferred level assigner.
|
String |
toDetailedString()
Create a detailed multiline String representation of the builder state.
|
static String |
toDetailedString(IDBasedHierarchicClustering c)
Utility method to create a detailed string representation of a clustering.
|
public IDBasedHierarchicClusterBuidler(HierarchicClustering.Alignment alignemnt)
alignemnt
- Alignment of the clustering hierarchyLicenseException
- when appropriate license is not availablepublic static IDBasedHierarchicClusterBuidler newRootAlignedIdDBasedHierarchicClusterBuilder()
public int addNewCluster()
Note that it is not necessary to call this method; clusters are added implicitly.
public int clusterOf(int structureID)
Opposed to HierarchicClustering.clusterOf(java.lang.Object)
this method expects the given structure
to be present in the current state of the clustering.
structureID
- Structure ID to look upIllegalArgumentException
- when the given structure is not part of the clusteringpublic boolean hasParent(int clusterID)
This method expects the given cluster to be part of the current state of the clusteing.
clusterID
- ClusterID to look upIllegalArgumentException
- when the given cluster is not part of the clusteringpublic int[] getImmediateLeaves(int clusterID)
clusterID
- Cluster IDIllegalArgumentException
- when the given cluster is not part of the clusteringpublic int[] getAllLeaves(int clusterID)
clusterID
- Cluster IDIllegalArgumentException
- when the given cluster is not part of the clusteringpublic int[] getChildClusters(int clusterID)
clusterID
- Cluster DIIllegalArgumentException
- when the given cluster is not part of the clusteringpublic int getParentClusterID(int clusterID)
clusterID
- Cluster ID to look upIllegalArgumentException
- when the given cluster is not part of the clustering or it has no parent
associatedpublic boolean isStructurePresent(int structureId)
structureId
- Structure ID to checktrue
when given structure is present in the clusteringpublic void removeStructure(int structureID)
This modification operation ensures valid and consistent state by throwing exception when given structure is not part of any cluster. Cluster representant references are also removed.
structureID
- StructureID to removepublic int getStructureImmediateParentCluster(int structureID)
structureID
- StructureIDIllegalArgumentException
- when given structure is not presentpublic boolean isEmpty()
public void detachToRootCluster(int clusterID)
This modification operation expects that the given cluster is a child of another cluster
clusterID
- clusterID to removepublic boolean isClusterRepresentantSet(int clusterID)
clusterID
- cluster IDIllegalArgumentException
- when given cluster is not assignedpublic int getClusterRepresentant(int clusterID)
clusterID
- cluster IDIllegalArgumentException
- when given cluster has no cluster representant setpublic void setClusterRepresentant(int structureID, int clusterID)
structureID
- Cluster representant structure IDclusterID
- Associated clusterpublic void setClusterPreferredLevel(int clusterID, double level)
IDBasedAssignerBuilder.setClusterLevel(int, double)
of the optional
IDBasedAssignerBuilder
.clusterID
- Cluster IDlevel
- Levelpublic void setLeafPreferredLevel(int leafID, double level)
IDBasedAssignerBuilder.setLeafLevel(int, double)
of the optional
IDBasedAssignerBuilder
.leafID
- Leaf IDlevel
- Levelpublic IDBasedClusterBuilderSpec newCluster()
addNewCluster()
then returns a wrapper for further operations.public IDBasedClusterBuilderSpec newRootCluster()
addNewCluster()
then returns a wrapper for further operations.public IDBasedClusterBuilderSpec cluster(int representedClusterId)
representedClusterId
- Cluster ID to representpublic void addStructureToCluster(int structureID, int parentClusterID)
structureID
- Structure ID to addparentClusterID
- Associated parent clusterIllegalArgumentException
- when structure is already added to another clusterpublic void addChildCluster(int childClusterID, int parentClusterID)
childClusterID
- Cluster ID to add as a childparentClusterID
- Associated parent clusterIllegalArgumentException
- when structure is already added to another clusterpublic String toDetailedString()
public IDBasedHierarchicClustering build(IDBasedAssignerBuilder assignerBuilder)
Derive the preferred level assigner (HierarchicClustering.getPreferredAssigner()
) from the given
assigner builder.
assignerBuilder
- Preferred level assignment source.IllegalStateException
- when a preferred level info is set to any cluster or leafpublic IDBasedHierarchicClustering build()
When any level info is previously set then it will be the preferred assigner. Otherwise the preferred level
assigner (returned by HierarchicClustering.getPreferredAssigner()
) will be the
graph depth based level assigner HierarchicClustering.unitPathAssigner()
.
public static String toDetailedString(IDBasedHierarchicClustering c)
c
- Clustering to traverse