-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fit function added with parameter input, removed whitespace with prec…
…ommit, rearranged class to private
- Loading branch information
Showing
6 changed files
with
64 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
"""Implements dynamic programming class for optimal segementation algorithm.""" | ||
import _DynP | ||
import numpy as np | ||
|
||
class DynP: | ||
"""Dynamic Programming class for calculating optimal segmentation | ||
|
||
Attributes: | ||
data (np.ndarray): Matrix storing the dataset. | ||
num_bkps (int): Number of breakpoints to detect. | ||
jump (int): Interval for checking potential breakpoints. | ||
min_size (int): Minimum size of a segment. | ||
class DynP: | ||
"""Detects the change points in a time series. | ||
Attributes | ||
---------- | ||
data: np.ndarray | ||
Matrix storing the time series data. | ||
num_bkps: int | ||
Number of change points to detect. | ||
jump: int | ||
Interval for checking potential change points. Changing will | ||
not provide optimal detection, but will reduce runtime. | ||
min_size: int | ||
Minimum size of a segment. Changing will not provide optimal | ||
detection, but will reduce runtime. | ||
""" | ||
|
||
def __init__(self, data: np.ndarray, num_bkps: int, jump: int, min_size: int): | ||
"""Initializes the DynamicProgramming instance with given parameters.""" | ||
def __init__( | ||
self, data: np.ndarray, num_bkps: int, jump: int, min_size: int | ||
): | ||
"""Initialize the DynamicProgramming instance with given parameters.""" | ||
self.dynp = _DynP.DynamicProgramming(data, num_bkps, jump, min_size) | ||
|
||
def set_num_threads(self, num_threads: int): | ||
"""Sets the number of threads for parallelization. | ||
"""Set the number of threads for parallelization. | ||
Args: | ||
num_threads (int): The number of threads to use. | ||
Parameters | ||
---------- | ||
num_threads: int | ||
The number of threads to use during computation. Default | ||
is determined automatically. | ||
""" | ||
self.dynp.set_threads(num_threads) | ||
|
||
def return_breakpoints(self) -> list: | ||
"""Returns the optimal set of breakpoints after segmentation. | ||
Returns: | ||
list: A list of integers representing the breakpoints. | ||
""" | ||
return self.dynp.return_breakpoints() | ||
|
||
def initialize_cost_matrix(self): | ||
"""Initializes and fills the upper triangular cost matrix for all data segments.""" | ||
self.dynp.initialize_cost_matrix() | ||
def fit(self, num_bkps: int) -> list: | ||
"""Calculate the cost matrix and return the breakpoints. | ||
def fit(self) -> list: | ||
"""Calculates the cost matrix and returns the breakpoints. | ||
Parameters | ||
---------- | ||
num_bkps: int | ||
number of change points to detect. | ||
Returns: | ||
Returns | ||
------- | ||
list: A list of integers representing the breakpoints. | ||
""" | ||
return self.dynp.fit() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters