Skip to content

Commit

Permalink
test abstraction from LayeredNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Aug 7, 2016
1 parent 12ee62b commit ddb3cc3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
14 changes: 11 additions & 3 deletions src/Phpml/NeuralNetwork/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace Phpml\NeuralNetwork;

interface Network extends Node
interface Network
{

/**
* @param mixed $input
*/
Expand All @@ -15,6 +14,15 @@ public function setInput($input);
/**
* @return array
*/
public function getLayers(): array;
public function getOutput(): array;

/**
* @param Layer $layer
*/
public function addLayer(Layer $layer);

/**
* @return Layer[]
*/
public function getLayers(): array;
}
37 changes: 33 additions & 4 deletions src/Phpml/NeuralNetwork/Network/LayeredNetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,62 @@

namespace Phpml\NeuralNetwork\Network;

use Phpml\NeuralNetwork\Layer;
use Phpml\NeuralNetwork\Network;

abstract class LayeredNetwork implements Network
{
/**
* @var Layer[]
*/
protected $layers;

/**
* @return array
* @param Layer $layer
*/
public function addLayer(Layer $layer)
{
$this->layers[] = $layer;
}

/**
* @return Layer[]
*/
public function getLayers(): array
{
return $this->layers;
}

/**
* @return Layer
*/
public function getOutputLayer(): Layer
{
return $this->layers[count($this->layers) - 1];
}

/**
* @return float
* @return array
*/
public function getOutput(): float
public function getOutput(): array
{
$result = [];
foreach ($this->getOutputLayer()->getNodes() as $neuron) {
$result[] = $neuron->getOutput();
}

return $result;
}

/**
* @param mixed $input
*/
public function setInput($input)
{
$firstLayer = $this->layers[0];

foreach ($firstLayer->getNodes() as $key => $neuron) {
$neuron->setInput($input[$key]);
}
}

}
1 change: 0 additions & 1 deletion src/Phpml/NeuralNetwork/Network/MultilayerPerceptron.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class MultilayerPerceptron extends LayeredNetwork
{

}
2 changes: 1 addition & 1 deletion src/Phpml/NeuralNetwork/Training.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Training
* @param array $samples
* @param array $targets
* @param float $desiredError
* @param int $maxIterations
* @param int $maxIterations
*/
public function train(array $samples, array $targets, float $desiredError = 0.001, int $maxIterations = 10000);
}
5 changes: 1 addition & 4 deletions src/Phpml/NeuralNetwork/Training/Backpropagation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

class Backpropagation implements Training
{

/**
* @param array $samples
* @param array $targets
* @param float $desiredError
* @param int $maxIterations
* @param int $maxIterations
*/
public function train(array $samples, array $targets, float $desiredError = 0.001, int $maxIterations = 10000)
{

}

}

0 comments on commit ddb3cc3

Please sign in to comment.