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

pbcost default values set to inf #522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alipmv
Copy link

@alipmv alipmv commented Oct 20, 2023

In the custom loop example, the objective function is called twice, which is a problem for computationally expensive objective functions, only because the array of personal best did not have default values for the first iteration. This has been fixed by setting the default values of pbcost to inf.

Description

  • The second call of the objective function in the custom loop example has been deleted.

  • In the definition of the Swarm class in swarms.py, a default value setter has been defined for self.pbcost attribute.

Motivation and Context

Without a default value for my_swar.pbcost the compute_pbcost function would raise an error in the first iteration, as there is nothing to compare the current cost to. To avoid this error, the objective function was previously called twice in the custom loop example, and not just at the first iteration but at every iteration. This almost doubles runtime, which is a major problem for computationally expensive objective functions. To resolve this issue, the default value of swarm.pbcost has been set to np.inf, to ensure it will be overwritten in the first iteration.

How Has This Been Tested?

One can successfully run all of the example files after the change.

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.

In the custom loop example, the objective function is called twice, which is a problem for computationally expensive objective functions, only because the array of personal best did not have default values for the first iteration. This has been fixed by setting the default values of pbcost to inf.
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

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.

None yet

1 participant