/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
distributions
/
/usr/local/lib64/python3.6/site-packages/torch/distributions
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
bernoulli.py
3904
0644
edit
dl
rm
beta.py
3406
0644
edit
dl
rm
binomial.py
5179
0644
edit
dl
rm
categorical.py
5488
0644
edit
dl
rm
cauchy.py
2714
0644
edit
dl
rm
chi2.py
909
0644
edit
dl
rm
constraints.py
17288
0644
edit
dl
rm
constraint_registry.py
10234
0644
edit
dl
rm
continuous_bernoulli.py
8532
0644
edit
dl
rm
dirichlet.py
3584
0644
edit
dl
rm
distribution.py
11735
0644
edit
dl
rm
exponential.py
2525
0644
edit
dl
rm
exp_family.py
2275
0644
edit
dl
rm
fishersnedecor.py
3152
0644
edit
dl
rm
gamma.py
3121
0644
edit
dl
rm
geometric.py
4266
0644
edit
dl
rm
gumbel.py
2528
0644
edit
dl
rm
half_cauchy.py
2257
0644
edit
dl
rm
half_normal.py
2058
0644
edit
dl
rm
independent.py
4361
0644
edit
dl
rm
kl.py
29998
0644
edit
dl
rm
kumaraswamy.py
2927
0644
edit
dl
rm
laplace.py
3054
0644
edit
dl
rm
lkj_cholesky.py
6124
0644
edit
dl
rm
logistic_normal.py
1983
0644
edit
dl
rm
log_normal.py
1772
0644
edit
dl
rm
lowrank_multivariate_normal.py
9930
0644
edit
dl
rm
mixture_same_family.py
8636
0644
edit
dl
rm
multinomial.py
4776
0644
edit
dl
rm
multivariate_normal.py
10548
0644
edit
dl
rm
negative_binomial.py
4091
0644
edit
dl
rm
normal.py
3351
0644
edit
dl
rm
one_hot_categorical.py
4375
0644
edit
dl
rm
pareto.py
2057
0644
edit
dl
rm
poisson.py
2066
0644
edit
dl
rm
relaxed_bernoulli.py
5360
0644
edit
dl
rm
relaxed_categorical.py
5202
0644
edit
dl
rm
studentT.py
3550
0644
edit
dl
rm
transformed_distribution.py
8270
0644
edit
dl
rm
transforms.py
38408
0644
edit
dl
rm
uniform.py
3112
0644
edit
dl
rm
utils.py
6196
0644
edit
dl
rm
von_mises.py
5091
0644
edit
dl
rm
weibull.py
2854
0644
edit
dl
rm
__init__.py
5884
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/distributions/geometric.py
(4266B)
from numbers import Number import torch from torch.distributions import constraints from torch.distributions.distribution import Distribution from torch.distributions.utils import broadcast_all, probs_to_logits, logits_to_probs, lazy_property from torch.nn.functional import binary_cross_entropy_with_logits class Geometric(Distribution): r""" Creates a Geometric distribution parameterized by :attr:`probs`, where :attr:`probs` is the probability of success of Bernoulli trials. It represents the probability that in :math:`k + 1` Bernoulli trials, the first :math:`k` trials failed, before seeing a success. Samples are non-negative integers [0, :math:`\inf`). Example:: >>> m = Geometric(torch.tensor([0.3])) >>> m.sample() # underlying Bernoulli has 30% chance 1; 70% chance 0 tensor([ 2.]) Args: probs (Number, Tensor): the probability of sampling `1`. Must be in range (0, 1] logits (Number, Tensor): the log-odds of sampling `1`. """ arg_constraints = {'probs': constraints.unit_interval, 'logits': constraints.real} support = constraints.nonnegative_integer def __init__(self, probs=None, logits=None, validate_args=None): if (probs is None) == (logits is None): raise ValueError("Either `probs` or `logits` must be specified, but not both.") if probs is not None: self.probs, = broadcast_all(probs) else: self.logits, = broadcast_all(logits) probs_or_logits = probs if probs is not None else logits if isinstance(probs_or_logits, Number): batch_shape = torch.Size() else: batch_shape = probs_or_logits.size() super(Geometric, self).__init__(batch_shape, validate_args=validate_args) if self._validate_args and probs is not None: # Add an extra check beyond unit_interval value = self.probs valid = value > 0 if not valid.all(): invalid_value = value.data[~valid] raise ValueError( "Expected parameter probs " f"({type(value).__name__} of shape {tuple(value.shape)}) " f"of distribution {repr(self)} " f"to be positive but found invalid values:\n{invalid_value}" ) def expand(self, batch_shape, _instance=None): new = self._get_checked_instance(Geometric, _instance) batch_shape = torch.Size(batch_shape) if 'probs' in self.__dict__: new.probs = self.probs.expand(batch_shape) if 'logits' in self.__dict__: new.logits = self.logits.expand(batch_shape) super(Geometric, new).__init__(batch_shape, validate_args=False) new._validate_args = self._validate_args return new @property def mean(self): return 1. / self.probs - 1. @property def variance(self): return (1. / self.probs - 1.) / self.probs @lazy_property def logits(self): return probs_to_logits(self.probs, is_binary=True) @lazy_property def probs(self): return logits_to_probs(self.logits, is_binary=True) def sample(self, sample_shape=torch.Size()): shape = self._extended_shape(sample_shape) tiny = torch.finfo(self.probs.dtype).tiny with torch.no_grad(): if torch._C._get_tracing_state(): # [JIT WORKAROUND] lack of support for .uniform_() u = torch.rand(shape, dtype=self.probs.dtype, device=self.probs.device) u = u.clamp(min=tiny) else: u = self.probs.new(shape).uniform_(tiny, 1) return (u.log() / (-self.probs).log1p()).floor() def log_prob(self, value): if self._validate_args: self._validate_sample(value) value, probs = broadcast_all(value, self.probs) probs = probs.clone(memory_format=torch.contiguous_format) probs[(probs == 1) & (value == 0)] = 0 return value * (-probs).log1p() + self.probs.log() def entropy(self): return binary_cross_entropy_with_logits(self.logits, self.probs, reduction='none') / self.probs
Save
cmd:
run