Python interpreter error, x takes no arguments (1 given)
Make sure, that all of your class methods (updateVelocity
, updatePosition
, ...) take at least one positional argument, which is canonically named self
and refers to the current instance of the class.
When you call particle.updateVelocity()
, the called method implicitly gets an argument: the instance, here particle
as first parameter.
Your updateVelocity()
method is missing the explicit self
parameter in its definition.
Should be something like this:
def updateVelocity(self):
for x in range(0,len(self.velocity)):
self.velocity[x] = 2*random.random()*(self.pbestx[x]-self.current[x]) + 2 \
* random.random()*(self.gbest[x]-self.current[x])
Your other methods (except for __init__
) have the same problem.
Python implicitly passes the object to method calls, but you need to explicitly declare the parameter for it. This is customarily named self
:
def updateVelocity(self):