InteractionType#
- class tensordict.nn.InteractionType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
StrEnumThe rule that a probabilistic module uses to get a value from a distribution.
RANDOM: a sample, fromrsample()if the distribution has it, else fromsample().MODE,MEDIAN,MEAN: the attribute of the same name. If the distribution has nomean,MEANaveragesn_empirical_estimatesamples (seeProbabilisticTensorDictModule).DETERMINISTIC: thedeterministic_sampleattribute. If the distribution does not have one, the mode for distributions with enumerable support (Categorical, Bernoulli,OneHotCategorical) and the mean for the others. For a distribution class that tensordict does not know, the module chooses the mean or the mode from the support of the distribution, and warns.
Set the type for a block of code with
set_interaction_type, or for one module with itsdefault_interaction_typeargument. Strings are accepted, in any case:InteractionType("RANDOM").Examples
>>> from tensordict.nn import InteractionType >>> InteractionType("RANDOM") <InteractionType.RANDOM: 'random'> >>> InteractionType.from_str("Mode") is InteractionType.MODE True
- classmethod from_str(type_str: str) InteractionType#
Returns the interaction type whose name matches a string, in any case.
- Parameters:
type_str (str) – the name, for example
"random"or"MODE".