Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #620 #635

Merged
merged 7 commits into from
Aug 25, 2024
Merged

Fix for issue #620 #635

merged 7 commits into from
Aug 25, 2024

Conversation

apanichella
Copy link
Contributor

This PR fixes the error in issue #620

The previous implementation can lead to division by zero or extremely large exponential values that can lead to overflow problems for constrained problems.

This PR fixes these errors as follows:

  • Regularization with epsilon: The small constant epsilon is added to each value of point[obj_index] before raising it to the power of x. This prevents the base of the exponentiation from becoming too small, which can lead to extremely large results when x is large.
  • Logarithm Handling: The logarithm calculation is adjusted to prevent taking the log of non-positive numbers.
  • Zero Handling: If the denominator (denominator) or the derivative (ff) is zero, the function returns a fallback value to avoid division by zero.

@muazhari
Copy link
Contributor

muazhari commented Aug 14, 2024

You are missing another error in this PR.

image

@apanichella
Copy link
Contributor Author

For which problem do you get this error? That would help me debugging the code

@muazhari
Copy link
Contributor

For which problem do you get this error? That would help me debugging the code

This: https://gist.github.com/muazhari/deed94f293489e95a75e95c057f5e98f

@apanichella
Copy link
Contributor Author

On my machine, I don't get that error. I have also tried with different seeds

@muazhari
Copy link
Contributor

muazhari commented Aug 14, 2024

Another error again in this: https://gist.github.com/muazhari/0825646b3767402b1899881836b36c42
image

I don't know if mixed variable modification to the GA algorithm is interoperable with agemoea2. I think it should because it uses the same abstraction in the superset class (GA), and is not specific to agemoea2.

@muazhari
Copy link
Contributor

On my machine, I don't get that error. I have also tried with different seeds

damn, how? My machine is currently a bit random as in my last GitHub issues to Pymoo, wsl, and Ray. Is it because intel stability issue? haha.

@muazhari
Copy link
Contributor

On my machine, I don't get that error. I have also tried with different seeds

I tried to run 3 times and still got the same error. Can you try to execute in different log levels? Or make sure the stdout/stderr not obstructed?

@apanichella
Copy link
Contributor Author

apanichella commented Aug 14, 2024

Another error again in this: https://gist.github.com/muazhari/0825646b3767402b1899881836b36c42 image

I don't know if mixed variable modification to the GA algorithm is interoperable with agemoea2. I think it should because it uses the same abstraction in the superset class (GA), and is not specific to agemoea2.

I also don't get this error on my machine (M3 Mac). But the last commit should consider/handle division with NaN and Inf value. This should prevent the error you have.

Actually, I am looking at the stack trace you have. It seems you are not using the code after my commits as the line f += np.power(point[obj_index], x) in your stack trace is now f += np.power(point[obj_index] + epsilon, x), which is the latest code.

@muazhari
Copy link
Contributor

muazhari commented Aug 14, 2024

Actually, I am looking at the stack trace you have. It seems you are not using the code after my commits as the line f += np.power(point[obj_index], x) in your stack trace is now f += np.power(point[obj_index] + epsilon, x), which is the latest code.

My bad. After ensuring to use your latest commit, both gists above did not display any errors.

@muazhari
Copy link
Contributor

muazhari commented Aug 14, 2024

For which problem do you get this error? That would help me debugging the code

This: https://gist.github.com/muazhari/deed94f293489e95a75e95c057f5e98f

Sorry, this first gist still has an error (the second gist is fixed). I don't know why the stack trace can't be displayed to the stdout when using logger/try-catch. After I removed it, the stack trace displayed the error. Please rerun the modified gist.

@apanichella
Copy link
Contributor Author

For which problem do you get this error? That would help me debugging the code

This: https://gist.github.com/muazhari/deed94f293489e95a75e95c057f5e98f

Sorry, this first gist still has an error (the second gist is fixed). I don't know why the stack trace can't be displayed to the stdout when using logger/try-catch. After I removed it, the stack trace displayed the error. Please rerun the modified gist.

It should be fixed with the last commit

@muazhari
Copy link
Contributor

In the second gist (https://gist.github.com/muazhari/0825646b3767402b1899881836b36c42), comes another warning:
image
In the first gist (https://gist.github.com/muazhari/deed94f293489e95a75e95c057f5e98f), still has an earlier error.
image

@apanichella
Copy link
Contributor Author

The last two commits should fix the issues in both gits. Let me know if you encounter more issues

@@ -209,7 +215,7 @@ def compute_geometry(front, extreme, n):
return p

@staticmethod
@jit(fastmath=True)
#@jit(nopython=True, fastmath=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it true to commenting this line?

def find_zero(point, n, precision):
x = 1

epsilon = 1e-10 # Small constant for regularization
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the epsilon of the numpy data type for consistency and precision? example: np.finfo(point.dtype).eps

Comment on lines +170 to +174
# Replace very small norms with 1 to prevent division by zero
nn[nn < 1e-8] = 1

distances = self.pairwise_distances(front, p)
distances[distances < 1e-8] = 1e-8 # Replace very small entries to prevent division by zero
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the epsilon of the numpy data type for consistency and precision? example: np.finfo(nn.dtype).eps and np.finfo(distances.dtype).eps.

@blankjul blankjul merged commit ad98c14 into anyoptimization:main Aug 25, 2024
1 check failed
@blankjul blankjul self-assigned this Aug 25, 2024
@blankjul
Copy link
Collaborator

I have merged the code for now. Please open a new PR if another fix is needed.

@blankjul
Copy link
Collaborator

Thanks @apanichella for taking care of it!

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.

3 participants