PopStdDev

function PopStdDev(int[] calldata x, int[] calldata weight, uint8 precisions) returns the population standard deviation

Lenghts of x and weights have to be equal. Precision represents the number of decimal places and can be set between 0 and 18. It is applied to x, weights and output.

function PopStdDev(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) PopStdDev(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.PopStdDev(xf, wf)
	return toBig(stdDev, mul), nil, nil
}

Last updated