prior2024_bic_gradient_k

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

prior2024_bic_gradient_k(bic_scores: Sequence[float], k_values: Sequence[int]) → int[source]

Choose K the way Prior 2024 habitat_computation.optimal_k does.

They fit GMM for k in 1..5, take np.gradient of the BIC curve, then the first difference of that slope, and pick the k at the largest absolute change of slope (their i_max + 1 index into k_list). This is not minimum-BIC.

Parameters:
  • bic_scores – One BIC per candidate k, same order as k_values. Need at least three candidates.

  • k_values – Candidate habitat counts (Prior used range(1, 6)).

Returns:

The selected k.

Raises:

ValueError – If the two sequences differ in length or are shorter than three points (their second-difference needs three gaps).