Пример #1
0
func normalDistributionDemo() {
	maxTrials := 100
	printEvery := 10
	fmt.Printf("\nGenerating %v normal samples. The descriptive statistics ", maxTrials)
	fmt.Printf("converge to the appropriate values: mean→0, variance→1, skew→0, kurtosis→0. \n")
	var d stats.Stats
	for i := 0; i <= maxTrials; i++ {
		y := rand.NormFloat64()
		d.Update(y)
		if i != 0 && i%printEvery == 0 {
			mean := d.Mean()
			variance := d.PopulationVariance()
			skew := d.PopulationSkew()
			kurtosis := d.PopulationKurtosis()
			fmt.Printf("itr %v: mean (→0.0) = %0.5f, variance (→1.0) = %0.5f, skew (→0.0) = %0.5f, kurtosis (→0.0) = %0.5f\n",
				i, mean, variance, skew, kurtosis)
		}
	}
}
Пример #2
0
func incrementalDemo() {
	var d stats.Stats
	fmt.Printf("\n**** Descriptive Statistics, Incremental Updates **\n")
	fmt.Printf("** create a new descriptive stats struct:\n")
	fmt.Printf("var d stats.Stats\n")
	fmt.Printf("** update it with new values:\n")
	for i := 0; i < NUM_SAMPLES; i++ {
		x := rand.Float64()*100.0 - 25.0 // uniform samples in {-25, 75}
		fmt.Printf("d.Update(%v)\n", x)
		d.Update(x)
	}
	fmt.Printf("then request stats, for example:    d.Count()\n")
	fmt.Printf("\n** Descriptive Statistics:\n")
	fmt.Printf("count = %v\n", d.Count())
	fmt.Printf("min = %v\n", d.Min())
	fmt.Printf("max = %v\n", d.Max())
	fmt.Printf("sum = %v\n", d.Sum())
	fmt.Printf("mean = %v\n", d.Mean())
	fmt.Printf("standard deviation = %v\n", d.SampleStandardDeviation())
	fmt.Printf("variance = %v\n", d.SampleVariance())
	skew := d.SampleSkew()
	fmt.Printf("skew = %v\n", skew)
	//
	// The rand functions return uniformly distributed values. Therefore, with
	// enough samples, the skew should be 0. Try increasing NUM_SAMPLES
	if skew < 0.0 {
		fmt.Printf("  The sample is skews left (longer tail to left).\n")
	} else if skew > 0.0 {
		fmt.Printf("  The sample is skews right (longer tail to right).\n")
	}
	kurtosis := d.SampleKurtosis()
	fmt.Printf("kurtosis = %v\n", kurtosis)
	//
	// The rand functions return uniformly distributed values. Therefore, with
	// enough of them, our sample should be flat, or platykurtic.
	if kurtosis < 0.0 {
		fmt.Printf("  The sample is platykurtic.\n")
	} else if kurtosis > 0.0 {
		fmt.Printf("  The sample is leptokurtic.\n")
	}
}