ComfyUI Node

Ptd Binomial

How many successes out of n tries

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptd Binomial
    • PTDISTRIBUTION
    total_count
    probs
    logits

    The Binomial distribution counts successes across a fixed number of independent trials: flip a coin 10 times, how many heads? Ptd Binomial builds that distribution as a PyTorch Distribution object - the natural successor to Ptd Bernoulli, which models just one trial. If your no-code workflow needs to model counts, batches of successes, or discrete events with a known probability, this is the node.

    How it works

    You supply total_count (n, the number of trials) plus either probs or logits for the per-trial success probability - exactly one of the two, never both. The node parses everything with ast.literal_eval, builds torch.distributions.Binomial, and hands back a PTDISTRIBUTION. total_count is cast to int64; the probabilities to float32.

    It's also subclassed to add scipy-backed cdf and icdf methods (stock PyTorch Binomial only ships the basics), which is one reason scipy is pinned in this pack's requirements. The output feeds the distribution-math family: Ptdm Sample to draw a count of successes, Ptdm LogProb / Ptdm Pmf to score a particular count, Ptdm Cdf for "at most this many" probabilities. For a toy example, set total_count to 10 and probs to 0.5, then sample - you'll get integers clustering around 5.

    The inputs that matter

    • total_count - the number of trials, n. A scalar or tuple of ints (10 or (10, 20)).
    • probs - per-trial success probability, scalar or tuple of floats.
    • logits - the log-odds alternative to probs.

    The exclusivity rule is enforced with a hard error, just like Bernoulli: pass both probs and logits and it throws "specify either probabilities or logits, but not both"; pass neither and it throws "you have to specify either". The empty-string defaults mean leaving a field blank is the trigger.

    Where people get burned

    • probs outside [0,1] won't be rejected up front; sampling will just return nonsense. Check your values.
    • total_count must be a valid literal - 10 parses, but 10 with a stray comma or an expression like 5*2 fails.
    • Forgetting that a sample from a Binomial is an integer - that's correct behavior, not a bug.

    Installing it

    It's in ComfyUI-Pt-Wrapper:

    • ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → Install → restart.
    • Or cd ComfyUI/custom_nodes && git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper and restart.

    The pack installs a heavy ML stack (transformers, datasets, peft, accelerate, scikit-learn, scipy, gensim, sentencepiece), so first boot is slow; scipy is load-bearing for these cdf/icdf extensions. No model downloads needed. It's a niche educational pack by HowToSD with little Reddit presence - check the repo's docs/reference/ and the issues tab when stuck.

    CategoryDistribution

    Inputs (3)

    NameTypeDefaultDescription
    total_countSTRING
    probsSTRING
    logitsSTRING

    Outputs (1)

    NameTypeDescription
    PTDISTRIBUTIONPTDISTRIBUTION