mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-10 00:37:55 +00:00
cs-fixer
This commit is contained in:
parent
26be771668
commit
01a2499754
@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Clustering;
|
||||
|
||||
interface Clusterer
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cluster(array $samples);
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Clustering;
|
||||
@ -70,7 +71,8 @@ class DBSCAN implements Clusterer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSamplesInRegion($localSample, $samples) {
|
||||
private function getSamplesInRegion($localSample, $samples)
|
||||
{
|
||||
$region = [];
|
||||
|
||||
foreach ($samples as $index => $sample) {
|
||||
@ -88,7 +90,8 @@ class DBSCAN implements Clusterer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function expandCluster($samples, &$visited) {
|
||||
private function expandCluster($samples, &$visited)
|
||||
{
|
||||
$cluster = [];
|
||||
|
||||
foreach ($samples as $index => $sample) {
|
||||
@ -105,5 +108,4 @@ class DBSCAN implements Clusterer
|
||||
|
||||
return $cluster;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace tests\Clustering;
|
||||
@ -7,14 +8,13 @@ use Phpml\Clustering\DBSCAN;
|
||||
|
||||
class DBSCANTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testDBSCANSamplesClustering()
|
||||
{
|
||||
$samples = [[1, 1], [8, 7], [1, 2], [7, 8], [2, 1], [8, 9]];
|
||||
|
||||
$clustered = [
|
||||
[[1, 1], [1, 2], [2, 1]],
|
||||
[[8, 7], [7, 8], [8, 9]]
|
||||
[[8, 7], [7, 8], [8, 9]],
|
||||
];
|
||||
|
||||
$dbscan = new DBSCAN($epsilon = 2, $minSamples = 3);
|
||||
@ -28,12 +28,11 @@ class DBSCANTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$clustered = [
|
||||
[[1, 1], [1, -1], [-1, -1], [-1, 1]],
|
||||
[[6, 6],[5, 6],[7, 8],[7, 7]]
|
||||
[[6, 6], [5, 6], [7, 8], [7, 7]],
|
||||
];
|
||||
|
||||
$dbscan = new DBSCAN($epsilon = 3, $minSamples = 4);
|
||||
|
||||
$this->assertEquals($clustered, $dbscan->cluster($samples));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user