ComfyUI Node

Ptd Chi2

The chi-squared distribution, for stats and variance modeling

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptd Chi2
    • PTDISTRIBUTION
    df

    The chi-squared distribution shows up everywhere in statistics - goodness-of-fit tests, variance estimation, confidence intervals - and it also happens to be the distribution of a sum of squared standard normals. Ptd Chi2 builds it as a PyTorch Distribution object with a single parameter: degrees of freedom. If your no-code workflow does any hypothesis-test-adjacent math or you just need a right-skewed, positive-only distribution to sample from, this is the node.

    How it works

    You give it df (degrees of freedom), it parses the string with ast.literal_eval, and constructs torch.distributions.Chi2. One parameter, one distribution. The shape intuition: with low df the distribution is heavily skewed toward zero; as df grows it becomes more bell-shaped and slides right. Sample from it and you get positive floats only - for df=1 the values can get startlingly large on the tail, which is correct behavior for a heavy-tailed distribution.

    This one is also subclassed to add an icdf method via scipy (stock PyTorch Chi2 doesn't ship the inverse CDF), so quantile questions - "what value cuts off the top 5%?" - are answerable in-graph with Ptdm Icdf. The PTDISTRIBUTION output works with the usual family: Ptdm Sample to draw values, Ptdm LogProb / Pdf to score them, Ptdm Cdf for cumulative probabilities.

    The one input that matters

    • df - degrees of freedom. A scalar like 3, or a tuple like (3, 5) for a batched distribution.

    It's required, defaults to "", and an empty string fails at ast.literal_eval - so the number-one beginner error is hitting Run without typing anything. Type a number and it just works.

    Where people get burned

    • df ≤ 0 is undefined for chi-squared; keep it a positive number. (Zero is technically degenerate and won't behave.)
    • Literal syntax: 3 and (3, 5) parse fine; 3, 5 without parentheses fails.
    • Expecting symmetric output - chi-squared is right-skewed by design; that skew is not a bug.

    Installing it

    Part of 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); scipy backs the icdf extension this node relies on. No model downloads needed. It's a niche educational pack by HowToSD with almost no community chatter - when stuck, the repo's docs/reference/ and the issues tab are your options.

    CategoryDistribution

    Inputs (1)

    NameTypeDefaultDescription
    dfSTRING

    Outputs (1)

    NameTypeDescription
    PTDISTRIBUTIONPTDISTRIBUTION