Particle Swarm Optimizer in Ruby?

P

Phil Tomson

Does anyone have a Particle Swarm Optimization package written in Ruby?

Phil
 
L

Lyndon Samson

------=_Part_15727_5284107.1125985321127
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I dont think you'll get too many false positives searching for that on=20
Google :)

------=_Part_15727_5284107.1125985321127--
 
H

horndude77

I wrote one up as a ruby learning exercise. I'll post you the code if
you like. (I'll probably have to go back through it to make sure
there's nothing too embarassing) I don't think there's much out there
otherwise. The algorithm itself is quite simple.
(http://en.wikipedia.org/wiki/Particle_swarm_optimization) Consider
coding it yourself if you like. Let me know.

------horndude77

Maybe this would be a good ruby quiz?
 
P

Phil Tomson

I wrote one up as a ruby learning exercise. I'll post you the code if
you like. (I'll probably have to go back through it to make sure
there's nothing too embarassing) I don't think there's much out there
otherwise. The algorithm itself is quite simple.
(http://en.wikipedia.org/wiki/Particle_swarm_optimization) Consider
coding it yourself if you like. Let me know.

I've started coding it. Just thought I'd ask first to see if anyone had
one already. One question, though: While the algorithm itself is rather
simple it seems that the main complexity is in adapting it to some
specific problems. I want to use it to optimize an atomic cluster such
that the configuration of the cluster and the distances between atoms
result in a cluster which has minimum energy. This means that each
'particle' in the PSO needs to adjust the positions of atoms in the
cluster (in 3D space) and then test the configuration. Lots of
parameters to consider (several atoms each with x,y,z to adjust)
Maybe this would be a good ruby quiz?

Perhaps so.

Phil
 
H

horndude77

Yeah, the hard part of PSO and genetic algorithms is coming up with a
way to represent the problem with a vector of a predetermined length
(ok well with genetic algorithms there are ways around the set vector
length actually). In your case it looks pretty simple actually. I
assume that the number of atoms is constant (If not then it would take
a lot more thought). Just string out all of their positions together
into one long vector. When you calculate the fitness you just have to
know how to pull out the correct position of each individual atom from
the particle's position vector. (If they're not unique then I guess
this doesn't really matter.) I believe that this would work just fine.

-----horndude77
 
P

Phil Tomson

Yeah, the hard part of PSO and genetic algorithms is coming up with a
way to represent the problem with a vector of a predetermined length
(ok well with genetic algorithms there are ways around the set vector
length actually). In your case it looks pretty simple actually. I
assume that the number of atoms is constant (If not then it would take
a lot more thought). Just string out all of their positions together
into one long vector. When you calculate the fitness you just have to
know how to pull out the correct position of each individual atom from
the particle's position vector. (If they're not unique then I guess
this doesn't really matter.) I believe that this would work just fine.

Yes, this is essentially what I'm doing.

There are 7 atoms in a cluster and each atom has a location in 3D space.
7 atoms * 3 dimensions yields 21 parameters to adjust (or put another
way, there are 21 dimensions in the problems space). I give the PSO a
list of 3D points (7 points) and then that list gets represented by a
Vector of 21 Floats. Pretty easy to translate between the two
representations. Not quite done yet, but I hope to get to the point where
I'm running it tomorrow.

The Framework philosophy part:
The only problem now is that the PSO code I've created is quite specific
to this particular problem. I thought about how I could generalize it to
make it useful for any kind of optimization problem, but after about an
hour of thinking about that I went ahead and just started coding it up
for this particular problem... so I'm not sure my PSO code will be very
useful for anyone else. I created an Ant Colony Optimization framework
which can be adapted to many different types of problems, but it's
flexibility actually makes it quite unwieldly, so maybe I'm better off
not making the PSO so flexible. So much for code reuse :-(

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top