Пример #1
0
//write data to text file for humans
func printDataToFile(f *os.File, c [][][]float64, total float64, centers [][]float64) {
	for k := 0; k < len(c); k++ {
		fmt.Println(total)
		f.WriteString("CLUSTER:" + strconv.FormatInt(int64(k), 8) + "\n")
		f.WriteString("There is " + strconv.FormatFloat(float64(len(c[k]))/total*100.0, 'f', 2, 64) + " percent of the data in this cluster" + "\n")
		f.WriteString("The mean of this cluster is " + vectorOperations.ToString(vectorOperations.FindMean(c[k])) + "\n")
		f.WriteString("The variance of this cluster is " + vectorOperations.ToString(vectorOperations.FindVariance(c[k], vectorOperations.FindMean(c[k]))) + "\n")
		for i := k + 1; i < len(c); i++ {
			f.WriteString("The distance between this cluster and cluster " + strconv.FormatInt(int64(i), 8) + " is " +
				strconv.FormatFloat(vectorOperations.CalcDistance(centers[i], centers[k]), 'f', 6, 64) + "\n")
		}
	}
}
Пример #2
0
func (c *Cluster) variance() []float64 {
	if len(c.Packets) == 0 {
		return make([]float64, 0)
	}
	return vectorOperations.FindVariance(c.Clusters[0], vectorOperations.FindMean(c.Clusters[0]))
}