ComfyUI Node

Ptdm Pmf

Ptdm Pmf — the discrete answer to 'how likely is exactly k?'

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptdm Pmf
  • distribution
  • TENSOR
k0

PDF is for continuous distributions; PMF is for the discrete ones. PtdmPmf computes the probability mass function - the exact probability that a discrete distribution (Poisson, Binomial, Categorical) equals a specific count k. If your distribution models "number of events" or "category index," this is the node that tells you how likely each specific outcome is. It's the discrete world's PDF, with actual probabilities instead of densities.

It's part of ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch environment. It pairs with the discrete Ptd* constructors like PtdPoisson, and it's genuinely handy when you want to see the shape of a count distribution - plot probability against k values and you'll watch the Poisson skew as its rate grows.

How it works

The interesting bit is the type handling. The node takes k as an INT (the only query node in this family with a real number widget - no text parsing). It then checks the distribution family: for Poisson, Categorical, Multinomial, Binomial, or NegativeBinomial it casts to an int64 tensor; otherwise float32. Then it computes torch.exp(distribution.log_prob(k)) - the stable route again. The author's docstring calls it "Number of successes," which tells you what family it's built for.

Inputs that matter

  • distribution - a PTDISTRIBUTION from a Ptd* constructor. For this node you want a discrete one, practically speaking.
  • k - the outcome count, an integer widget (default 0).

Output is a TENSOR containing the probability of that exact outcome, in [0, 1]. Summing the PMF across all possible k gives 1.0 - a useful sanity check if you're computing several of them.

Installing it

ComfyUI Manager → Install Custom Nodes → search "Pt Wrapper" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart ComfyUI after. The pack's first install is heavy (matplotlib, pandas, scipy, scikit-learn, transformers, datasets, pinned gensim), but this node needs nothing beyond the pack itself.

Common issues

The main trap is feeding a continuous distribution into a PMF node. It won't crash - the code just falls to the float32 branch and computes whatever the distribution defines - but the result isn't a probability mass and can be misleading. Pair it with discrete constructors and you're doing it right. Also, k must be within the distribution's support: for a Poisson with rate 3, a k of 40 is astronomically unlikely but still valid; a negative k is not.

CategoryDistribution

Inputs (2)

NameTypeDefaultDescription
distributionPTDISTRIBUTION
kINT0-2147483648–2147483648

Outputs (1)

NameTypeDescription
TENSORTENSOR