Note that there are some explanatory texts on larger screens.

plurals
  1. POPython compiler error, x takes no arguments (1 given)
    primarykey
    data
    text
    <p>I'm writing a small piece of python as a homework assignment, and I'm not getting it to run! I don't have that much Python-experience, but I know quite a lot of Java. I'm trying to implement a Particle Swarm Optimization algorithm, and here's what I have: </p> <pre><code>class Particle: def __init__(self,domain,ID): self.ID = ID self.gbest = None self.velocity = [] self.current = [] self.pbest = [] for x in range(len(domain)): self.current.append(random.randint(domain[x][0],domain[x][1])) self.velocity.append(random.randint(domain[x][0],domain[x][1])) self.pbestx = self.current def updateVelocity(): 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]) def updatePosition(): for x in range(0,len(self.current)): self.current[x] = self.current[x] + self.velocity[x] def updatePbest(): if costf(self.current) &lt; costf(self.best): self.best = self.current def psoOptimize(domain,costf,noOfParticles=20, noOfRuns=30): particles = [] for i in range(noOfParticles): particle = Particle(domain,i) particles.append(particle) for i in range(noOfRuns): Globalgbest = [] cost = 9999999999999999999 for i in particles: if costf(i.pbest) &lt; cost: cost = costf(i.pbest) Globalgbest = i.pbest for particle in particles: particle.updateVelocity() particle.updatePosition() particle.updatePbest(costf) particle.gbest = Globalgbest return determineGbest(particles,costf) </code></pre> <p>Now, I see no reason why this shouldn't work. However, when I run it, I get this error:</p> <p><strong>"TypeError: updateVelocity() takes no arguments (1 given)"</strong></p> <p>I don't understand! I'm not giving it any arguments!</p> <p>Thanks for the help,</p> <p>Linus</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload