Skip to content

Commit 3395b42

Browse files
committed
Renaming variables from snake_case to camelCase
1 parent 70e9da4 commit 3395b42

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/FPGrowth.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,20 @@ protected function findFrequentPatterns(array $transactions): array
104104
protected function generateAssociationRules(array $patterns): array
105105
{
106106
$rules = [];
107-
foreach (array_keys($patterns) as $itemsetStr) {
108-
$itemset = explode(',', $itemsetStr);
109-
$upper_support = $patterns[$itemsetStr];
110-
for ($i = 1; $i < count($itemset); $i++) {
111-
$combinations = new Combinations($itemset, $i);
107+
foreach (array_keys($patterns) as $pattern) {
108+
$itemSet = explode(',', $pattern);
109+
$upperSupport = $patterns[$pattern];
110+
for ($i = 1; $i < count($itemSet); $i++) {
111+
$combinations = new Combinations($itemSet, $i);
112112
foreach ($combinations->generator() as $antecedent) {
113113
sort($antecedent);
114114
$antecedentStr = implode(',', $antecedent);
115-
$consequent = array_diff($itemset, $antecedent);
115+
$consequent = array_diff($itemSet, $antecedent);
116116
sort($consequent);
117117
$consequentStr = implode(',', $consequent);
118118
if (isset($patterns[$antecedentStr])) {
119-
$lower_support = $patterns[$antecedentStr];
120-
$confidence = floatval($upper_support) / $lower_support;
119+
$lowerSupport = $patterns[$antecedentStr];
120+
$confidence = floatval($upperSupport) / $lowerSupport;
121121
if ($confidence >= $this->confidence) {
122122
$rules[] = [$antecedentStr, $consequentStr, $confidence];
123123
}

src/FPTree.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class FPTree
2020
* Initialize the tree.
2121
* @param array $transactions
2222
* @param int $threshold
23-
* @param $root_value
24-
* @param int $root_count
23+
* @param $rootValue
24+
* @param int $rootCount
2525
*/
26-
public function __construct(array $transactions, int $threshold, $root_value, int $root_count)
26+
public function __construct(array $transactions, int $threshold, $rootValue, int $rootCount)
2727
{
2828
$this->frequent = $this->findFrequentItems($transactions, $threshold);
2929
$this->headers = $this->buildHeaderTable();
30-
$this->root = $this->buildFPTree($transactions, $root_value, $root_count, $this->frequent);
30+
$this->root = $this->buildFPTree($transactions, $rootValue, $rootCount, $this->frequent);
3131
}
3232

3333
/**
@@ -75,29 +75,29 @@ protected function buildHeaderTable(): array
7575
/**
7676
* Build the FP tree and return the root node.
7777
* @param $transactions
78-
* @param $root_value
79-
* @param $root_count
78+
* @param $rootValue
79+
* @param $rootCount
8080
* @param $frequent
8181
* @return FPNode
8282
*/
83-
protected function buildFPTree($transactions, $root_value, $root_count, &$frequent): FPNode
83+
protected function buildFPTree($transactions, $rootValue, $rootCount, &$frequent): FPNode
8484
{
85-
$root = new FPNode($root_value, $root_count, null);
85+
$root = new FPNode($rootValue, $rootCount, null);
8686
arsort($frequent);
8787
foreach ($transactions as $transaction) {
88-
$sorted_items = [];
88+
$sortedItems = [];
8989
foreach ($transaction as $item) {
9090
if (isset($frequent[$item])) {
91-
$sorted_items[] = $item;
91+
$sortedItems[] = $item;
9292
}
9393
}
9494

95-
usort($sorted_items, function ($a, $b) use ($frequent) {
95+
usort($sortedItems, function ($a, $b) use ($frequent) {
9696
return $frequent[$b] <=> $frequent[$a];
9797
});
9898

99-
if (count($sorted_items) > 0) {
100-
$this->insertTree($sorted_items, $root);
99+
if (count($sortedItems) > 0) {
100+
$this->insertTree($sortedItems, $root);
101101
}
102102
}
103103
return $root;
@@ -131,10 +131,10 @@ protected function insertTree(array $items, FPNode $node): void
131131
}
132132

133133
// Call function recursively.
134-
$remaining_items = array_slice($items, 1, null);
134+
$remainingItems = array_slice($items, 1, null);
135135

136-
if (count($remaining_items) > 0) {
137-
$this->insertTree($remaining_items, $child);
136+
if (count($remainingItems) > 0) {
137+
$this->insertTree($remainingItems, $child);
138138
}
139139
}
140140

@@ -146,17 +146,17 @@ protected function insertTree(array $items, FPNode $node): void
146146
*/
147147
protected function treeHasSinglePath(FPNode $node): bool
148148
{
149-
$num_children = count($node->children);
149+
$childrenCount = count($node->children);
150150

151-
if ($num_children > 1) {
151+
if ($childrenCount > 1) {
152152
return false;
153153
}
154154

155-
if ($num_children === 0) {
155+
if ($childrenCount === 0) {
156156
return true;
157157
}
158158

159-
return $this->treeHasSinglePath($node->children[array_key_first($node->children)]);
159+
return $this->treeHasSinglePath(current($node->children));
160160
}
161161

162162
/**
@@ -238,15 +238,15 @@ protected function generatePatternList(): array
238238
protected function mineSubTrees(int $threshold): array
239239
{
240240
$patterns = [];
241-
$mining_order = $this->frequent;
242-
asort($mining_order);
243-
$mining_order = array_keys($mining_order);
241+
$miningOrder = $this->frequent;
242+
asort($miningOrder);
243+
$miningOrder = array_keys($miningOrder);
244244

245245
// Get items in tree in reverse order of occurrences.
246-
foreach ($mining_order as $item) {
246+
foreach ($miningOrder as $item) {
247247
/** @var FPNode[] $suffixes */
248248
$suffixes = [];
249-
$conditional_tree_input = [];
249+
$conditionalTreeInput = [];
250250
$node = $this->headers[$item];
251251

252252
// Follow node links to get a list of all occurrences of a certain item.
@@ -265,20 +265,20 @@ protected function mineSubTrees(int $threshold): array
265265
$parent = $parent->parent;
266266
}
267267
for ($i = 0; $i < $frequency; $i++) {
268-
$conditional_tree_input[] = $path;
268+
$conditionalTreeInput[] = $path;
269269
}
270270
}
271271

272272
// Now we have the input for a subtree, so construct it and grab the patterns.
273-
$subtree = new FPTree($conditional_tree_input, $threshold, $item, $this->frequent[$item]);
274-
$subtree_patterns = $subtree->minePatterns($threshold);
273+
$subtree = new FPTree($conditionalTreeInput, $threshold, $item, $this->frequent[$item]);
274+
$subtreePatterns = $subtree->minePatterns($threshold);
275275

276276
// Insert subtree patterns into main patterns dictionary.
277-
foreach (array_keys($subtree_patterns) as $pattern) {
277+
foreach (array_keys($subtreePatterns) as $pattern) {
278278
if (in_array($pattern, $patterns)) {
279-
$patterns[$pattern] += $subtree_patterns[$pattern];
279+
$patterns[$pattern] += $subtreePatterns[$pattern];
280280
} else {
281-
$patterns[$pattern] = $subtree_patterns[$pattern];
281+
$patterns[$pattern] = $subtreePatterns[$pattern];
282282
}
283283
}
284284
}

0 commit comments

Comments
 (0)