VVarisel Desk
Workflows

Coding workflows · Welford sample variance

03
Built around your work

A concrete starting point

Compute sample variance for 2 through 10000 values bounded by 1e150 in magnitude using Welford updates. Check constant samples and large offsets, rejecting Booleans, non-finite values and invalid counts.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Welford sample variance

A concrete starting point
from math import isfinite
def sample_variance(values):
    if type(values) not in (list, tuple) or not 2 <= len(values) <= 10000:
        raise ValueError("sample count")
    if any(type(x) not in (int, float) or not -1e150 <= x <= 1e150
           or not isfinite(x) for x in values):
        raise ValueError("bounded finite samples")
    mean, m2 = 0.0, 0.0
    for n, x in enumerate(values, 1):
        delta = x - mean
        mean += delta / n
        m2 += delta * (x - mean)
    return m2 / (len(values) - 1)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗