Beispiel #1
0
 /**
  * @depends testOffsetSetOffsetGet
  */
 function testHashNull()
 {
     $map = new HashMap();
     $map->offsetSet(null, 1);
     $this->assertEquals(1, $map->offsetGet(null));
 }
 public function generateRulesBruteForce($largeItemSets, $metricThreshold, $upperBoundMinSuppAsInstances, $lowerBoundMinSuppAsInstances, $totalTransactions)
 {
     $rules = array();
     // new ArrayList<AssociationRule>();
     $largeItemSets->sort();
     $frequencyLookup = new HashMap();
     //   new HashMap<Collection<BinaryItem>, Integer>();
     $frequentBinaryItemset = $largeItemSets->getSet();
     // process each large item set
     foreach ($frequentBinaryItemset as $fis) {
         $frequencyLookup->offsetSet($fis->getItems(), $fis->getSupport());
         if (count($fis->getItems()) > 1) {
             // generate all the possible subsets for the premise
             $subset = array_fill(0, count($fis->getItems()), false);
             //array[fis.getItems().size()];
             $premise = null;
             $consequence = null;
             while (!is_null($premise = $this->getPremise($fis, $subset))) {
                 if (count($premise) > 0 && count($premise) < count($fis->getItems())) {
                     $consequence = $this->getConsequence($fis, $subset);
                     $totalSupport = $fis->getSupport();
                     $supportPremise = $frequencyLookup->offsetGet($premise);
                     $supportConsequence = $frequencyLookup->offsetGet($consequence);
                     // a candidate rule
                     $candidate = new DefaultAssociationRule($premise, $consequence, $supportPremise, $supportConsequence, $totalSupport, $totalTransactions);
                     if ($candidate->getPrimaryMetricValue() > $metricThreshold && $candidate->getTotalSupport() >= $lowerBoundMinSuppAsInstances && $candidate->getTotalSupport() <= $upperBoundMinSuppAsInstances) {
                         // accept this rule
                         $rules[] = $candidate;
                     }
                 }
                 $this->nextSubset($subset);
             }
         }
     }
     return $rules;
 }