Skip to content

Conversation

Copy link

Copilot AI commented Dec 12, 2025

KMeans.find_centers() called _has_converged() before self.oldmu was initialized to a valid value, causing TypeError: object of type 'NoneType' has no len() on first iteration.

Changes

  • Initialize self.oldmu to K distinct arrays with infinity values before entering convergence loop
  • Ensures convergence check can safely access len(self.oldmu) and returns False on first iteration
  • Uses list comprehension to create independent array objects
# Before the convergence loop in find_centers()
self.oldmu = [np.array([float('inf')] * len(X[0])) for _ in range(K)]

iter = 0
while not self._has_converged() and iter < nitermax:
    self.oldmu = self.mu
    # ...

The infinity values guarantee initial centers differ from self.mu, allowing the algorithm to run while maintaining correct convergence detection.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 12, 2025 11:58
Co-authored-by: michael-petersen <19195541+michael-petersen@users.noreply.github.com>
Co-authored-by: michael-petersen <19195541+michael-petersen@users.noreply.github.com>
Co-authored-by: michael-petersen <19195541+michael-petersen@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on Draft HDF5 converter Fix self.oldmu initialization causing TypeError in KMeans.find_centers() Dec 12, 2025
@michael-petersen michael-petersen marked this pull request as ready for review December 15, 2025 14:57
@michael-petersen michael-petersen merged commit ffe8f19 into hdf5 Dec 15, 2025
@michael-petersen michael-petersen deleted the copilot/sub-pr-29-yet-again branch December 15, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants