/usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributions/__pycache__/geometric.cpython-36.pyc (4183B)
3
Eg @ sd d dl mZ d dlZd dlmZ d dlmZ d dlmZm Z m
Z
mZ d dlm
Z
G dd deZdS ) )NumberN)constraints)Distribution)
broadcast_allprobs_to_logitslogits_to_probs
lazy_property) binary_cross_entropy_with_logitsc s e Zd ZdZejejdZejZ d fdd Z
d fdd Zedd Z
ed
d Zedd
Zedd Zej fddZdd Zdd Z ZS ) Geometrica
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`.
)probslogitsNc s |d k|d kkrt d|d k r.t|\| _nt|\| _|d k rF|n|}t|tr^tj }n|j }t t
| j||d | jr|d k r| j}|dk}|j
s|j| }t dt|j dt|j dt| d| d S )Nz;Either `probs` or `logits` must be specified, but not both.)
validate_argsr zExpected parameter probs (z
of shape z) of distribution z* to be positive but found invalid values:
)
ValueErrorr r r
isinstancer torchSizesizesuperr
__init___validate_argsalldatatype__name__tupleshaperepr) selfr r r
Zprobs_or_logitsbatch_shapevalueZvalidZ
invalid_value) __class__ I/usr/local/lib64/python3.6/site-packages/torch/distributions/geometric.pyr ! s"
zGeometric.__init__c sf | j t|}tj|}d| jkr.| jj||_d| jkrF| jj||_tt|j |dd | j
|_
|S )Nr r F)r
)Z_get_checked_instancer
r r __dict__r expandr r r r )r r Z _instancenew)r r! r" r$ ; s
zGeometric.expandc C s d| j d S )Ng ?)r )r r! r! r" meanF s zGeometric.meanc C s d| j d | j S )Ng ?)r )r r! r! r" varianceJ s zGeometric.variancec C s t | jddS )NT) is_binary)r r )r r! r! r" r N s zGeometric.logitsc C s t | jddS )NT)r( )r r )r r! r! r" r R s zGeometric.probsc C s | j |}tj| jjj}tj ^ tjj rTtj || jj| jj
d}|j|d}n| jj|j
|d}|j | j j j S Q R X d S )N)dtypedevice)min )Z_extended_shaper Zfinfor r) tinyZno_grad_CZ_get_tracing_stateZrandr* clampr% Zuniform_loglog1pfloor)r Zsample_shaper r- ur! r! r" sampleV s
zGeometric.samplec C sZ | j r| j| t|| j\}}|jtjd}d||dk|dk@ <