Skip to main content
Log in

Mojo function

variance

variance(src: Buffer[type, size, address_space=address_space, origin=origin], mean_value: SIMD[type, 1], correction: Int = 1) -> SIMD[type, 1]

Given a mean, computes the variance of elements in a buffer.

The mean value is used to avoid a second pass over the data:

variance(x) = sum((x - E(x))^2) / (size - correction)
variance(x) = sum((x - E(x))^2) / (size - correction)

Args:

  • src (Buffer[type, size, address_space=address_space, origin=origin]): The buffer.
  • mean_value (SIMD[type, 1]): The mean value of the buffer.
  • correction (Int): Normalize variance by size - correction.

Returns:

The variance value of the elements in a buffer.

variance(src: Buffer[type, size, address_space=address_space, origin=origin], correction: Int = 1) -> SIMD[type, 1]

Computes the variance value of the elements in a buffer.

variance(x) = sum((x - E(x))^2) / (size - correction)
variance(x) = sum((x - E(x))^2) / (size - correction)

Args:

  • src (Buffer[type, size, address_space=address_space, origin=origin]): The buffer.
  • correction (Int): Normalize variance by size - correction (Default=1).

Returns:

The variance value of the elements in a buffer.