mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-07 16:03:59 +00:00
test abstraction from LayeredNetwork
This commit is contained in:
parent
12ee62bbca
commit
ddb3cc367b
@ -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;
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,5 +6,4 @@ namespace Phpml\NeuralNetwork\Network;
|
||||
|
||||
class MultilayerPerceptron extends LayeredNetwork
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user