LPPGrowth

class PAMI.localPeriodicPattern.basic.LPPGrowth.LPPGrowth(iFile, maxPer, maxSoPer, minDur, sep='\t')[source]

Bases: _localPeriodicPatterns

Description:

Local Periodic Patterns, which are patterns (sets of events) that have a periodic behavior in some non predefined time-intervals. A pattern is said to be a local periodic pattern if it appears regularly and continuously in some time-intervals. The maxSoPer (maximal period of spillovers) measure allows detecting time-intervals of variable lengths where a pattern is continuously periodic, while the minDur (minimal duration) measure ensures that those time-intervals have a minimum duration.

Reference:

Fournier-Viger, P., Yang, P., Kiran, R. U., Ventura, S., Luna, J. M.. (2020). Mining Local Periodic Patterns in a Discrete Sequence. Information Sciences, Elsevier, to appear. [ppt] DOI: 10.1016/j.ins.2020.09.044

Parameters:
  • iFile – str : Name of the Input file to mine complete set of local periodic pattern’s

  • oFile – str : Name of the output file to store complete set of local periodic patterns

  • minDur – str: Minimal duration in seconds between consecutive periods of time-intervals where a pattern is continuously periodic.

  • maxPer – float: Controls the maximum number of transactions in which any two items within a pattern can reappear.

  • maxSoPer – float: Controls the maximum number of time periods between consecutive periods of time-intervals where a pattern is continuously periodic.

  • sep – str : This variable is used to distinguish items from one another in a transaction. The default seperator is tab space. However, the users can override their default separator.

Attributes:
iFilestr

Input file name or path of the input file

oFilestr

Output file name or path of the output file

maxPerfloat

User defined maxPer value.

maxSoPerfloat

User defined maxSoPer value.

minDurfloat

User defined minDur value.

tsMinint / date

First time stamp of input data.

tsMaxint / date

Last time stamp of input data.

startTimefloat

Time when start of execution the algorithm.

endTimefloat

Time when end of execution the algorithm.

finalPatternsdict

To store local periodic patterns and its PTL.

tsListdict

To store items and its time stamp as bit vector.

rootTree

It is root node of transaction tree of whole input data.

PTLdict

Storing the item and its PTL.

itemslist

Storing local periodic item list.

sep: str

separator used to distinguish items from each other. The default separator is tab space.

Methods:
findSeparator(line)

Find the separator of the line which split strings.

creteLPPlist()

Create the local periodic patterns list from input data.

createTSList()

Create the tsList as bit vector from input data.

generateLPP()

Generate 1 length local periodic pattens by tsList and execute depth first search.

createLPPTree()

Create LPPTree of local periodic item from input data.

patternGrowth(tree, prefix, prefixPFList)

Execute pattern growth algorithm. It is important function in this program.

calculatePTL(tsList)

Calculate PTL from input tsList as integer list.

calculatePTLbit(tsList)

Calculate PTL from input tsList as bit vector.

mine()

Mining process will start from here.

getMemoryUSS()

Total amount of USS memory consumed by the mining process will be retrieved from this function.

getMemoryRSS()

Total amount of RSS memory consumed by the mining process will be retrieved from this function.

getRuntime()

Total amount of runtime taken by the mining process will be retrieved from this function.

getLocalPeriodicPatterns()

return local periodic patterns and its PTL

save(oFile)

Complete set of local periodic patterns will be loaded in to an output file.

getPatternsAsDataFrame()

Complete set of local periodic patterns will be loaded in to a dataframe.

Executing the code on terminal:

Format:

(.venv) $ python3 LPPMGrowth.py <inputFile> <outputFile> <maxPer> <minSoPer> <minDur>

Example Usage:

(.venv) $ python3 LPPMGrowth.py sampleDB.txt patterns.txt 0.3 0.4 0.5

Sample run of importing the code:

from PAMI.localPeriodicPattern.basic import LPPGrowth as alg

obj = alg.LPPGrowth(iFile, maxPer, maxSoPer, minDur)

obj.mine()

localPeriodicPatterns = obj.getPatterns()

print(f'Total number of local periodic patterns: {len(localPeriodicPatterns)}')

obj.save(oFile)

Df = obj.getPatternsAsDataFrame()

memUSS = obj.getMemoryUSS()

print(f'Total memory in USS: {memUSS}')

memRSS = obj.getMemoryRSS()

print(f'Total memory in RSS: {memRSS}')

runtime = obj.getRuntime()

print(f'Total execution time in seconds: {runtime})

Credits:

The complete program was written by So Nakamura under the supervision of Professor Rage Uday Kiran.

getMemoryRSS() float[source]

Total amount of RSS memory consumed by the mining process will be retrieved from this function

Returns:

returning RSS memory consumed by the mining process

Return type:

float

getMemoryUSS() float[source]

Total amount of USS memory consumed by the mining process will be retrieved from this function

Returns:

returning USS memory consumed by the mining process

Return type:

float

getPatterns() Dict[source]

Function to send the set of local periodic patterns after completion of the mining process

Returns:

returning frequent patterns

Return type:

dict

getPatternsAsDataFrame() DataFrame[source]

Storing final local periodic patterns in a dataframe

Returns:

returning local periodic patterns in a dataframe

Return type:

pd.DataFrame

getRuntime() float[source]

Calculating the total amount of runtime taken by the mining process

Returns:

returning total amount of runtime taken by the mining process

Return type:

float

mine() None[source]

Mining process start from here.

printResults() None[source]

This function is used to print the results

save(outFile: str) None[source]

Complete set of local periodic patterns will be loaded in to an output file

Parameters:

outFile (csv file) – name of the output file

Returns:

None

startMine() None[source]

Mining process start from here.

class PAMI.localPeriodicPattern.basic.LPPGrowth.Node[source]

Bases: object

A class used to represent the node of localPeriodicPatternTree

Attributes:
itemint

storing item of a node

parentnode

To maintain the parent of every node

childlist

To maintain the children of node

nodeLinknode

To maintain the next node of node

tidListset

To maintain timestamps of node

Methods:
getChild(itemName)

storing the children to their respective parent nodes

getChild(item: int) Node[source]

This function is used to get child node from the parent node

Parameters:

item (int) – item of the parent node

Returns:

if node have node of item, then return it. if node don’t have return []

Return type:

Node

class PAMI.localPeriodicPattern.basic.LPPGrowth.Tree[source]

Bases: object

A class used to represent the frequentPatternGrowth tree structure

Attributes:
rootnode

Represents the root node of the tree

nodeLinksdictionary

storing last node of each item

firstNodeLinkdictionary

storing first node of each item

Methods:
addTransaction(transaction,timeStamp)

creating transaction as a branch in frequentPatternTree

fixNodeLinks(itemName, newNode)

add newNode link after last node of item

deleteNode(itemName)

delete all node of item

createPrefixTree(path,timeStampList)

create prefix tree by path

addTransaction(transaction: List[int], tid: int) None[source]

add transaction into tree

Parameters:
  • transaction (list) – it represents the one transaction in database

  • tid (list or int) – represents the timestamp of transaction

Returns:

None

createPrefixTree(path: List[int], tidList: List[int]) None[source]

create prefix tree by path

Parameters:
  • path (list) – it represents path to root from prefix node

  • tidList (list) – it represents tid of each item

Returns:

None

deleteNode(item: int) None[source]

delete the node from tree

Parameters:

item (str) – it represents the item name of node

Returns:

None

fix node link

Parameters:
  • item (string) – it represents item name of newNode

  • newNode (Node) – it represents node which is added

Returns:

None