1 | <?php |
||
9 | class Adaline extends Perceptron |
||
10 | { |
||
11 | /** |
||
12 | * Batch training is the default Adaline training algorithm |
||
13 | */ |
||
14 | public const BATCH_TRAINING = 1; |
||
15 | |||
16 | /** |
||
17 | * Online training: Stochastic gradient descent learning |
||
18 | */ |
||
19 | public const ONLINE_TRAINING = 2; |
||
20 | |||
21 | /** |
||
22 | * Training type may be either 'Batch' or 'Online' learning |
||
23 | * |
||
24 | * @var string|int |
||
25 | */ |
||
26 | protected $trainingType; |
||
27 | |||
28 | /** |
||
29 | * Initalize an Adaline (ADAptive LInear NEuron) classifier with given learning rate and maximum |
||
30 | * number of iterations used while training the classifier <br> |
||
31 | * |
||
32 | * Learning rate should be a float value between 0.0(exclusive) and 1.0 (inclusive) <br> |
||
33 | * Maximum number of iterations can be an integer value greater than 0 <br> |
||
34 | * If normalizeInputs is set to true, then every input given to the algorithm will be standardized |
||
35 | * by use of standard deviation and mean calculation |
||
36 | * |
||
37 | * @throws \Exception |
||
38 | */ |
||
39 | public function __construct( |
||
40 | float $learningRate = 0.001, |
||
41 | int $maxIterations = 1000, |
||
42 | bool $normalizeInputs = true, |
||
43 | int $trainingType = self::BATCH_TRAINING |
||
44 | ) { |
||
45 | if (!in_array($trainingType, [self::BATCH_TRAINING, self::ONLINE_TRAINING])) { |
||
46 | throw new Exception('Adaline can only be trained with batch and online/stochastic gradient descent algorithm'); |
||
47 | } |
||
48 | |||
49 | $this->trainingType = $trainingType; |
||
50 | |||
51 | parent::__construct($learningRate, $maxIterations, $normalizeInputs); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Adapts the weights with respect to given samples and targets |
||
56 | * by use of gradient descent learning rule |
||
57 | */ |
||
58 | protected function runTraining(array $samples, array $targets) |
||
75 | } |
||
76 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.