Phpml\Association\Apriori::candidates PHP Method

candidates() private method

Calculates frequent k item sets, where count($samples) == $k - 1.
private candidates ( array $samples ) : array
$samples array
return array
    private function candidates(array $samples) : array
    {
        $candidates = [];
        foreach ($samples as $p) {
            foreach ($samples as $q) {
                if (count(array_merge(array_diff($p, $q), array_diff($q, $p))) != 2) {
                    continue;
                }
                $candidate = array_unique(array_merge($p, $q));
                if ($this->contains($candidates, $candidate)) {
                    continue;
                }
                foreach ((array) $this->samples as $sample) {
                    if ($this->subset($sample, $candidate)) {
                        $candidates[] = $candidate;
                        continue 2;
                    }
                }
            }
        }
        return $candidates;
    }