Skip to main content

Mojo function

variance

variance(src: NDBuffer[dtype, 1, origin], mean_value: SIMD[dtype, 1], correction: Int = 1) -> SIMD[dtype, 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 (NDBuffer[dtype, 1, origin]): The buffer.
  • mean_value (SIMD[dtype, 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[dtype: DType, input_fn_1d: fn[DType, Int](idx: Int) capturing -> SIMD[$0, $1]](length: Int, mean_value: SIMD[dtype, 1], correction: Int = 1) -> SIMD[dtype, 1]

variance(src: NDBuffer[dtype, 1, origin], correction: Int = 1) -> SIMD[dtype, 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 (NDBuffer[dtype, 1, origin]): The buffer.
  • correction (Int): Normalize variance by size - correction (Default=1).

Returns:

The variance value of the elements in a buffer.

variance[dtype: DType, input_fn_1d: fn[DType, Int](idx: Int) capturing -> SIMD[$0, $1]](length: Int, correction: Int = 1) -> SIMD[dtype, 1]

Was this page helpful?