fix(ga): Suppress divide-by-zero warning in NumPy solver #17

Merged
jono merged 1 commits from v0.4.1-dev into main 2025-10-27 16:26:58 +00:00
2 changed files with 5 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
# --- Core Metadata --- # --- Core Metadata ---
name = "polysolve" name = "polysolve"
version = "0.4.0" version = "0.4.1"
authors = [ authors = [
{ name="Jonathan Rampersad", email="jonathan@jono-rams.work" }, { name="Jonathan Rampersad", email="jonathan@jono-rams.work" },
] ]

View File

@@ -295,7 +295,8 @@ class Function:
y_calculated = np.polyval(self.coefficients, solutions) y_calculated = np.polyval(self.coefficients, solutions)
error = y_calculated - y_val error = y_calculated - y_val
ranks = np.where(error == 0, np.finfo(float).max, np.abs(1.0 / error)) with np.errstate(divide='ignore'):
ranks = np.where(error == 0, np.finfo(float).max, np.abs(1.0 / error))
# Sort solutions by fitness (descending) # Sort solutions by fitness (descending)
sorted_indices = np.argsort(-ranks) sorted_indices = np.argsort(-ranks)
@@ -345,7 +346,8 @@ class Function:
# After all generations, do one last ranking to find the best solutions # After all generations, do one last ranking to find the best solutions
y_calculated = np.polyval(self.coefficients, solutions) y_calculated = np.polyval(self.coefficients, solutions)
error = y_calculated - y_val error = y_calculated - y_val
ranks = np.where(error == 0, np.finfo(float).max, np.abs(1.0 / error)) with np.errstate(divide='ignore'):
ranks = np.where(error == 0, np.finfo(float).max, np.abs(1.0 / error))
sorted_indices = np.argsort(-ranks) sorted_indices = np.argsort(-ranks)
# Get the top 'sample_size' solutions the user asked for # Get the top 'sample_size' solutions the user asked for