torch_ecg.utils¶
This module contains a collection of utility functions and classes that are used throughout the package.
Neural network auxiliary functions and classes¶
|
Extend the prediction arrays to prediction arrays in larger range of classes |
|
Compute the output shape of a (transpose) convolution/maxpool/avgpool layer. |
|
Compute the output shape of a convolution layer. |
|
Compute the output shape of a transpose convolution layer |
|
Compute the output shape of a maxpool layer. |
|
Compute the output shape of a avgpool layer. |
|
Compute the output shape of a sequential model. |
|
compute the size (number of parameters) of a |
|
Default collate functions for model training. |
|
Compute the receptive field of several types of |
|
Adjust the filter lengths in the config for convolutional neural networks, according to the new sampling frequency. |
Mixin class for size related methods |
|
Mixin class for loading from checkpoint class methods |
Signal processing functions¶
|
Smooth the 1d data using a window with requested size. |
|
Resample the 2d irregular timeseries sig into a 1d or 2d regular time series with frequency output_fs, elements of sig are in the form |
|
Detect peaks in data based on their amplitude and other features. |
|
Remove signal spikes using a naive method. |
|
Butterworth bandpass filtering the signals. |
|
Get amplitude of a signal (near critical points if given). |
|
Normalize a signal. |
|
Perform z-score normalization on |
|
Resample signal tensors to a new sampling frequency or a new signal length. |
Data operations¶
|
Get the mask around the given critical points. |
|
Transform class weight to sample weight. |
|
Ensure the multi-lead (ECG) signal to be of specified format. |
|
Ensure the (ECG) signal to be of specified length. |
|
Convert masks into lists of |
|
Convert a mask into a list of intervals, or a dict of lists of intervals. |
|
Generate a list of numbers uniformly distributed. |
|
Perform stratified train-test split on the dataframe. |
|
Convert a categorical array to a one-hot array. |
|
Generate weight mask for a binary target mask, accounting the foreground weight and boundary weight. |
Interval operations¶
|
Find the overlap between two intervals. |
|
Check whether interval is an Interval or a GeneralizedInterval. |
|
Check whether val is inside interval or not. |
|
Check whether val is inside generalized_interval or not. |
|
Find the union of intervals. |
|
Calculate the union of a list (or tuple) of |
|
Calculate the intersection of all intervals in interval_list. |
|
calculate the intersection of intervals. |
Calculate the complement of an interval in another interval. |
|
|
Compute an optimal covering of to_cover by intervals. |
|
Compute the length of an interval. |
|
Compute the length of an interval. |
|
Locate local extrema points in a 1D signal. |
|
Determines if two (generalized) intervals intersect or not. |
|
Find the largest (the largest interval length) covering of a sequence of intervals. |
Metrics computations¶
|
Compute top n accuracy. |
|
Compute a binary confusion matrix |
|
Compute binary one-vs-rest confusion matrices. |
|
Compute macro metrics, and metrics for each class. |
|
|
|
QRS accuracy score, proposed in CPSC2019. |
Decorators and Mixins¶
|
Decorator to add docstring to a function or a class. |
Remove parameters and/or returns from docstring, which is of the format of numpydoc. |
|
|
Default class representation. |
Mixin class for enhanced |
|
Mixin class for getting citations from DOIs. |
|
|
Get the kwargs of a function or class. |
|
Get the required positional arguments of a function or class. |
|
Add keyword arguments to a function. |
Path operations¶
|
Get the list of records in a recursive manner. |
String operations¶
|
Convert a (possibly) nested dict into a str of json-like formatted form. |
|
Converts a "boolean" value possibly in the format of |
|
Kill all leading white spaces in each line of text, while keeping all lines (including empty) |
|
Get the current time in the |
Visualization functions¶
|
Function to plot raw ECG signal. |
Miscellaneous¶
|
Initialize a logger. |
|
Sum a sequence of lists. |
|
Determine if two dicts are equal. |
|
Class for computing moving average. |
|
Context manager to time the execution of a block of code. |
|
A context manager that raises a |