pub fn validate_linkage_matrix<F: Float + FromPrimitive + Debug + PartialOrd + Display>(
linkage_matrix: ArrayView2<'_, F>,
n_observations: usize,
) -> Result<()>Expand description
Validates a linkage matrix for correctness
This function performs comprehensive validation of a linkage matrix to ensure it meets the mathematical requirements for hierarchical clustering.
§Arguments
linkage_matrix- The linkage matrix to validate (n-1 × 4)n_observations- Expected number of original observations
§Returns
Result<()>- Ok if valid, error with detailed message if invalid
§Validation Checks
- Matrix dimensions are correct (n-1 rows, 4 columns)
- Cluster indices are valid and in proper range
- Merge distances are non-negative and monotonic (for single/complete linkage)
- Cluster sizes are consistent and >= 2
- No self-merges (cluster merging with itself)
- All values are finite