How to test statistical properties of the range of a function?

Hi again ^^

I’ve started a (perlin-family-of) noises project with a friend. There, I have a function that takes an N-D f32 vector and outputs a pseudorandom, unitary, N-D f32 vector. The ideas behind that function are that:

  1. Its output is always unitary
  2. Its output is deterministic (i.e. f(x) = f(x’) if x = x’, regardless of the state of the program)
  3. Its output’s expected value is the zero vector (0n). This means that the distribution of outputs is balanced and doesn’t favor any direction in particular.

I can test (1) and (2) using things like quickcheck and proptest. However, I have no clue as to how I would test (3). This is the model I have in mind:

  • For each dimension n=1…20 or so:
    • Take a large (>10000) m.
    • Generate m random n-D f32 vectors.
    • Obtain f(x) for each one of those.
    • Sum the results and divide by m.
    • Result should be “close” to 0n. under a highly likely Delta determined by m (I remember reading when I took statistics that there is a formula for this).
      How “close” it is can be used to say how confident the program is about that value being correct. Here’s an explanation.

Is there a crate I could use for this purpose?

I have a feeling checking the distribution of a function’s outputs is going to be annoying. It’s not like a normal boolean property test where you can check whether a value is true. The property is statistical in nature so you’ll probably need to repeatedly call the function then use statistics on the output.

I don’t know of any testing crates which will statistically analyse your function, so you may need to use statistics crates from and roll your own.

1 Like