问题描述
我在尝试制作蛇形 AI 时遇到 NEAT 类型错误:
#!/bin/bash
# duplicate file descriptor 1 on file descriptor 3
exec 3>&1
# Inform the user that a scan is in progress
printf "Scanning for networks in range...\nPlease wait..." | dialog \
--backtitle "$APP_TITLE" \
--title "Scanning Networks" \
--progressBox 10 40 2>&1 1>&3
# Perform the scan
scan=$(iwlist wlan0 scan)
# Close file descriptor 3
exec 3>&-
clear
grep -E "SSID|Authentication" <<<"$scan"
{
"$schema": "https://deno.land/x/denon@2.4.7/schema.json","scripts": {
"start": {
"cmd": "deno run app.ts","desc": "run my app.ts file","allow": [
"net"
],"tsconfig": "tsconfig.json"
}
},"watcher": {
"match": [
"app.ts","src/**/*.ts"
]
}
}
node_inputs.append(self.values[i] * w)
TypeError: can't multiply sequence by non-int of type 'float'
getData 函数的样子
class SnakeGame(object):
def __init__(self,genomes,config):
self.genomes = genomes
self.nets = []
for id,g in self.genomes:
net = neat.nn.FeedForwardNetwork.create(g,config)
self.nets.append(net)
g.fitness = 0
def game(self):
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
data = self.nets[0].activate(self.getData())
output = data.index(max(data))
解决方法
这里的问题是 'w' 是浮动的。考虑以下示例:
"a" * 5 # this makes "aaaaa"
["a"] * 5 # this makes ["a","a","a"]
在同样的逻辑中,写出像 ["a"] * 5.5
这样的东西是没有意义的。如果你这样做,你会得到你上面写的错误。所以弄清楚为什么 w
是一个浮点数而不是一个整数 - 可能是它的值是一个整数但表示为一个浮点数(例如 5.0)。
我犯的错误是我没有使用不存在的变量,还传递了一个数组作为输入,我猜这是不允许的?