test abstraction from LayeredNetwork

This commit is contained in:
Arkadiusz Kondas 2016-08-07 23:41:02 +02:00
parent 12ee62bbca
commit ddb3cc367b
5 changed files with 52 additions and 19 deletions

View File

@ -4,9 +4,8 @@ declare (strict_types = 1);
namespace Phpml\NeuralNetwork;
interface Network extends Node
interface Network
{
/**
* @param mixed $input
*/
@ -15,6 +14,15 @@ interface Network extends Node
/**
* @return array
*/
public function getLayers(): array;
public function getOutput(): array;
/**
* @param Layer $layer
*/
public function addLayer(Layer $layer);
/**
* @return Layer[]
*/
public function getLayers(): array;
}

View File

@ -4,25 +4,51 @@ declare (strict_types = 1);
namespace Phpml\NeuralNetwork\Network;
use Phpml\NeuralNetwork\Layer;
use Phpml\NeuralNetwork\Network;
abstract class LayeredNetwork implements Network
{
/**
* @var Layer[]
*/
protected $layers;
/**
* @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 array
*/
public function getLayers(): array
{
}
/**
* @return float
*/
public function getOutput(): float
public function getOutput(): array
{
$result = [];
foreach ($this->getOutputLayer()->getNodes() as $neuron) {
$result[] = $neuron->getOutput();
}
return $result;
}
/**
@ -30,7 +56,10 @@ abstract class LayeredNetwork implements Network
*/
public function setInput($input)
{
$firstLayer = $this->layers[0];
foreach ($firstLayer->getNodes() as $key => $neuron) {
$neuron->setInput($input[$key]);
}
}
}

View File

@ -6,5 +6,4 @@ namespace Phpml\NeuralNetwork\Network;
class MultilayerPerceptron extends LayeredNetwork
{
}

View File

@ -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);
}

View File

@ -8,16 +8,13 @@ use Phpml\NeuralNetwork\Training;
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)
{
}
}