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 duplicate cost function calls in optimize() implementations #266

Conversation

danielcorreia96
Copy link
Contributor

Description

Fixed duplicate cost function calls in optimize() implementations using a swarm pbest_cost initialization to np.inf.

Related Issue

Resolves: #257

Motivation and Context

As pointed out in #257, for each iteration of the algorithm, the cost function is being called twice in the current implementations. This leads to significant performance drawbacks in situations where the cost function is expensive to calculate.

Hence, we can just initialize the pbest_cost to np.inf in order to remove the second cost function call.

Full credits to @pdiaz2 for raising the issue and proposing this solution: I simply extracted the relevant changes from the solution provided via file (#257 (comment))

How Has This Been Tested?

  1. Ran tests locally
  2. Personal project

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Questions

  • Not sure if this PR requires changes in the documentation
  • Not sure if the code style is correct: I only ran "black pyswarms tests" before opening this PR (which formatted some files unrelated to the actual changes...)

@ljvmiranda921
Copy link
Owner

Hey @whzup , wanna help me out reviewing this one?

Copy link
Collaborator

@whzup whzup left a comment

Choose a reason for hiding this comment

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

I think that's a good solution. Seems like we had some redundancies there. Although, @ljvmiranda921 do you want this to go straight into the master branch?

@ljvmiranda921
Copy link
Owner

Hi @whzup ! Yes, I think we can treat this as a bugfix and release immediately. OK, I'll leave this to your judgement. If you're fine with this then I'll make the merge to master

@whzup
Copy link
Collaborator

whzup commented Feb 4, 2019

@ljvmiranda921 I think this works as it is, the tests run without errors so let us merge it 😄

@ljvmiranda921
Copy link
Owner

ljvmiranda921 commented Feb 4, 2019

@whzup ok then! will merge this now and do a patch release

@ljvmiranda921 ljvmiranda921 merged commit 0adef1a into ljvmiranda921:master Feb 4, 2019
@ljvmiranda921
Copy link
Owner

@all-contributors please add @danielcorreia96 for bug and code

@allcontributors
Copy link
Contributor

@ljvmiranda921

I've put up a pull request to add @danielcorreia96! 🎉

@ljvmiranda921
Copy link
Owner

@all-contributors please add @whzup for code, infrastructure, doc, and ideas

@allcontributors
Copy link
Contributor

@ljvmiranda921

I've put up a pull request to add @whzup! 🎉

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.

The cost function is called twice for an iteration?
3 participants