ComfyUI Node

Ptd Poisson

Ptd Poisson — a count distribution with the cdf/icdf that PyTorch forgot

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptd Poisson
    • PTDISTRIBUTION
    rate

    The Poisson distribution answers "how many times does something happen in a fixed window?" - website visits per hour, defects per batch, rain events per season. PtdPoisson is the pack's node for it: you give it a rate, it builds the distribution, and then you can sample counts or ask how likely a particular count is. If your workflow ever touches event-count data, this is the node you want.

    It comes from ComfyUI-Pt-Wrapper, HowToSD's no-code PyTorch toolkit. The Ptd* constructors pair with the Ptdm* query nodes, and Poisson is one of the more interesting of the lot because of what the pack had to do to make it work.

    How it works

    The node builds a torch.distributions.Poisson and wraps it in a subclass called PoissonEx. Here's the thing: PyTorch's Poisson is missing both cdf and icdf - trying to call them throws NotImplementedError. The pack patches that with scipy: cdf uses scipy.stats.poisson.cdf, icdf uses scipy.stats.poisson.ppf. That's the real reason scipy is in the pack's requirements.txt, and it's why PtdPoisson + PtdmCdf / PtdmIcdf work while plain torch would choke.

    Also worth knowing: Poisson is a discrete distribution. The query nodes handle this - PtdmPdf/PtdmLogProb/PtdmCdf detect the Poisson family and cast your value to an integer tensor before evaluating.

    Inputs that matter

    Just one real input:

    • rate - the average number of events per window (the λ parameter). Must be positive.

    It's a STRING field parsed with literal_eval, so type 3.5, or (1.0, 2.0, 5.0) for a batch of three distributions with different rates. The output is a single PTDISTRIBUTION socket.

    Installing it

    Same as the rest of the pack - ComfyUI Manager, search "Pt Wrapper", install, restart. Manual route:

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

    Then restart ComfyUI. The first install is the slow part: matplotlib, pandas, scipy, scikit-learn, transformers, datasets, and a pinned gensim==4.3.2. For this node specifically, scipy is the one that actually matters - if you see it fail on cdf/icdf, that's the dependency to check.

    Common issues

    Two classics. First, the text-input trap: an empty or mistyped rate field throws a SyntaxError. Second, don't feed Poisson a negative rate - the distribution is undefined there and you'll get a validation error. And a note for expectations: samples from a Poisson are non-negative integers, so when you run PtdmSample you'll see whole numbers like 2, 5, 0 - that's correct behavior, not a rounding artifact.

    CategoryDistribution

    Inputs (1)

    NameTypeDefaultDescription
    rateSTRING

    Outputs (1)

    NameTypeDescription
    PTDISTRIBUTIONPTDISTRIBUTION