baybe.utils.augmentation.df_apply_permutation_augmentation

baybe.utils.augmentation.df_apply_permutation_augmentation(df: DataFrame, permutation_groups: Sequence[Sequence[str]])[source]

Augment a dataframe if permutation invariant columns are present.

Each group in permutation_groups contains the names of columns that are permuted in lockstep. All groups must have the same length, and that length must be at least 2 (otherwise there is nothing to permute).

Parameters:
  • df (DataFrame) – The dataframe that should be augmented.

  • permutation_groups (Sequence[Sequence[str]]) – Groups of column names that are permuted in lockstep. For example, [["A1", "A2"], ["B1", "B2"]] means that the columns A1 and A2 are permuted, and B1 and B2 are permuted in the same way.

Return type:

DataFrame

Returns:

The augmented dataframe containing the original one. Augmented row indices are identical with the index of their original row.

Raises:
  • ValueError – If no permutation groups are given.

  • ValueError – If any permutation group has fewer than two entries.

  • ValueError – If the permutation groups have differing amounts of entries.

Examples

>>> df = pd.DataFrame({'A1':[1,2],'A2':[3,4], 'B1': [5, 6], 'B2': [7, 8]})
>>> df
   A1  A2  B1  B2
0   1   3   5   7
1   2   4   6   8
>>> groups = [['A1', 'A2']]
>>> dfa = df_apply_permutation_augmentation(df, groups)
>>> dfa
   A1  A2  B1  B2
0   1   3   5   7
0   3   1   5   7
1   2   4   6   8
1   4   2   6   8
>>> groups = [['A1', 'A2'], ['B1', 'B2']]
>>> dfa = df_apply_permutation_augmentation(df, groups)
>>> dfa
   A1  A2  B1  B2
0   1   3   5   7
0   3   1   7   5
1   2   4   6   8
1   4   2   8   6