mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-23 23:28:24 +00:00
extract functions from loops and remove unused code
This commit is contained in:
parent
637fd613b8
commit
f186aa9c0b
@ -61,7 +61,7 @@ class Space extends SplObjectStorage
|
|||||||
*/
|
*/
|
||||||
public function addPoint(array $coordinates, $data = null)
|
public function addPoint(array $coordinates, $data = null)
|
||||||
{
|
{
|
||||||
return $this->attach($this->newPoint($coordinates), $data);
|
$this->attach($this->newPoint($coordinates), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +74,7 @@ class Space extends SplObjectStorage
|
|||||||
throw new InvalidArgumentException('can only attach points to spaces');
|
throw new InvalidArgumentException('can only attach points to spaces');
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::attach($point, $data);
|
parent::attach($point, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -230,8 +230,8 @@ class Space extends SplObjectStorage
|
|||||||
protected function initializeKMPPClusters(int $clustersNumber)
|
protected function initializeKMPPClusters(int $clustersNumber)
|
||||||
{
|
{
|
||||||
$clusters = [];
|
$clusters = [];
|
||||||
$position = rand(1, count($this));
|
$this->rewind();
|
||||||
for ($i = 1, $this->rewind(); $i < $position && $this->valid(); $i++, $this->next());
|
|
||||||
$clusters[] = new Cluster($this, $this->current()->getCoordinates());
|
$clusters[] = new Cluster($this, $this->current()->getCoordinates());
|
||||||
|
|
||||||
$distances = new SplObjectStorage();
|
$distances = new SplObjectStorage();
|
||||||
|
@ -193,7 +193,8 @@ class Matrix
|
|||||||
$product = [];
|
$product = [];
|
||||||
$multiplier = $matrix->toArray();
|
$multiplier = $matrix->toArray();
|
||||||
for ($i = 0; $i < $this->rows; ++$i) {
|
for ($i = 0; $i < $this->rows; ++$i) {
|
||||||
for ($j = 0; $j < $matrix->getColumns(); ++$j) {
|
$columns = $matrix->getColumns();
|
||||||
|
for ($j = 0; $j < $columns; ++$j) {
|
||||||
$product[$i][$j] = 0;
|
$product[$i][$j] = 0;
|
||||||
for ($k = 0; $k < $this->columns; ++$k) {
|
for ($k = 0; $k < $this->columns; ++$k) {
|
||||||
$product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];
|
$product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user