synaptic-net/lab
Composer 安装命令:
composer require synaptic-net/lab
包简介
A lightweight PHP library for building and training neural networks from scratch, featuring customizable neurons, activation functions, and backpropagation support.
README 文档
README
Synaptic Net is a lightweight PHP library for building and training simple neural networks from scratch.
It’s designed for learning and experimenting with how neurons, layers, activation functions, and backpropagation interact internally — without relying on any external machine learning frameworks.
Features
- Customizable neuron and layer classes
- Backpropagation training process implemented from scratch
- Multiple activation functions (Sigmoid, ReLU, etc.)
- Supports multilayer perceptrons (MLP)
- Educational and fully readable code structure
Installation
composer require synaptic-net/lab
Basic Example
Below is a simple example of how to create and train a multilayer neural network using Synaptic Net to learn the XOR problem:
$network = new SimpleNeuralNetwork([ (object)[ 'type' => SimpleLayer::class, 'typeNeuron' => SimpleNeuron::class, 'sizeNeuron' => 4, 'learningRate' => 0.2, 'activateFunction' => SigmoidActivateFunction::class, 'weights' => [ [rand(-100, 100) / 100, rand(-100, 100) / 100], [rand(-100, 100) / 100, rand(-100, 100) / 100], [rand(-100, 100) / 100, rand(-100, 100) / 100], [rand(-100, 100) / 100, rand(-100, 100) / 100], ], 'bias' => [0, 0, 0, 0] ], (object)[ 'type' => SimpleLayer::class, 'typeNeuron' => SimpleNeuron::class, 'sizeNeuron' => 1, 'learningRate' => 0.2, 'activateFunction' => SigmoidActivateFunction::class, 'weights' => [ [rand(-100, 100) / 100, rand(-100, 100) / 100, rand(-100, 100) / 100, rand(-100, 100) / 100] ], 'bias' => [0] ] ]); // XOR training data $training = [ [[0, 0], [0]], [[0, 1], [1]], [[1, 0], [1]], [[1, 1], [0]], [[0.1, 0.9], [1]], [[0.9, 0.1], [1]], [[0.8, 0.8], [0]], [[0.2, 0.2], [0]] ]; $stages = 5000; $network->learn($stages, $training); // Test results $tests = [ [[0, 0], [0]], [[0, 1], [1]], [[1, 0], [1]], [[1, 1], [0]], [[0.2, 0.8], [1]], [[0.9, 0.2], [1]], [[0.7, 0.7], [0]], [[0.3, 0.3], [0]] ]; echo "<h3>TEST MULTILAYER XOR RESULTS</h3>"; foreach ($tests as $val) { $inputs = $val[0]; $expected = $val[1][0]; $output = $network->activate($inputs); $result = round($output[0]); $color = $result == $expected ? 'green' : 'red'; $text = $result == $expected ? 'good' : 'bad'; echo "Input: [" . implode(',', $inputs) . "] → Output: " . number_format($output[0], 3) . " | Expected: $expected <span style='color:$color'>$text</span><br>"; }
Expected Output
TEST MULTILAYER XOR RESULTS
Input: [0,0] → Output: 0.035 | Expected: 0 good
Input: [0,1] → Output: 0.981 | Expected: 1 good
Input: [1,0] → Output: 0.987 | Expected: 1 good
Input: [1,1] → Output: 0.042 | Expected: 0 good
Input: [0.2,0.8] → Output: 0.739 | Expected: 1 good
Input: [0.9,0.2] → Output: 0.867 | Expected: 1 good
Input: [0.7,0.7] → Output: 0.061 | Expected: 0 good
Input: [0.3,0.3] → Output: 0.059 | Expected: 0 good
License
MIT License
See the LICENSE file for details.
synaptic-net/lab 适用场景与选型建议
synaptic-net/lab 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 synaptic-net/lab 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 synaptic-net/lab 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-19