MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / update_header

Function update_header

machine_learning/frequent_pattern_growth.py:173–210  ·  view source on GitHub ↗

Update the header table with a node link. Args: node_to_test: The node to be updated in the header table. target_node: The node to link to. Example: >>> data_set = [ ... ['A', 'B', 'C'], ... ['A', 'C'], ... ['A', 'B', 'E'], ... ['A', 'B'

(node_to_test: TreeNode, target_node: TreeNode)

Source from the content-addressed store, hash-verified

171
172
173def update_header(node_to_test: TreeNode, target_node: TreeNode) -> TreeNode:
174 """
175 Update the header table with a node link.
176
177 Args:
178 node_to_test: The node to be updated in the header table.
179 target_node: The node to link to.
180
181 Example:
182 >>> data_set = [
183 ... ['A', 'B', 'C'],
184 ... ['A', 'C'],
185 ... ['A', 'B', 'E'],
186 ... ['A', 'B', 'C', 'E'],
187 ... ['B', 'E']
188 ... ]
189 >>> min_sup = 2
190 >>> fp_tree, header_table = create_tree(data_set, min_sup)
191 >>> fp_tree
192 TreeNode('Null Set', 1, None)
193 >>> node1 = TreeNode("A", 3, None)
194 >>> node2 = TreeNode("B", 4, None)
195 >>> node1
196 TreeNode('A', 3, None)
197 >>> node1 = update_header(node1, node2)
198 >>> node1
199 TreeNode('A', 3, None)
200 >>> node1.node_link
201 TreeNode('B', 4, None)
202 >>> node2.node_link is None
203 True
204 """
205 while node_to_test.node_link is not None:
206 node_to_test = node_to_test.node_link
207 if node_to_test.node_link is None:
208 node_to_test.node_link = target_node
209 # Return the updated node
210 return node_to_test
211
212
213def ascend_tree(leaf_node: TreeNode, prefix_path: list[str]) -> None:

Callers 2

update_treeFunction · 0.85
mine_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected