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
[x] 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:
[x] My code follows the code style of this project.
[x] My change requires a change to the documentation.
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: