连接4与神经网络:评估草案+进一步的步骤

caw*_*caw 7 artificial-intelligence game-ai neural-network

我想构建一个使用人工神经网络工作的Connect 4引擎 - 仅仅因为我对ANN很着迷.

我创建了以下ANN结构草案.会有用吗?这些连接是否正确(即使是交叉连接)?

替代文字

你能帮我起草这个ANN的UML类图吗?

我想将董事会代表作为其输入提供给ANN.输出应该是选择的举动.

以后应该使用强化学习学习,并且应该应用sigmoid函数.该引擎将与人类玩家对抗.并且根据游戏的结果,应该调整权重.

我在找什么......

......主要是编码问题.从抽象思维到编码越远,它就越好.

Ale*_*ler 3

下面是我在搞乱神经网络时如何组织设计和代码的。这里的代码(显然)是伪代码,大致遵循面向对象的约定。

从下往上开始,你将拥有你的神经元。每个神经元需要能够保存它对传入连接的权重、用于保存传入连接数据的缓冲区以及其传出边缘的列表。每个神经元需要能够做三件事:

  • 一种从传入边缘接受数据的方法
  • 一种处理输入数据和权重以制定该神经元将发送的值的方法
  • 在传出边缘发送该神经元值的一种方法

从代码角度来看,这转化为:

// Each neuron needs to keep track of this data
float in_data[]; // Values sent to this neuron
float weights[]; // The weights on each edge
float value; // The value this neuron will be sending out
Neuron out_edges[]; // Each Neuron that this neuron should send data to

// Each neuron should expose this functionality
void accept_data( float data ) {
    in_data.append(data); // Add the data to the incoming data buffer
}
void process() {
    value = /* result of combining weights and incoming data here */;
}
void send_value() {
    foreach ( neuron in out_edges ) {
        neuron.accept_data( value );
    }
}
Run Code Online (Sandbox Code Playgroud)

接下来,我发现如果创建一个包含神经元列表的 Layer 类,则最简单。(很有可能跳过这个类,只让你的 NeuralNetwork 保存一个神经元列表。我发现使用 Layer 类在组织和调试方面更容易。)每个层都应该公开以下功能:

  • 使每个神经元“放电”
  • 返回该层所包围的原始神经元数组。(当您需要执行诸如在神经网络的第一层中手动填充输入数据之类的操作时,这非常有用。)

从代码角度来看,这转化为:

//Each layer needs to keep track of this data.
Neuron[] neurons;

//Each layer should expose this functionality.
void fire() {
    foreach ( neuron in neurons ) {
        float value = neuron.process();
        neuron.send_value( value );
    }
}
Neuron[] get_neurons() {
    return neurons;
}
Run Code Online (Sandbox Code Playgroud)

最后,您有一个 NeuralNetwork 类,它包含层列表、使用初始数据设置第一层的方法、学习算法以及运行整个神经网络的方法。在我的实现中,我通过添加由单个假神经元组成的第四层来收集最终的输出数据,该假神经元只是缓冲所有传入数据并返回该数据。

// Each neural network needs to keep track of this data.
Layer[] layers;

// Each neural network should expose this functionality
void initialize( float[] input_data ) {
    foreach ( neuron in layers[0].get_neurons() ) {
        // do setup work here
    }
}
void learn() {
    foreach ( layer in layers ) {
        foreach ( neuron in layer ) {
            /* compare the neuron's computer value to the value it
             * should have generated and adjust the weights accordingly
             */
        }
    }
}
void run() {
    foreach (layer in layers) {
        layer.fire();
    }
}
Run Code Online (Sandbox Code Playgroud)

我建议从向后传播作为学习算法开始,因为它被认为是最容易实现的。当我从事这项工作时,我很难找到该算法的非常简单的解释,但我的笔记将该网站列为一个很好的参考。

我希望这足以让您开始!