PHP中的神经网络实现,已打包供Composer使用。

v1.3 2017-01-30 15:16 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:40:48 UTC


README

PHP中的神经网络实现,已打包供Composer使用。

基于Edward Akerboom的Tremani神经网络,但进行了简化、整理并打包以供Composer使用。

安装

通过Composer安装Brainy,如下所示

composer require lambdacasserole/brainy

或者,如果您正在使用PHAR(确保php.exe可执行文件在您的PATH中)

php composer.phar require lambdacasserole/brainy

使用方法

创建新的神经网络实例,如下所示

// Create a new neural network with 3 input neurons, one layer of 4 hidden neurons, and 1 output neuron.
$network = new NeuralNetwork(3, 4, 1);

将训练数据添加到您的网络中,如下

// Add training data to the network. In this case, we want the network to learn the 'XOR' function.
$network->addTrainingData([-1, -1, 1], [-1]);
$network->addTrainingData([-1, 1, 1], [1]);
$network->addTrainingData([1, -1, 1], [1]);
$network->addTrainingData([1, 1, 1], [-1]);

然后开始训练

// Train in a maximum of 1000 epochs to a maximum error rate of 0.01.
$success = $network->train(1000, 0.01);

现在开始使用它

$output = $network->calculate([-1, -1, 1]); // Gives [-1].
$output = $network->calculate([-1, 1, 1]); // Gives [1].

兼容性

使用新的数组语法和扩展运算符,因此不支持5.6之前的任何PHP版本。

进一步阅读

原始仓库包含更全面的文档,尽管由于此版本中对其进行的一些修改,可能需要稍作调整。