1 | <?php |
||
13 | class Adaline extends Perceptron |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Batch training is the default Adaline training algorithm |
||
18 | */ |
||
19 | const BATCH_TRAINING = 1; |
||
20 | |||
21 | /** |
||
22 | * Online training: Stochastic gradient descent learning |
||
23 | */ |
||
24 | const ONLINE_TRAINING = 2; |
||
25 | |||
26 | /** |
||
27 | * The function whose result will be used to calculate the network error |
||
28 | * for each instance |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected static $errorFunction = 'output'; |
||
33 | |||
34 | /** |
||
35 | * Training type may be either 'Batch' or 'Online' learning |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $trainingType; |
||
40 | |||
41 | /** |
||
42 | * @var Normalizer |
||
43 | */ |
||
44 | private $normalizer; |
||
45 | |||
46 | /** |
||
47 | * Initalize an Adaline (ADAptive LInear NEuron) classifier with given learning rate and maximum |
||
48 | * number of iterations used while training the classifier <br> |
||
49 | * |
||
50 | * Learning rate should be a float value between 0.0(exclusive) and 1.0 (inclusive) <br> |
||
51 | * Maximum number of iterations can be an integer value greater than 0 <br> |
||
52 | * If normalizeInputs is set to true, then every input given to the algorithm will be standardized |
||
53 | * by use of standard deviation and mean calculation |
||
54 | * |
||
55 | * @param int $learningRate |
||
56 | * @param int $maxIterations |
||
57 | */ |
||
58 | public function __construct(float $learningRate = 0.001, int $maxIterations = 1000, |
||
72 | |||
73 | /** |
||
74 | * @param array $samples |
||
75 | * @param array $targets |
||
76 | */ |
||
77 | public function train(array $samples, array $targets) |
||
85 | |||
86 | /** |
||
87 | * Adapts the weights with respect to given samples and targets |
||
88 | * by use of gradient descent learning rule |
||
89 | */ |
||
90 | protected function runTraining() |
||
121 | |||
122 | /** |
||
123 | * Returns the direction of gradient given the desired and actual outputs |
||
124 | * |
||
125 | * @param int $desired |
||
126 | * @param int $output |
||
127 | * @return int |
||
128 | */ |
||
129 | protected function gradient($desired, $output) |
||
133 | |||
134 | /** |
||
135 | * @param array $sample |
||
136 | * @return mixed |
||
137 | */ |
||
138 | public function predictSample(array $sample) |
||
148 | } |
||
149 |
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.