Align the length of the sequences to the specified sequence length. Parameters: X (ndarray): Input sequences. seq_len (int): Desired sequence length. Returns: ndarray: Aligned sequences with the specified length.
(X, seq_len)
| 4 | from concurrent.futures import ProcessPoolExecutor, as_completed |
| 5 | |
| 6 | def length_align(X, seq_len): |
| 7 | """ |
| 8 | Align the length of the sequences to the specified sequence length. |
| 9 | |
| 10 | Parameters: |
| 11 | X (ndarray): Input sequences. |
| 12 | seq_len (int): Desired sequence length. |
| 13 | |
| 14 | Returns: |
| 15 | ndarray: Aligned sequences with the specified length. |
| 16 | """ |
| 17 | if seq_len < X.shape[-1]: |
| 18 | X = X[...,:seq_len] # Truncate the sequence if seq_len is shorter than the sequence length |
| 19 | if seq_len > X.shape[-1]: |
| 20 | padding_num = seq_len - X.shape[-1] # Calculate padding length |
| 21 | pad_width = [(0, 0) for _ in range(len(X.shape) - 1)] + [(0, padding_num)] |
| 22 | X = np.pad(X, pad_width=pad_width, mode="constant", constant_values=0) # Pad the sequence with zeros |
| 23 | return X |
| 24 | |
| 25 | def load_data(data_path, feature_type, seq_len, num_tab=1): |
| 26 | """ |