Example #1
0
 public function test($repeat = 100)
 {
     while ($repeat--) {
         $ll = new HyperLogLog\Basic($this->pValue);
         $i = 100000000 + $this->random();
         $r = mt_rand(1, 4);
         $end = $i + $this->i * $r;
         while ($i <= $end) {
             $ll->add($i += $r);
         }
         $this->average[0] += $this->i;
         $count = $ll->count();
         $this->average[1] += $count;
         $this->average[2] += $this->i;
         $this->results[] = array($this->i, $count, $this->i);
     }
 }
Example #2
0
 public function test($repeat = 100)
 {
     while ($repeat--) {
         $keep = array();
         $ll = new HyperLogLog\Basic($this->pValue);
         $total = 0;
         while (1) {
             $total++;
             $rand = $this->random();
             $keep[$rand] = 1;
             $ll->add($rand);
             if (count($keep) >= $this->i) {
                 break;
             }
         }
         $this->average[0] += count($keep);
         $count = $ll->count();
         $this->average[1] += $count;
         $this->average[2] += $total;
         $this->results[] = array(count($keep), $count, $total);
     }
 }
Example #3
0
<?php

include __DIR__ . '/../vendor/autoload.php';
include __DIR__ . '/randomGenerator.php';
$set1 = randomSet();
$set2 = randomSet();
echo "Number of words in set 1: " . count($set1) . "\n";
echo "Number of words in set 2: " . count($set2) . "\n";
$union = array_merge($set1, $set2);
echo "Number of words in union: " . count($union) . "\n";
echo "------\nCardinality of union\n";
echo $card = cardinality($union) . "\n";
echo "------\nLogLog\n";
$log_log1 = new HyperLogLog\Basic(14);
foreach ($set1 as $word) {
    $log_log1->add($word);
}
echo "Added set 1\n";
$log_log2 = new HyperLogLog\Basic(14);
foreach ($set2 as $word) {
    $log_log2->add($word);
}
echo "Added set 2\n";
$log_log1->union($log_log2);
echo "Union complete\n";
$count = $log_log1->count() . "\n";
echo $count . 'error: ' . number_format(($count - $card) / ($card / 100.0), 3) . '%' . PHP_EOL;
Example #4
0
<?php

include __DIR__ . '/../vendor/autoload.php';
include __DIR__ . '/randomGenerator.php';
$words = randomSet();
echo "Number of words\n" . count($words) . "\n";
echo "------\nCardinality\n";
echo $card = cardinality($words) . "\n";
echo "------\nLogLog\n";
$log_log = new HyperLogLog\Basic();
foreach ($words as $word) {
    $log_log->add($word);
}
$count = $log_log->count() . "\n";
echo $count . 'error: ' . number_format(($count - $card) / ($card / 100.0), 3) . '%' . PHP_EOL;