mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-08 08:08:07 +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)
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
return parent::attach($point, $data);
|
||||
parent::attach($point, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,8 +230,8 @@ class Space extends SplObjectStorage
|
||||
protected function initializeKMPPClusters(int $clustersNumber)
|
||||
{
|
||||
$clusters = [];
|
||||
$position = rand(1, count($this));
|
||||
for ($i = 1, $this->rewind(); $i < $position && $this->valid(); $i++, $this->next());
|
||||
$this->rewind();
|
||||
|
||||
$clusters[] = new Cluster($this, $this->current()->getCoordinates());
|
||||
|
||||
$distances = new SplObjectStorage();
|
||||
|
@ -193,7 +193,8 @@ class Matrix
|
||||
$product = [];
|
||||
$multiplier = $matrix->toArray();
|
||||
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;
|
||||
for ($k = 0; $k < $this->columns; ++$k) {
|
||||
$product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];
|
||||
|
Loading…
Reference in New Issue
Block a user