1 | <?php |
||
12 | class Adaline extends Perceptron |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Batch training is the default Adaline training algorithm |
||
17 | */ |
||
18 | const BATCH_TRAINING = 1; |
||
19 | |||
20 | /** |
||
21 | * Online training: Stochastic gradient descent learning |
||
22 | */ |
||
23 | const ONLINE_TRAINING = 2; |
||
24 | |||
25 | /** |
||
26 | * The function whose result will be used to calculate the network error |
||
27 | * for each instance |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected static $errorFunction = 'output'; |
||
32 | |||
33 | /** |
||
34 | * Training type may be either 'Batch' or 'Online' learning |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $trainingType; |
||
39 | |||
40 | /** |
||
41 | * Initalize an Adaline (ADAptive LInear NEuron) classifier with given learning rate and maximum |
||
42 | * number of iterations used while training the classifier <br> |
||
43 | * |
||
44 | * Learning rate should be a float value between 0.0(exclusive) and 1.0 (inclusive) <br> |
||
45 | * Maximum number of iterations can be an integer value greater than 0 <br> |
||
46 | * If normalizeInputs is set to true, then every input given to the algorithm will be standardized |
||
47 | * by use of standard deviation and mean calculation |
||
48 | * |
||
49 | * @param int $learningRate |
||
50 | * @param int $maxIterations |
||
51 | */ |
||
52 | public function __construct(float $learningRate = 0.001, int $maxIterations = 1000, |
||
63 | |||
64 | /** |
||
65 | * Adapts the weights with respect to given samples and targets |
||
66 | * by use of gradient descent learning rule |
||
67 | */ |
||
68 | protected function runTraining() |
||
85 | |||
86 | /** |
||
87 | * Returns the direction of gradient given the desired and actual outputs |
||
88 | * |
||
89 | * @param int $desired |
||
90 | * @param int $output |
||
91 | * @return int |
||
92 | */ |
||
93 | protected function gradient($desired, $output) |
||
97 | |||
98 | /** |
||
99 | * Updates the weights of the network given the direction of the |
||
100 | * gradient for each sample |
||
101 | * |
||
102 | * @param array $updates |
||
103 | */ |
||
104 | protected function updateWeights(array $updates) |
||
122 | } |
||
123 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.