微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 NEAT 的类型错误

如何解决带有 NEAT 的类型错误

我在尝试制作蛇形 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
 

config-Feedforward.txt 的部分代码

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)。

,

我犯的错误是我没有使用不存在的变量,还传递了一个数组作为输入,我猜这是不允许的?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。