Skip to content

Bug: transformed_range is empty when i_best_alpha == 0 #28

Description

@tobias-zehnder

Description

In the pcvl branch of alpha selection, transformed_range becomes an empty list when i_best_alpha == 0. This happens because pl_alphas[0] is the maximum value, causing np.argmax() to return 0. As a result, np.arange(i_best_alpha) generates an empty array, leading to a failure in np.argmax(transformed_pl_alphas).

Expected Behavior

The code should handle cases where i_best_alpha == 0 by skipping the transformation step and directly assigning best_alpha, best_l1_ratio, and best_pl_score from the original values.

Proposed Fix

Modify the code to check for i_best_alpha == 0 and handle it explicitly.

Code Reference

sparsesurv/sparsesurv/cv.py

Lines 553 to 565 in 90b5292

transformed_range = np.arange(i_best_alpha)
transformed_pl_alphas = pl_alphas[transformed_range] - (
((pl_best_alpha - pl_alpha_max) / sparsity_best_alpha)
* n_coefs[transformed_range]
)
transformed_i_best_alpha = np.argmax(transformed_pl_alphas)
this_best_pl_transformed = transformed_pl_alphas[
transformed_i_best_alpha
]
if this_best_pl_transformed > best_pl_score:
best_alpha = l1_alphas[transformed_i_best_alpha]
best_l1_ratio = l1_ratio
best_pl_score = this_best_pl_transformed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions