Skip to content

Commit

Permalink
Change from theta to learning rate var name in NN (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonllao authored and akondas committed Nov 20, 2017
1 parent 333598b commit b1d40bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A multilayer perceptron (MLP) is a feedforward artificial neural network model t
* $hiddenLayers (array) - array with the hidden layers configuration, each value represent number of neurons in each layers
* $classes (array) - array with the different training set classes (array keys are ignored)
* $iterations (int) - number of training iterations
* $theta (int) - network theta parameter
* $learningRate (float) - the learning rate
* $activationFunction (ActivationFunction) - neuron activation function

```
Expand Down
10 changes: 5 additions & 5 deletions src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ abstract class MultilayerPerceptron extends LayeredNetwork implements Estimator,
protected $activationFunction;

/**
* @var int
* @var float
*/
private $theta;
private $learningRate;

/**
* @var Backpropagation
Expand All @@ -58,7 +58,7 @@ abstract class MultilayerPerceptron extends LayeredNetwork implements Estimator,
/**
* @throws InvalidArgumentException
*/
public function __construct(int $inputLayerFeatures, array $hiddenLayers, array $classes, int $iterations = 10000, ?ActivationFunction $activationFunction = null, int $theta = 1)
public function __construct(int $inputLayerFeatures, array $hiddenLayers, array $classes, int $iterations = 10000, ?ActivationFunction $activationFunction = null, float $learningRate = 1)
{
if (empty($hiddenLayers)) {
throw InvalidArgumentException::invalidLayersNumber();
Expand All @@ -73,7 +73,7 @@ public function __construct(int $inputLayerFeatures, array $hiddenLayers, array
$this->inputLayerFeatures = $inputLayerFeatures;
$this->hiddenLayers = $hiddenLayers;
$this->activationFunction = $activationFunction;
$this->theta = $theta;
$this->learningRate = $learningRate;

$this->initNetwork();
}
Expand All @@ -87,7 +87,7 @@ private function initNetwork(): void
$this->addBiasNodes();
$this->generateSynapses();

$this->backpropagation = new Backpropagation($this->theta);
$this->backpropagation = new Backpropagation($this->learningRate);
}

public function train(array $samples, array $targets): void
Expand Down
10 changes: 5 additions & 5 deletions src/Phpml/NeuralNetwork/Training/Backpropagation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Backpropagation
{
/**
* @var int
* @var float
*/
private $theta;
private $learningRate;

/**
* @var array
Expand All @@ -24,9 +24,9 @@ class Backpropagation
*/
private $prevSigmas = null;

public function __construct(int $theta)
public function __construct(float $learningRate)
{
$this->theta = $theta;
$this->learningRate = $learningRate;
}

/**
Expand All @@ -43,7 +43,7 @@ public function backpropagate(array $layers, $targetClass): void
if ($neuron instanceof Neuron) {
$sigma = $this->getSigma($neuron, $targetClass, $key, $i == $layersNumber);
foreach ($neuron->getSynapses() as $synapse) {
$synapse->changeWeight($this->theta * $sigma * $synapse->getNode()->getOutput());
$synapse->changeWeight($this->learningRate * $sigma * $synapse->getNode()->getOutput());
}
}
}
Expand Down

0 comments on commit b1d40bf

Please sign in to comment.