jtet / 感知器
感知器的简单PHP实现。
dev-master
2021-02-04 14:00 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-28 14:44:08 UTC
README
什么是感知器?
"the perceptron is an algorithm for supervised classification of an input into one of two possible outputs.
It is a type of linear classifier, i.e. a classification algorithm that makes its predictions based on a
linear predictor function combining a set of weights with the feature vector describing a given input."
更多信息请访问 http://en.wikipedia.org/wiki/Perceptron
训练
while($p->getIterationError() > $x) { for ($i = 0; $i < count($inputVectors); $i++){ $p->train($inputVectors[$i], $outcomes[$i); } }
测试输入
echo $p->test($inputVector)? "True": "False";
示例
以下代码将感知器训练为NAND门
$p = new \JTet\Perceptron\Perceptron(2); $i = 0; while($i < 100000) { $input = array(0, 0); $output = 1; $p->train($input, $output); $input = array(0, 1); $output = 1; $p->train($input, $output); $input = array(1,0); $output = 1; $p->train($input, $output); $input = array(1,1); $output = 0; $p->train($input, $output); $i++; } echo $p->test(array(1,1))? "Incorrect\n": "Correct\n"; echo $p->test(array(0,1))? "Correct\n": "Incorrect\n"; echo $p->test(array(0,0))? "Correct\n": "Incorrect\n"; echo $p->test(array(1,0))? "Correct\n": "Incorrect\n";
获取感知器
将以下内容添加到您的composer.json文件中,并运行composer update。
"require": {
"jtet/perceptron": "dev-master"
}
许可证
感知器在OSL-3.0许可证下可供您使用。