GPU operations
Methods for performing image, classification, and data transformations on the GPU
Time-series statistics
- simba.data_processors.cuda.timeseries.sliding_hjort_parameters_gpu(data, window_sizes, sample_rate)[source]
Compute Hjorth parameters over sliding windows on the GPU.
See also
For CPU implementation, see :simba.mixins.timeseries_features_mixin.TimeseriesFeatureMixin.hjort_parameters
- Parameters
data (np.ndarray) – 1D numeric array of signal data.
window_sizes (np.ndarray) – 1D numeric array of window sizes (in seconds).
sample_rate (int) – Sampling rate of the data (samples per second).
- Returns
3D array of shape (3, len(data), len(window_sizes)) containing Hjorth parameters computed for each data point and window size.
- Return type
np.ndarray
- Example
>>> x = np.random.randint(0, 500, (10,)).astype(np.float32) >>> window_sizes = np.array([1.0, 0.5]).astype(np.float64) >>> sample_rate = 10 >>> H = sliding_hjort_parameters_gpu(data=x, window_sizes=window_sizes, sample_rate=sample_rate)
- simba.data_processors.cuda.timeseries.sliding_linearity_index_cuda(x, window_size, sample_rate)[source]
Calculates the straightness (linearity) index of a path using CUDA acceleration.
The output is a value between 0 and 1, where 1 indicates a perfectly straight path.
EXPECTED RUNTIMES
FRAMES (MILLIONS)
GPU TIME (S)
GPU TIME (STEV)
2
0.03031
0.002
4
0.05208
0.004
8
0.08882
0.0056
16
0.17612
0.0108
32
0.37699
0.01587
64
0.70194
0.01848
128
1.36778
0.06145
256
3.09965
0.21796
512
17.9707
10.5061
NVIDIA GeForce RTX 4070
time window = 2.5s @ 30 FPS
3 ITERATIONS
See also
simba.mixins.timeseries_features_mixin.TimeseriesFeatureMixin.sliding_linearity_index(),simba.mixins.timeseries_features_mixin.TimeseriesFeatureMixin.linearity_index()- Parameters
x (np.ndarray) – An (N, M) array representing the path, where N is the number of points and M is the number of spatial dimensions (e.g., 2 for 2D or 3 for 3D). Each row represents the coordinates of a point along the path.
window_size (float) – The size of the sliding window in seconds. This defines the time window over which the linearity index is calculated. The window size should be specified in seconds.
sample_rate (float) – The sample rate in Hz (samples per second), which is used to convert the window size from seconds to frames.
- Returns
A 1D array of length N, where each element represents the linearity index of the path within a sliding window. The value is a ratio between the straight-line distance and the actual path length for each window. Values range from 0 to 1, with 1 indicating a perfectly straight path.
- Return type
np.ndarray
- Example
>>> x = np.random.randint(0, 500, (100, 2)).astype(np.float32) >>> q = sliding_linearity_index_cuda(x=x, window_size=2, sample_rate=30)
- simba.data_processors.cuda.timeseries.sliding_percent_beyond_n_std(data, time_window, sample_rate, value)[source]
Computes the percentage of points in each sliding window of data that fall beyond n standard deviations from the mean of that window.
This function uses GPU acceleration via CUDA to efficiently compute the result over large datasets.
- Parameters
data (np.ndarray) – The input 1D data array for which the sliding window computation is to be performed.
time_window (float) – The length of the time window in seconds.
sample_rate (float) – The sample rate of the data in Hz (samples per second).
value (float) – The number of standard deviations beyond which to count data points.
- Returns
An array containing the count of data points beyond n standard deviations for each window.
- Return type
np.ndarray
- Example
>>> data = np.random.randint(0, 100, (100,)) >>> results = sliding_percent_beyond_n_std(data=data, time_window=1, sample_rate=10, value=2)
- simba.data_processors.cuda.timeseries.sliding_spatial_density_cuda(x, radius, pixels_per_mm, window_size, sample_rate)[source]
Computes the spatial density of points within a moving window along a trajectory using CUDA for acceleration.
This function calculates a spatial density measure for each point along a 2D trajectory path by counting the number of neighboring points within a specified radius. The computation is performed within a sliding window that moves along the trajectory, using GPU acceleration to handle large datasets efficiently.
EXPECTED RUNTIMES
FRAMES (MILLIONS)
GPU TIME (S)
GPU TIME (STEV)
2
0.5252
0.00063
4
1.0396
0.00099
8
2.0821
0.00231
16
4.2678
0.070249
32
8.4416
0.121225
64
16.941
0.097708
128
34.092
0.03986
256
68.052
0.27862
512
138.78118
3.755006
NVIDIA GeForce RTX 4070
time window = 2.5s @ 30 FPS
3 ITERATIONS
See also
simba.mixins.timeseries_features_mixin.TimeseriesFeatureMixin.spatial_density(),simba.mixins.timeseries_features_mixin.TimeseriesFeatureMixin.sliding_spatial_density()- Parameters
x (np.ndarray) – A 2D array of shape (N, 2), where N is the number of points and each point has two spatial coordinates (x, y). The array represents the trajectory path of points in a 2D space (e.g., x and y positions in space).
radius (float) – The radius (in millimeters) within which to count neighboring points around each trajectory point. Defines the area of interest around each point.
pixels_per_mm (float) – The scaling factor that converts the physical radius (in millimeters) to pixel units for spatial density calculations.
window_size (float) – The size of the sliding window (in seconds or points) to compute the density of points. A larger window size will consider more points in each density calculation.
sample_rate (float) – The rate at which to sample the trajectory points (e.g., frames per second or samples per unit time). It adjusts the granularity of the sliding window.
- Returns
A 1D numpy array where each element represents the computed spatial density for the trajectory at the corresponding point in time (or frame). Higher values indicate more densely packed points within the specified radius, while lower values suggest more sparsely distributed points.
- Return type
np.ndarray
- Example
>>> df = pd.read_csv("/mnt/c/troubleshooting/two_black_animals_14bp/project_folder/csv/outlier_corrected_movement_location/Test_3.csv") >>> x = df[['Nose_1_x', 'Nose_1_y']].values >>> results_cuda = sliding_spatial_density_cuda(x=x, radius=10.0, pixels_per_mm=4.0, window_size=1, sample_rate=20)
- simba.data_processors.cuda.timeseries.sliding_threshold(data, time_window, sample_rate, value, inverse=False)[source]
Compute the count of observations above or below threshold crossings over a sliding window using GPU acceleration.
- Parameters
- Returns
Array containing count of threshold crossings per window.
- Return type
np.ndarray