示例#1
0
 public function testClusterMinMax()
 {
     $cluster = new Cluster();
     $cluster[] = new Point(1, 2);
     $this->assertEquals($cluster->getXMin(), 1);
     $this->assertEquals($cluster->getXMax(), 1);
     $this->assertEquals($cluster->getYMin(), 2);
     $this->assertEquals($cluster->getYMax(), 2);
     $cluster[] = new Point(2, 2);
     $this->assertEquals($cluster->getXMin(), 1);
     $this->assertEquals($cluster->getXMax(), 2);
     $this->assertEquals($cluster->getYMin(), 2);
     $this->assertEquals($cluster->getYMax(), 2);
     $cluster[] = new Point(1.5, 2);
     $this->assertEquals($cluster->getXMin(), 1);
     $this->assertEquals($cluster->getXMax(), 2);
     $this->assertEquals($cluster->getYMin(), 2);
     $this->assertEquals($cluster->getYMax(), 2);
     $cluster[] = new Point(0, 2);
     $this->assertEquals($cluster->getXMin(), 0);
     $this->assertEquals($cluster->getXMax(), 2);
     $this->assertEquals($cluster->getYMin(), 2);
     $this->assertEquals($cluster->getYMax(), 2);
     $cluster[] = new Point(0, -2);
     $this->assertEquals($cluster->getXMin(), 0);
     $this->assertEquals($cluster->getXMax(), 2);
     $this->assertEquals($cluster->getYMin(), -2);
     $this->assertEquals($cluster->getYMax(), 2);
     $cluster[] = new Point(0, 10);
     $this->assertEquals($cluster->getXMin(), 0);
     $this->assertEquals($cluster->getXMax(), 2);
     $this->assertEquals($cluster->getYMin(), -2);
     $this->assertEquals($cluster->getYMax(), 10);
 }
示例#2
0
文件: DBSCAN.php 项目: npoggi/aloja
 private function init($data)
 {
     // Fill search class with all the points
     $this->search->setData($data);
     // Initialize auxiliary variables
     $this->visited = array();
     $this->cluster = array();
     $this->noise = array();
     // Check if any parameter is missing to calculate heuristic values
     if ($this->eps === null || $this->minPoints === null) {
         $data_clustered = $data;
         if (!$data_clustered instanceof Cluster) {
             // Convert array to cluster
             $data_clustered = new Cluster($data);
         }
         // Calculate heuristic values and set them as DBSCAN parameters
         $x_diff = $data_clustered->getXMax() - $data_clustered->getXMin();
         $y_diff = $data_clustered->getYMax() - $data_clustered->getYMin();
         $this->eps = max($x_diff, $y_diff) / $this::HEURISTIC_DIVISION;
         if ($this->eps <= 0) {
             // If all the points are in the same place, eps will be 0,
             // and because the distance comparison is a "less strict"
             // all points would be noise. This way they will all belong
             // to the same cluster
             $this->eps = 1;
         }
         $this->minPoints = 1;
     }
 }