doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
support = Real()
torch.distributions#torch.distributions.cauchy.Cauchy.support
property variance
torch.distributions#torch.distributions.cauchy.Cauchy.variance
class torch.distributions.chi2.Chi2(df, validate_args=None) [source] Bases: torch.distributions.gamma.Gamma Creates a Chi2 distribution parameterized by shape parameter df. This is exactly equivalent to Gamma(alpha=0.5*df, beta=0.5) Example: >>> m = Chi2(torch.tensor([1.0])) >>> m.sample() # Chi2 distributed with shape df=1 tensor([ 0.1046]) Parameters df (float or Tensor) – shape parameter of the distribution arg_constraints = {'df': GreaterThan(lower_bound=0.0)} property df expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.chi2.Chi2
arg_constraints = {'df': GreaterThan(lower_bound=0.0)}
torch.distributions#torch.distributions.chi2.Chi2.arg_constraints
property df
torch.distributions#torch.distributions.chi2.Chi2.df
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.chi2.Chi2.expand
torch.distributions.constraints.cat alias of torch.distributions.constraints._Cat
torch.distributions#torch.distributions.constraints.cat
class torch.distributions.constraints.Constraint [source] Abstract base class for constraints. A constraint object represents a region over which a variable is valid, e.g. within which a variable can be optimized. Variables ~Constraint.is_discrete (bool) – Whether constrained space is discrete. Defaults to False. ~Constraint.event_dim (int) – Number of rightmost dimensions that together define an event. The check() method will remove this many dimensions when computing validity. check(value) [source] Returns a byte tensor of sample_shape + batch_shape indicating whether each event in value satisfies this constraint.
torch.distributions#torch.distributions.constraints.Constraint
check(value) [source] Returns a byte tensor of sample_shape + batch_shape indicating whether each event in value satisfies this constraint.
torch.distributions#torch.distributions.constraints.Constraint.check
torch.distributions.constraints.dependent_property alias of torch.distributions.constraints._DependentProperty
torch.distributions#torch.distributions.constraints.dependent_property
torch.distributions.constraints.greater_than alias of torch.distributions.constraints._GreaterThan
torch.distributions#torch.distributions.constraints.greater_than
torch.distributions.constraints.greater_than_eq alias of torch.distributions.constraints._GreaterThanEq
torch.distributions#torch.distributions.constraints.greater_than_eq
torch.distributions.constraints.half_open_interval alias of torch.distributions.constraints._HalfOpenInterval
torch.distributions#torch.distributions.constraints.half_open_interval
torch.distributions.constraints.independent alias of torch.distributions.constraints._IndependentConstraint
torch.distributions#torch.distributions.constraints.independent
torch.distributions.constraints.integer_interval alias of torch.distributions.constraints._IntegerInterval
torch.distributions#torch.distributions.constraints.integer_interval
torch.distributions.constraints.interval alias of torch.distributions.constraints._Interval
torch.distributions#torch.distributions.constraints.interval
torch.distributions.constraints.less_than alias of torch.distributions.constraints._LessThan
torch.distributions#torch.distributions.constraints.less_than
torch.distributions.constraints.multinomial alias of torch.distributions.constraints._Multinomial
torch.distributions#torch.distributions.constraints.multinomial
torch.distributions.constraints.stack alias of torch.distributions.constraints._Stack
torch.distributions#torch.distributions.constraints.stack
class torch.distributions.constraint_registry.ConstraintRegistry [source] Registry to link constraints to transforms. register(constraint, factory=None) [source] Registers a Constraint subclass in this registry. Usage: @my_registry.register(MyConstraintClass) def construct_transform(constraint): assert isinstance(constraint, MyConstraint) return MyTransform(constraint.arg_constraints) Parameters constraint (subclass of Constraint) – A subclass of Constraint, or a singleton object of the desired class. factory (callable) – A callable that inputs a constraint object and returns a Transform object.
torch.distributions#torch.distributions.constraint_registry.ConstraintRegistry
register(constraint, factory=None) [source] Registers a Constraint subclass in this registry. Usage: @my_registry.register(MyConstraintClass) def construct_transform(constraint): assert isinstance(constraint, MyConstraint) return MyTransform(constraint.arg_constraints) Parameters constraint (subclass of Constraint) – A subclass of Constraint, or a singleton object of the desired class. factory (callable) – A callable that inputs a constraint object and returns a Transform object.
torch.distributions#torch.distributions.constraint_registry.ConstraintRegistry.register
class torch.distributions.continuous_bernoulli.ContinuousBernoulli(probs=None, logits=None, lims=(0.499, 0.501), validate_args=None) [source] Bases: torch.distributions.exp_family.ExponentialFamily Creates a continuous Bernoulli distribution parameterized by probs or logits (but not both). The distribution is supported in [0, 1] and parameterized by ‘probs’ (in (0,1)) or ‘logits’ (real-valued). Note that, unlike the Bernoulli, ‘probs’ does not correspond to a probability and ‘logits’ does not correspond to log-odds, but the same names are used due to the similarity with the Bernoulli. See [1] for more details. Example: >>> m = ContinuousBernoulli(torch.tensor([0.3])) >>> m.sample() tensor([ 0.2538]) Parameters probs (Number, Tensor) – (0,1) valued parameters logits (Number, Tensor) – real valued parameters whose sigmoid matches ‘probs’ [1] The continuous Bernoulli: fixing a pervasive error in variational autoencoders, Loaiza-Ganem G and Cunningham JP, NeurIPS 2019. https://arxiv.org/abs/1907.06845 arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0, upper_bound=1.0)} cdf(value) [source] entropy() [source] expand(batch_shape, _instance=None) [source] has_rsample = True icdf(value) [source] log_prob(value) [source] logits [source] property mean property param_shape probs [source] rsample(sample_shape=torch.Size([])) [source] sample(sample_shape=torch.Size([])) [source] property stddev support = Interval(lower_bound=0.0, upper_bound=1.0) property variance
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli
arg_constraints = {'logits': Real(), 'probs': Interval(lower_bound=0.0, upper_bound=1.0)}
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.arg_constraints
cdf(value) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.cdf
entropy() [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.entropy
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.expand
has_rsample = True
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.has_rsample
icdf(value) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.icdf
logits [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.logits
log_prob(value) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.log_prob
property mean
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.mean
property param_shape
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.param_shape
probs [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.probs
rsample(sample_shape=torch.Size([])) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.rsample
sample(sample_shape=torch.Size([])) [source]
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.sample
property stddev
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.stddev
support = Interval(lower_bound=0.0, upper_bound=1.0)
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.support
property variance
torch.distributions#torch.distributions.continuous_bernoulli.ContinuousBernoulli.variance
class torch.distributions.dirichlet.Dirichlet(concentration, validate_args=None) [source] Bases: torch.distributions.exp_family.ExponentialFamily Creates a Dirichlet distribution parameterized by concentration concentration. Example: >>> m = Dirichlet(torch.tensor([0.5, 0.5])) >>> m.sample() # Dirichlet distributed with concentrarion concentration tensor([ 0.1046, 0.8954]) Parameters concentration (Tensor) – concentration parameter of the distribution (often referred to as alpha) arg_constraints = {'concentration': IndependentConstraint(GreaterThan(lower_bound=0.0), 1)} entropy() [source] expand(batch_shape, _instance=None) [source] has_rsample = True log_prob(value) [source] property mean rsample(sample_shape=()) [source] support = Simplex() property variance
torch.distributions#torch.distributions.dirichlet.Dirichlet
arg_constraints = {'concentration': IndependentConstraint(GreaterThan(lower_bound=0.0), 1)}
torch.distributions#torch.distributions.dirichlet.Dirichlet.arg_constraints
entropy() [source]
torch.distributions#torch.distributions.dirichlet.Dirichlet.entropy
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.dirichlet.Dirichlet.expand
has_rsample = True
torch.distributions#torch.distributions.dirichlet.Dirichlet.has_rsample
log_prob(value) [source]
torch.distributions#torch.distributions.dirichlet.Dirichlet.log_prob
property mean
torch.distributions#torch.distributions.dirichlet.Dirichlet.mean
rsample(sample_shape=()) [source]
torch.distributions#torch.distributions.dirichlet.Dirichlet.rsample
support = Simplex()
torch.distributions#torch.distributions.dirichlet.Dirichlet.support
property variance
torch.distributions#torch.distributions.dirichlet.Dirichlet.variance
class torch.distributions.distribution.Distribution(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None) [source] Bases: object Distribution is the abstract base class for probability distributions. property arg_constraints Returns a dictionary from argument names to Constraint objects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict. property batch_shape Returns the shape over which parameters are batched. cdf(value) [source] Returns the cumulative density/mass function evaluated at value. Parameters value (Tensor) – entropy() [source] Returns entropy of distribution, batched over batch_shape. Returns Tensor of shape batch_shape. enumerate_support(expand=True) [source] Returns tensor containing all values supported by a discrete distribution. The result will enumerate over dimension 0, so the shape of the result will be (cardinality,) + batch_shape + event_shape (where event_shape = () for univariate distributions). Note that this enumerates over all batched tensors in lock-step [[0, 0], [1, 1], …]. With expand=False, enumeration happens along dim 0, but with the remaining batch dimensions being singleton dimensions, [[0], [1], ... To iterate over the full Cartesian product use itertools.product(m.enumerate_support()). Parameters expand (bool) – whether to expand the support over the batch dims to match the distribution’s batch_shape. Returns Tensor iterating over dimension 0. property event_shape Returns the shape of a single sample (without batching). expand(batch_shape, _instance=None) [source] Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to batch_shape. This method calls expand on the distribution’s parameters. As such, this does not allocate new memory for the expanded distribution instance. Additionally, this does not repeat any args checking or parameter broadcasting in __init__.py, when an instance is first created. Parameters batch_shape (torch.Size) – the desired expanded size. _instance – new instance provided by subclasses that need to override .expand. Returns New distribution instance with batch dimensions expanded to batch_size. icdf(value) [source] Returns the inverse cumulative density/mass function evaluated at value. Parameters value (Tensor) – log_prob(value) [source] Returns the log of the probability density/mass function evaluated at value. Parameters value (Tensor) – property mean Returns the mean of the distribution. perplexity() [source] Returns perplexity of distribution, batched over batch_shape. Returns Tensor of shape batch_shape. rsample(sample_shape=torch.Size([])) [source] Generates a sample_shape shaped reparameterized sample or sample_shape shaped batch of reparameterized samples if the distribution parameters are batched. sample(sample_shape=torch.Size([])) [source] Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched. sample_n(n) [source] Generates n samples or n batches of samples if the distribution parameters are batched. static set_default_validate_args(value) [source] Sets whether validation is enabled or disabled. The default behavior mimics Python’s assert statement: validation is on by default, but is disabled if Python is run in optimized mode (via python -O). Validation may be expensive, so you may want to disable it once a model is working. Parameters value (bool) – Whether to enable validation. property stddev Returns the standard deviation of the distribution. property support Returns a Constraint object representing this distribution’s support. property variance Returns the variance of the distribution.
torch.distributions#torch.distributions.distribution.Distribution
property arg_constraints Returns a dictionary from argument names to Constraint objects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
torch.distributions#torch.distributions.distribution.Distribution.arg_constraints
property batch_shape Returns the shape over which parameters are batched.
torch.distributions#torch.distributions.distribution.Distribution.batch_shape
cdf(value) [source] Returns the cumulative density/mass function evaluated at value. Parameters value (Tensor) –
torch.distributions#torch.distributions.distribution.Distribution.cdf
entropy() [source] Returns entropy of distribution, batched over batch_shape. Returns Tensor of shape batch_shape.
torch.distributions#torch.distributions.distribution.Distribution.entropy
enumerate_support(expand=True) [source] Returns tensor containing all values supported by a discrete distribution. The result will enumerate over dimension 0, so the shape of the result will be (cardinality,) + batch_shape + event_shape (where event_shape = () for univariate distributions). Note that this enumerates over all batched tensors in lock-step [[0, 0], [1, 1], …]. With expand=False, enumeration happens along dim 0, but with the remaining batch dimensions being singleton dimensions, [[0], [1], ... To iterate over the full Cartesian product use itertools.product(m.enumerate_support()). Parameters expand (bool) – whether to expand the support over the batch dims to match the distribution’s batch_shape. Returns Tensor iterating over dimension 0.
torch.distributions#torch.distributions.distribution.Distribution.enumerate_support
property event_shape Returns the shape of a single sample (without batching).
torch.distributions#torch.distributions.distribution.Distribution.event_shape
expand(batch_shape, _instance=None) [source] Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to batch_shape. This method calls expand on the distribution’s parameters. As such, this does not allocate new memory for the expanded distribution instance. Additionally, this does not repeat any args checking or parameter broadcasting in __init__.py, when an instance is first created. Parameters batch_shape (torch.Size) – the desired expanded size. _instance – new instance provided by subclasses that need to override .expand. Returns New distribution instance with batch dimensions expanded to batch_size.
torch.distributions#torch.distributions.distribution.Distribution.expand
icdf(value) [source] Returns the inverse cumulative density/mass function evaluated at value. Parameters value (Tensor) –
torch.distributions#torch.distributions.distribution.Distribution.icdf
log_prob(value) [source] Returns the log of the probability density/mass function evaluated at value. Parameters value (Tensor) –
torch.distributions#torch.distributions.distribution.Distribution.log_prob
property mean Returns the mean of the distribution.
torch.distributions#torch.distributions.distribution.Distribution.mean
perplexity() [source] Returns perplexity of distribution, batched over batch_shape. Returns Tensor of shape batch_shape.
torch.distributions#torch.distributions.distribution.Distribution.perplexity
rsample(sample_shape=torch.Size([])) [source] Generates a sample_shape shaped reparameterized sample or sample_shape shaped batch of reparameterized samples if the distribution parameters are batched.
torch.distributions#torch.distributions.distribution.Distribution.rsample
sample(sample_shape=torch.Size([])) [source] Generates a sample_shape shaped sample or sample_shape shaped batch of samples if the distribution parameters are batched.
torch.distributions#torch.distributions.distribution.Distribution.sample
sample_n(n) [source] Generates n samples or n batches of samples if the distribution parameters are batched.
torch.distributions#torch.distributions.distribution.Distribution.sample_n
static set_default_validate_args(value) [source] Sets whether validation is enabled or disabled. The default behavior mimics Python’s assert statement: validation is on by default, but is disabled if Python is run in optimized mode (via python -O). Validation may be expensive, so you may want to disable it once a model is working. Parameters value (bool) – Whether to enable validation.
torch.distributions#torch.distributions.distribution.Distribution.set_default_validate_args
property stddev Returns the standard deviation of the distribution.
torch.distributions#torch.distributions.distribution.Distribution.stddev
property support Returns a Constraint object representing this distribution’s support.
torch.distributions#torch.distributions.distribution.Distribution.support
property variance Returns the variance of the distribution.
torch.distributions#torch.distributions.distribution.Distribution.variance
class torch.distributions.exponential.Exponential(rate, validate_args=None) [source] Bases: torch.distributions.exp_family.ExponentialFamily Creates a Exponential distribution parameterized by rate. Example: >>> m = Exponential(torch.tensor([1.0])) >>> m.sample() # Exponential distributed with rate=1 tensor([ 0.1046]) Parameters rate (float or Tensor) – rate = 1 / scale of the distribution arg_constraints = {'rate': GreaterThan(lower_bound=0.0)} cdf(value) [source] entropy() [source] expand(batch_shape, _instance=None) [source] has_rsample = True icdf(value) [source] log_prob(value) [source] property mean rsample(sample_shape=torch.Size([])) [source] property stddev support = GreaterThan(lower_bound=0.0) property variance
torch.distributions#torch.distributions.exponential.Exponential
arg_constraints = {'rate': GreaterThan(lower_bound=0.0)}
torch.distributions#torch.distributions.exponential.Exponential.arg_constraints
cdf(value) [source]
torch.distributions#torch.distributions.exponential.Exponential.cdf
entropy() [source]
torch.distributions#torch.distributions.exponential.Exponential.entropy
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.exponential.Exponential.expand
has_rsample = True
torch.distributions#torch.distributions.exponential.Exponential.has_rsample
icdf(value) [source]
torch.distributions#torch.distributions.exponential.Exponential.icdf
log_prob(value) [source]
torch.distributions#torch.distributions.exponential.Exponential.log_prob
property mean
torch.distributions#torch.distributions.exponential.Exponential.mean
rsample(sample_shape=torch.Size([])) [source]
torch.distributions#torch.distributions.exponential.Exponential.rsample
property stddev
torch.distributions#torch.distributions.exponential.Exponential.stddev
support = GreaterThan(lower_bound=0.0)
torch.distributions#torch.distributions.exponential.Exponential.support
property variance
torch.distributions#torch.distributions.exponential.Exponential.variance
class torch.distributions.exp_family.ExponentialFamily(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None) [source] Bases: torch.distributions.distribution.Distribution ExponentialFamily is the abstract base class for probability distributions belonging to an exponential family, whose probability mass/density function has the form is defined below pF(x;θ)=exp⁡(⟨t(x),θ⟩−F(θ)+k(x))p_{F}(x; \theta) = \exp(\langle t(x), \theta\rangle - F(\theta) + k(x)) where θ\theta denotes the natural parameters, t(x)t(x) denotes the sufficient statistic, F(θ)F(\theta) is the log normalizer function for a given family and k(x)k(x) is the carrier measure. Note This class is an intermediary between the Distribution class and distributions which belong to an exponential family mainly to check the correctness of the .entropy() and analytic KL divergence methods. We use this class to compute the entropy and KL divergence using the AD framework and Bregman divergences (courtesy of: Frank Nielsen and Richard Nock, Entropies and Cross-entropies of Exponential Families). entropy() [source] Method to compute the entropy using Bregman divergence of the log normalizer.
torch.distributions#torch.distributions.exp_family.ExponentialFamily
entropy() [source] Method to compute the entropy using Bregman divergence of the log normalizer.
torch.distributions#torch.distributions.exp_family.ExponentialFamily.entropy
class torch.distributions.fishersnedecor.FisherSnedecor(df1, df2, validate_args=None) [source] Bases: torch.distributions.distribution.Distribution Creates a Fisher-Snedecor distribution parameterized by df1 and df2. Example: >>> m = FisherSnedecor(torch.tensor([1.0]), torch.tensor([2.0])) >>> m.sample() # Fisher-Snedecor-distributed with df1=1 and df2=2 tensor([ 0.2453]) Parameters df1 (float or Tensor) – degrees of freedom parameter 1 df2 (float or Tensor) – degrees of freedom parameter 2 arg_constraints = {'df1': GreaterThan(lower_bound=0.0), 'df2': GreaterThan(lower_bound=0.0)} expand(batch_shape, _instance=None) [source] has_rsample = True log_prob(value) [source] property mean rsample(sample_shape=torch.Size([])) [source] support = GreaterThan(lower_bound=0.0) property variance
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor
arg_constraints = {'df1': GreaterThan(lower_bound=0.0), 'df2': GreaterThan(lower_bound=0.0)}
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.arg_constraints
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.expand
has_rsample = True
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.has_rsample
log_prob(value) [source]
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.log_prob
property mean
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.mean
rsample(sample_shape=torch.Size([])) [source]
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.rsample
support = GreaterThan(lower_bound=0.0)
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.support
property variance
torch.distributions#torch.distributions.fishersnedecor.FisherSnedecor.variance
class torch.distributions.gamma.Gamma(concentration, rate, validate_args=None) [source] Bases: torch.distributions.exp_family.ExponentialFamily Creates a Gamma distribution parameterized by shape concentration and rate. Example: >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0])) >>> m.sample() # Gamma distributed with concentration=1 and rate=1 tensor([ 0.1046]) Parameters concentration (float or Tensor) – shape parameter of the distribution (often referred to as alpha) rate (float or Tensor) – rate = 1 / scale of the distribution (often referred to as beta) arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rate': GreaterThan(lower_bound=0.0)} entropy() [source] expand(batch_shape, _instance=None) [source] has_rsample = True log_prob(value) [source] property mean rsample(sample_shape=torch.Size([])) [source] support = GreaterThan(lower_bound=0.0) property variance
torch.distributions#torch.distributions.gamma.Gamma
arg_constraints = {'concentration': GreaterThan(lower_bound=0.0), 'rate': GreaterThan(lower_bound=0.0)}
torch.distributions#torch.distributions.gamma.Gamma.arg_constraints
entropy() [source]
torch.distributions#torch.distributions.gamma.Gamma.entropy
expand(batch_shape, _instance=None) [source]
torch.distributions#torch.distributions.gamma.Gamma.expand
has_rsample = True
torch.distributions#torch.distributions.gamma.Gamma.has_rsample
log_prob(value) [source]
torch.distributions#torch.distributions.gamma.Gamma.log_prob
property mean
torch.distributions#torch.distributions.gamma.Gamma.mean
rsample(sample_shape=torch.Size([])) [source]
torch.distributions#torch.distributions.gamma.Gamma.rsample
support = GreaterThan(lower_bound=0.0)
torch.distributions#torch.distributions.gamma.Gamma.support