1 | <?php |
||
19 | abstract class MultilayerPerceptron extends LayeredNetwork implements Estimator, IncrementalEstimator |
||
20 | { |
||
21 | use Predictable; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $classes = []; |
||
27 | |||
28 | /** |
||
29 | * @var ActivationFunction |
||
30 | */ |
||
31 | protected $activationFunction; |
||
32 | |||
33 | /** |
||
34 | * @var Backpropagation |
||
35 | */ |
||
36 | protected $backpropagation = null; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | private $inputLayerFeatures; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | private $hiddenLayers = []; |
||
47 | |||
48 | /** |
||
49 | * @var float |
||
50 | */ |
||
51 | private $learningRate; |
||
52 | |||
53 | /** |
||
54 | * @throws InvalidArgumentException |
||
55 | */ |
||
56 | public function __construct(int $inputLayerFeatures, array $hiddenLayers, array $classes, int $iterations = 10000, ?ActivationFunction $activationFunction = null, float $learningRate = 1) |
||
75 | |||
76 | public function train(array $samples, array $targets): void |
||
82 | |||
83 | /** |
||
84 | * @throws InvalidArgumentException |
||
85 | */ |
||
86 | public function partialTrain(array $samples, array $targets, array $classes = []): void |
||
97 | |||
98 | public function setLearningRate(float $learningRate) |
||
103 | |||
104 | /** |
||
105 | * @param mixed $target |
||
106 | */ |
||
107 | abstract protected function trainSample(array $sample, $target); |
||
108 | |||
109 | /** |
||
110 | * @return mixed |
||
111 | */ |
||
112 | abstract protected function predictSample(array $sample); |
||
113 | |||
114 | protected function reset(): void |
||
118 | |||
119 | private function initNetwork(): void |
||
130 | |||
131 | private function addInputLayer(int $nodes): void |
||
135 | |||
136 | private function addNeuronLayers(array $layers, ?ActivationFunction $activationFunction = null): void |
||
142 | |||
143 | private function generateSynapses(): void |
||
152 | |||
153 | private function addBiasNodes(): void |
||
160 | |||
161 | private function generateLayerSynapses(Layer $nextLayer, Layer $currentLayer): void |
||
169 | |||
170 | private function generateNeuronSynapses(Layer $currentLayer, Neuron $nextNeuron): void |
||
176 | |||
177 | private function trainSamples(array $samples, array $targets): void |
||
183 | } |
||
184 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: