1 | <?php |
||
12 | class Backpropagation implements Training |
||
13 | { |
||
14 | /** |
||
15 | * @var Network |
||
16 | */ |
||
17 | private $network; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $theta; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $sigmas; |
||
28 | |||
29 | /** |
||
30 | * @param Network $network |
||
31 | * @param int $theta |
||
32 | */ |
||
33 | public function __construct(Network $network, int $theta = 1) |
||
38 | |||
39 | /** |
||
40 | * @param array $samples |
||
41 | * @param array $targets |
||
42 | * @param float $desiredError |
||
43 | * @param int $maxIterations |
||
44 | */ |
||
45 | public function train(array $samples, array $targets, float $desiredError = 0.001, int $maxIterations = 10000) |
||
55 | |||
56 | /** |
||
57 | * @param array $samples |
||
58 | * @param array $targets |
||
59 | * @param float $desiredError |
||
60 | * |
||
61 | * @return int |
||
62 | */ |
||
63 | private function trainSamples(array $samples, array $targets, float $desiredError): int |
||
78 | |||
79 | /** |
||
80 | * @param array $sample |
||
81 | * @param array $target |
||
82 | */ |
||
83 | private function trainSample(array $sample, array $target) |
||
102 | |||
103 | /** |
||
104 | * @param Neuron $neuron |
||
105 | * @param array $target |
||
106 | * @param int $key |
||
107 | * @param bool $lastLayer |
||
108 | * |
||
109 | * @return float |
||
110 | */ |
||
111 | private function getSigma(Neuron $neuron, array $target, int $key, bool $lastLayer): float |
||
126 | |||
127 | /** |
||
128 | * @param Neuron $neuron |
||
129 | * |
||
130 | * @return float |
||
131 | */ |
||
132 | private function getPrevSigma(Neuron $neuron): float |
||
142 | |||
143 | /** |
||
144 | * @param array $result |
||
145 | * @param array $target |
||
146 | * @param float $desiredError |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | private function isResultWithinError(array $result, array $target, float $desiredError) |
||
160 | } |
||
161 |