Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Checklist: