in fclib/fclib/feature_engineering/feature_utils.py [0:0]
def gen_sequence_array(df_all, seq_len, seq_cols, grain1_name, grain2_name, start_timestep=0, end_timestep=None):
"""Combine feature sequences for all the combinations of (grain1_name, grain2_name) into a
3-dimensional array.
Args:
df_all (pd.Dataframe): Time series data of all the grains for multi-granular data
seq_len (int): Number of previous time series values to be used to form sequences
seq_cols (list[str]): A list of names of the feature columns
grain1_name (str): Name of the 1st column indicating the time series graunularity
grain2_name (str): Name of the 2nd column indicating the time series graunularity
start_timestep (int): First time step you can use to create feature sequences
end_timestep (int): Last time step you can use to create feature sequences
Returns:
seq_array (np.array): An array of feature sequences for all combinations of granularities
"""
seq_gen = (
list(
gen_sequence(
df_all[(df_all[grain1_name] == grain1) & (df_all[grain2_name] == grain2)],
seq_len,
seq_cols,
start_timestep,
end_timestep,
)
)
for grain1, grain2 in itertools.product(df_all[grain1_name].unique(), df_all[grain2_name].unique())
)
seq_array = np.concatenate(list(seq_gen)).astype(np.float32)
return seq_array