Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generalized discrete optimizer for non-binary integer problems? #400

Closed
ddathan opened this issue May 5, 2020 · 5 comments
Closed

Generalized discrete optimizer for non-binary integer problems? #400

ddathan opened this issue May 5, 2020 · 5 comments
Labels
stale Not much activity here

Comments

@ddathan
Copy link

ddathan commented May 5, 2020

Is your feature request related to a problem? Please describe.
I am trying to use PSO to optimize the number of neurons in each layer of a neural network and thus require an integer implementation of the PSO algorithm. As I understand it at the moment there is only an "off the shelf" implementation of a binary version for discrete problems.

Describe the solution you'd like
A generalized implementation of the discrete PSO algorithm for integer variables with user defined bounds.

I understand this may be possible to put together from the base modules so alternatively some direction of how this could be achieved would be greatly appreciated as I have had difficulty when attempting to do so myself.

Many thanks,

@whzup
Copy link
Collaborator

whzup commented May 5, 2020

Hello @ddathan, and welcome to pyswarms!:smile: So I think this is an integer programming problem. The integer aspect may be a bit hard to implement, though. This kind of optimization should be possible but at the moment this needs some additional parts (I'm guessing). A quick Google search yielded this paper. Maybe this gives some direction as to how to theoretically build it up. Maybe an adjustment to the calculation of the positions and velocities already suffices. I'll have a look at it this week 😃.

@whzup
Copy link
Collaborator

whzup commented May 7, 2020

Hey @ddathan

I attached the source for a custom optimizer for integer programming. As we have already been thinking about making a tutorial on how to make a custom optimizer this was the perfect excuse to create a template 😄. The custom optimizer just casts all positions and velocities to integers and I'm not 100% how the convergence behaves in this case. I tried to comment on the crucial bits but if you still have questions about the code feel free to ask! 👍
integer_optimizer.txt

@ddathan
Copy link
Author

ddathan commented May 7, 2020

This looks fantastic, many thanks for the great work and support!

@msat59
Copy link
Contributor

msat59 commented May 21, 2020

Hey @ddathan

I attached the source for a custom optimizer for integer programming. As we have already been thinking about making a tutorial on how to make a custom optimizer this was the perfect excuse to create a template . The custom optimizer just casts all positions and velocities to integers and I'm not 100% how the convergence behaves in this case. I tried to comment on the crucial bits but if you still have questions about the code feel free to ask!
integer_optimizer.txt

I like this method which is the best one; but the easiest and fastest one is to convert desired positions to int in the objective function, and leave other as float. So if one is not familiar with writing the custom optimizer, can use below method.

def objfun(pos):
    layer1=round(pos[0])   # int number
    layer2=round(pos[1])
    x1 = pos[2]    # float number 
    ...
    ...
    return cost
    

@stale
Copy link

stale bot commented Jun 20, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale Not much activity here label Jun 20, 2020
@stale stale bot closed this as completed Jun 23, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
stale Not much activity here
Projects
None yet
Development

No branches or pull requests

3 participants