StdDev

function StdDev(int[] calldata x, int[] calldata weights, uint8 precision) returns the sample standard deviation.

The length of x and weights must be equal. Precision representes the number of decimal places between 0 and 18. It is applied to x, weights and the output.

function StdDev(int[] calldata x, int[] calldata weights, uint8 precision) external returns (int)

Under the hood, the following functions are utilized directly in the Neural client.

func (con *NeuralMath) StdDev(gas *big.Int, x, weights []*big.Int, precision uint8) (*big.Int, error, *big.Int) {
	mul, err := validatePrecision(precision)
	if err != nil {
		return nil, err, nil
	}
	if len(x) != len(weights) {
		return nil, errors.New("x must have the same length as weghts"), nil
	}
	xf, err := toFloats(x, mul)
	if err != nil {
		return nil, err, nil
	}
	wf, err := toFloats(weights, mul)
	if err != nil {
		return nil, err, nil
	}
	stdDev := stat.StdDev(xf, wf)
	return toBig(stdDev, mul), nil, nil
}

Last updated