MCPcopy Create free account
hub / github.com/FIND-Lab/Website-Fingerprinting-Library / length_align

Function length_align

WFlib/tools/data_processor.py:6–23  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

4from concurrent.futures import ProcessPoolExecutor, as_completed
5
6def 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
25def load_data(data_path, feature_type, seq_len, num_tab=1):
26 """

Callers 1

load_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected