github.com/blend/go-sdk@v1.20220411.3/mathutil/std_dev.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package mathutil
     9  
    10  import "math"
    11  
    12  // StdDevP finds the amount of variation from the population
    13  func StdDevP(input []float64) float64 {
    14  	if len(input) == 0 {
    15  		return 0
    16  	}
    17  
    18  	// stdev is generally the square root of the variance
    19  	return math.Pow(VarP(input), 0.5)
    20  }
    21  
    22  // StdDevS finds the amount of variation from a sample
    23  func StdDevS(input []float64) float64 {
    24  	if len(input) == 0 {
    25  		return 0
    26  	}
    27  
    28  	// stdev is generally the square root of the variance
    29  	return math.Pow(VarS(input), 0.5)
    30  }