Skip to content

BUG: coerce scalar hidden_layer_sizes - #158

Merged
tylerjereddy merged 1 commit into
lanl:mainfrom
sdtemple:sdtemple_issue_136_layers_index_error
Nov 22, 2026
Merged

tylerjereddy merged 1 commit into
lanl:mainfrom
sdtemple:sdtemple_issue_136_layers_index_error

Conversation

@sdtemple

Copy link
Copy Markdown
Collaborator

Fixes #136
Supercedes #137

Summary:

  • Used the sklearn.neural_network approach to handling a scalar hidden_layer_sizes in MLP-based estimators.
  • Duplicated this for partial_fit and fit methods in the standard and ensemble estimators
  • Added 4 regression tests for these fixes

NOTES:

  • The fix currently duplicates this coercion in fit and partial_fit for the standard and ensemble estimators. That could be enhanced via MAINT: reduce initialization logic duplication #153
  • The coercion line of list() probably isn't necessary, but I am explicitly following the code style written by sklearn.neural_network for its MLP-based estimators
  • self.hidden_layer_sizes is not modified by the coercion in fit, in following the sklearn standard to not modify variables in __init__
  • partial_fit does not have the check that min() < 1, as that was an oversight from previous commits, and therefore out of scope here. That would be easily addressed, though, by MAINT: reduce initialization logic duplication #153

SI disclosure: I had Claude Sonnet make these changes based in conversation in #136 and #137. In particular, I had it implement the bug fix that I explicitly wrote in #136.

* SI disclosure: I had Claude Sonnet make these changes
	based in conversation in gh_136 and gh_137. In
	particular, I had it implement the bug fix that
	I explicitly wrote in gh_136.

* Used the sklearn.neural_network approach to handling
	a scalar hidden_layer_sizes in MLP-based estimators.

* Duplicated this for partial_fit and fit methods in the
	standard and ensemble estimators

* Added 4 regression tests for these fixes
@sdtemple

Copy link
Copy Markdown
Collaborator Author

My main arguments here to use my proposed design is:

  1. Always defer to how sklearn code when possible
  2. We don't need the complexity of an np.ndarray. This small coerced variable only needs to be able to slice and index for the for loop that initializes the network weights.

Per #137 (comment)

Strictly speaking, there is no need to think about code design for a hypothetical array API implementation #129. That enhancement PR is not guaranteed to be merged anytime soon or ever, but it is worth noting that np.atleast_1d does not have a standard xp implementation and would require array-api-extras https://data-apis.org/array-api-extra/generated/array_api_extra.atleast_nd.html

@sdtemple

Copy link
Copy Markdown
Collaborator Author

Some of the pytest checks appear to have failed because of #98 . I'll try right now to see if I can get a solution for that issue.

@tylerjereddy tylerjereddy added the bug Something isn't working label Nov 20, 2026
@tylerjereddy tylerjereddy added this to the 0.3.0 milestone Nov 20, 2026

@tylerjereddy tylerjereddy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that all 12 test cases correctly fail before the source patch is applied, and that all lines of code in the diff are covered by testing.

I'm not a huge fan of the code duplication and asymmetry in input validation between fit() and partial_fit(), but I can live with it for now.

Separate from my manual review, Opus 5.5 had some complaints, one of which crosses the threshold for opening a new issue, but I won't block on it here.

@tylerjereddy

Copy link
Copy Markdown
Collaborator

CI failure unrelated.

@tylerjereddy
tylerjereddy merged commit 768bf3c into lanl:main Nov 22, 2026
23 of 25 checks passed
@tylerjereddy

Copy link
Copy Markdown
Collaborator

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: IndexError when hidden_layer_sizes is a scalar

2 participants