예제 #1
0
 private static function recurse($uids)
 {
     // Base Case
     if (empty($uids)) {
         return $uids;
     }
     // Loop over each user id
     foreach ($uids as $uid) {
         // Seed this cluster
         $cluster = new Cluster($uid);
         // Loop over each user id again
         foreach ($uids as $uid2) {
             // Add the user id if it is within the threshold
             if ($uid == $uid2) {
                 continue;
             }
             $dist = self::distance($uid, $uid2);
             if ($dist <= self::$threshold) {
                 $cluster->add_user($uid2);
             }
         }
         // Only save this cluster if it is the largest one
         if (!isset($max) || $cluster->size() > $max->size()) {
             $max = $cluster;
         }
         unset($cluster);
     }
     // Remove cluster from uids
     $uids = array_diff($uids, $max->users);
     // Return all of the clusters
     return array_merge(array($max), self::recurse($uids));
 }