tfep.nn.conditioners.made.generate_degrees

tfep.nn.conditioners.made.generate_degrees(n_features: int, order: Literal['ascending', 'descending', 'random'] = 'ascending', max_value: int | None = None, conditioning_indices: Sequence[int] | None = None, repeats: int | Sequence[int] = 1) Tensor[source]

Generate node degrees for MADE layers.

This generates a tensor representing degrees from 0 to max_value. Conditioning degrees are set to -1.

Parameters:
  • n_features (int) – The length of the generated 1D tensor.

  • order (Literal[‘ascending’, ‘descending’, ‘random’], optional) – In what order to generate the degrees. Default is 'ascending'.

  • max_value (int, optional) – The maximum value to assign to the degree tensor. By default, this is determined automatically to be consistent to the value of the other parameters.

  • conditioning_indices (None or Sequence[int], optional) – The indices of the output tensor whose degree must be set to -1. Default is None.

  • repeats (Union[int, Sequence[int]], optional) – How many time to repeat a degree. This is similar to the repeats argument in torch.repeat_interleave(). If this is a Sequence[int] and max_value is passed, this must have length max_value+1.

Returns:

degrees – Shape (n_features,). The degrees.

Return type:

torch.Tensor

Examples

>>> generate_degrees(n_features=3).tolist()
[0, 1, 2]
>>> generate_degrees(7, order='descending').tolist()
[6, 5, 4, 3, 2, 1, 0]

If max_value is smaller than the requested number of elements, the array of degrees is obtained by tiling

>>> generate_degrees(7, order='descending', max_value=2).tolist()
[2, 1, 0, 2, 1, 0, 2]

conditioning_indices can be used to set some elements as “conditioning” (see the documentation of MADE for details).

>>> generate_degrees(7, max_value=2, conditioning_indices=[0, 2, 3]).tolist()
[-1, 0, -1, -1, 1, 2, 0]

repeats can be used to assign contiguous elements to the same degree

>>> generate_degrees(6, repeats=2).tolist()
[0, 0, 1, 1, 2, 2]
>>> generate_degrees(7, repeats=[1, 3, 2], conditioning_indices=[2]).tolist()
[0, 1, -1, 1, 1, 2, 2]