Skip to content

Commit

Permalink
extract functions from loops and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Aug 2, 2016
1 parent 637fd61 commit f186aa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Phpml/Clustering/KMeans/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function newPoint(array $coordinates)
*/
public function addPoint(array $coordinates, $data = null)
{
return $this->attach($this->newPoint($coordinates), $data);
$this->attach($this->newPoint($coordinates), $data);
}

/**
Expand All @@ -74,7 +74,7 @@ public function attach($point, $data = null)
throw new InvalidArgumentException('can only attach points to spaces');
}

return parent::attach($point, $data);
parent::attach($point, $data);
}

/**
Expand Down Expand Up @@ -230,8 +230,8 @@ private function initializeRandomClusters(int $clustersNumber)
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();
Expand Down
3 changes: 2 additions & 1 deletion src/Phpml/Math/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public function multiply(Matrix $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];
Expand Down

0 comments on commit f186aa9

Please sign in to comment.