cpdbench.dataset.CPDNdarrayDataset
1from numpy import ndarray 2 3from cpdbench.dataset.CPDDataset import CPDDataset 4 5 6class CPDNdarrayDataset(CPDDataset): 7 """Implementation of CPDDataset where the data source is a standard 2D numpy array 8 """ 9 10 def get_validation_preview(self) -> tuple[ndarray, list[int]]: 11 return self._validation_array, self._validation_ground_truths 12 13 def __init__(self, numpy_array: ndarray, ground_truths: list[int], validation_amount: int = -1): 14 """Constructor 15 :param numpy_array: the main dataset as 2D numpy array 16 :param ground_truths: the ground truth changepoints of the dataset as int list 17 :param validation_amount: the number of datapoints (in the 2nd dimension) to use for validation purposes. 18 """ 19 self._ndarray = numpy_array 20 self._ground_truths = ground_truths 21 if validation_amount == -1: 22 self._validation_array = self._ndarray[:, :] 23 else: 24 self._validation_array = self._ndarray[:, 0:validation_amount] 25 validation_array_length = self._validation_array.shape[1] 26 self._validation_ground_truths = [el for el in self._ground_truths if el < validation_array_length] 27 28 def init(self) -> None: 29 pass 30 31 def get_signal(self) -> tuple[ndarray, list[int]]: 32 return self._ndarray, self._ground_truths
7class CPDNdarrayDataset(CPDDataset): 8 """Implementation of CPDDataset where the data source is a standard 2D numpy array 9 """ 10 11 def get_validation_preview(self) -> tuple[ndarray, list[int]]: 12 return self._validation_array, self._validation_ground_truths 13 14 def __init__(self, numpy_array: ndarray, ground_truths: list[int], validation_amount: int = -1): 15 """Constructor 16 :param numpy_array: the main dataset as 2D numpy array 17 :param ground_truths: the ground truth changepoints of the dataset as int list 18 :param validation_amount: the number of datapoints (in the 2nd dimension) to use for validation purposes. 19 """ 20 self._ndarray = numpy_array 21 self._ground_truths = ground_truths 22 if validation_amount == -1: 23 self._validation_array = self._ndarray[:, :] 24 else: 25 self._validation_array = self._ndarray[:, 0:validation_amount] 26 validation_array_length = self._validation_array.shape[1] 27 self._validation_ground_truths = [el for el in self._ground_truths if el < validation_array_length] 28 29 def init(self) -> None: 30 pass 31 32 def get_signal(self) -> tuple[ndarray, list[int]]: 33 return self._ndarray, self._ground_truths
Implementation of CPDDataset where the data source is a standard 2D numpy array
CPDNdarrayDataset( numpy_array: numpy.ndarray, ground_truths: list, validation_amount: int = -1)
14 def __init__(self, numpy_array: ndarray, ground_truths: list[int], validation_amount: int = -1): 15 """Constructor 16 :param numpy_array: the main dataset as 2D numpy array 17 :param ground_truths: the ground truth changepoints of the dataset as int list 18 :param validation_amount: the number of datapoints (in the 2nd dimension) to use for validation purposes. 19 """ 20 self._ndarray = numpy_array 21 self._ground_truths = ground_truths 22 if validation_amount == -1: 23 self._validation_array = self._ndarray[:, :] 24 else: 25 self._validation_array = self._ndarray[:, 0:validation_amount] 26 validation_array_length = self._validation_array.shape[1] 27 self._validation_ground_truths = [el for el in self._ground_truths if el < validation_array_length]
Constructor
Parameters
- numpy_array: the main dataset as 2D numpy array
- ground_truths: the ground truth changepoints of the dataset as int list
- validation_amount: the number of datapoints (in the 2nd dimension) to use for validation purposes.
def
get_validation_preview(self) -> tuple[numpy.ndarray, list[int]]:
11 def get_validation_preview(self) -> tuple[ndarray, list[int]]: 12 return self._validation_array, self._validation_ground_truths
Return a smaller part of the complete signal for fast runtime validation.
Returns
A 2D ndarray containing the timeseries (time x feature)