python参数解释器_Python解释器错误,x不接受参数(给定1)

我在写一小段python作为家庭作业,我不能让它运行!我没有那么多的Python经验,但我知道很多Java。

我正在尝试实现一个粒子群优化算法,以下是我所拥有的: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) < 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) < 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)

现在,我不明白为什么这不应该起作用。

但是,当我运行它时,会出现以下错误:

“TypeError:updateVelocity()不接受参数(给定1)”

我不明白!我不给它任何理由!

谢谢你的帮助

莱纳斯

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值