ComfyUI Node

Ptdm Pdf

Ptdm Pdf — how likely is this exact value? The density node, demystified

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptdm Pdf
  • distribution
  • TENSOR
x

PtdmPdf answers "how likely is this exact value under my distribution?" It computes the probability density function at a point - the height of the bell curve, if you're picturing a normal. It's the first distribution node most people reach for, because plotting a PDF is the most intuitive way to see what a distribution actually looks like. You build a Ptd* distribution, plug it in with a value, and get the density back as a tensor.

It's part of ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch environment. The distribution subset of the pack is its little statistics lab, and the PDF/PMF nodes are the ones that make it visual: sample a bunch of points, run them through PtdmPdf, plot the results, and you've drawn the distribution's shape in the graph.

How it works

The node parses your x with literal_eval, casts to int64 if the distribution is discrete (Poisson/Binomial/Categorical family) or float32 otherwise, and then does something slightly clever: it calls distribution.log_prob(x) and exponentiates. That torch.exp(log_prob(...)) dance is the numerically stable way to get a probability - which is why the pack's log-prob node and this one are so tightly coupled. The author's own note is worth heeding: PDF is unsupported for some distributions in PyTorch.

Inputs that matter

  • distribution - a PTDISTRIBUTION from a Ptd* node.
  • x - the value to evaluate, as a text literal: 0.0, 10, or a tuple like (-1.0, 0.0, 1.0).

Output is a TENSOR of densities. Densities aren't probabilities - for continuous distributions they can exceed 1 at the peak. That surprises people every time; it's not an error.

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. Heavy first install (matplotlib, pandas, scipy, scikit-learn, transformers, datasets, pinned gensim), no model downloads.

Common issues

The text-input trap applies - x must be a number literal or you get the "You need to specify a float or an int." error. And the density-vs-probability confusion is the classic: for a continuous distribution, PDF values over 1 are normal and fine; the area under the curve is what integrates to 1, not the height. If your curve looks shifted or flat, check that you entered sensible loc/scale on the constructor side.

CategoryDistribution

Inputs (2)

NameTypeDefaultDescription
distributionPTDISTRIBUTION
xSTRING

Outputs (1)

NameTypeDescription
TENSORTENSOR