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

Decorator for cost functions #228

Closed
whzup opened this issue Aug 16, 2018 · 0 comments
Closed

Decorator for cost functions #228

whzup opened this issue Aug 16, 2018 · 0 comments
Assignees
Labels
documentation Documentation improvements or fixes enhancement Feature requests unit tests Test-related changes v.1.1.0 In pipeline for next version

Comments

@whzup
Copy link
Collaborator

whzup commented Aug 16, 2018

Is your feature request related to a problem? Please describe.
Until now the cost function had to return the shape (n_particles, ) which has caused some problems in using the package.

Describe the solution you'd like
I propose a decorator so we can just mark the cost function:

@pyswarms.cost
def cost_function(x, **kwargs):
    cost = do_something_costly(x, **kwargs)
    return cost

This lets the user write a "strategy" that has to be applied to all the particles in the swarm in order to compute the cost.

Describe alternatives you've considered
N/A

Additional context
The hypothesis module has something similar where users can create custom strategies for the testing by using a decorator

@whzup whzup added enhancement Feature requests documentation Documentation improvements or fixes unit tests Test-related changes v.1.1.0 In pipeline for next version labels Aug 16, 2018
@whzup whzup self-assigned this Aug 16, 2018
@whzup whzup mentioned this issue Aug 16, 2018
9 tasks
@ljvmiranda921 ljvmiranda921 changed the title Create a decorator to mark and vectorize the cost function Decorator for cost functions Aug 17, 2018
ljvmiranda921 pushed a commit that referenced this issue Aug 20, 2018
Resolves #228 

Added a cost function decorator which allows the user to write a cost
function that serves as a model for how the cost will be computed for
every one particle. The decorator is tested with a pytest file where the
shape and the equality with an example function is checked. I added a
note to the documentation that some numpy functions will return arrays
with single values in them.
ljvmiranda921 pushed a commit that referenced this issue Jan 29, 2019
Resolves #228 

Added a cost function decorator which allows the user to write a cost
function that serves as a model for how the cost will be computed for
every one particle. The decorator is tested with a pytest file where the
shape and the equality with an example function is checked. I added a
note to the documentation that some numpy functions will return arrays
with single values in them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation improvements or fixes enhancement Feature requests unit tests Test-related changes v.1.1.0 In pipeline for next version
Projects
None yet
Development

No branches or pull requests

2 participants