Ejemplo n.º 1
0
Archivo: ks.go Proyecto: ARodri/hume
func (ks *KS) compute(data map[string]float64, total int) (float64, error, string) {
	var err error
	var msg string
	testValue := float64(0)

	fm_data, _ := numeric.ND_Mapper(data)
	keys_data := fm_data.FloatSlice
	map_data := fm_data.Float2String
	totalZero := fm_data.TotalFloat

	benchmark, err := histogram.GetFloatMap(ks.BenchmarkJSON)
	if err != nil {
		msg = fmt.Sprintf("Error in benchmark float map: %s", err)
		logrus.Error(msg)
		return testValue, err, msg
	}
	fm_benchmark, err := numeric.ND_Mapper(benchmark)
	if err != nil {
		msg = fmt.Sprintf("Error in mapping benchmark to NumericDistribution: %s", err)
		logrus.Error(msg)
		return testValue, err, msg
	}
	keys_benchmark := fm_benchmark.FloatSlice
	map_benchmark := fm_benchmark.Float2String
	totalOne := fm_benchmark.TotalFloat

	key_map, keys_all := arrayMapper(keys_data, keys_benchmark)
	sort.Sort(sort.Float64Slice(keys_all))

	zeroSoFar := float64(0)
	oneSoFar := float64(0)
	currentKS := math.NaN()
	maxKS := float64(0)

	for _, f := range keys_all {
		if key_map[f][0] {
			zeroSoFar += data[map_data[f]]
		}
		if key_map[f][1] {
			oneSoFar += benchmark[map_benchmark[f]]
		}

		currentKS = (zeroSoFar / totalZero) - (oneSoFar / totalOne)

		if math.Abs(currentKS) > math.Abs(maxKS) || math.IsNaN(currentKS) {
			maxKS = currentKS
		}
	}

	testValue = maxKS * 100
	return testValue, err, msg
}
Ejemplo n.º 2
0
//NEAREST RANK METHOD (USES ONLY MEMBERS OF POPULATION - NO INTERPOLATION)
func (p *Percentile) Finalize() error {
	p.result = make(map[string]float64)

	fm, _ := numeric.ND_Mapper(p.counts)
	keys := fm.FloatSlice
	m := fm.Float2String
	totalFloat := fm.TotalFloat
	sort.Sort(sort.Float64Slice(keys))

	for c := float64(0); c < 100; c++ {
		threshold := totalFloat * c / 100
		sum := float64(0)
		//keep index of key coorsponding to last sum
		var i int
		var k float64
		for i, k = range keys {
			sum += p.counts[m[k]]
			if sum >= threshold {
				break
			}
		}
		p.result[strconv.FormatFloat(c, 'f', -1, 64)] = keys[i]
	}

	return nil
}
Ejemplo n.º 3
0
func (nv *NearestValueThreshold) compute(data map[string]float64, total int) (float64, error, string) {
	var err error
	var msg string
	testValue := float64(0)

	testFloat, err := strconv.ParseFloat(nv.Value, 64)
	if err != nil {
		msg = fmt.Sprintf("Error converting value to float: %s", err)
		logrus.Error(msg)
		return testValue, err, msg
	}

	fm, _ := numeric.ND_Mapper(data)
	keys := fm.FloatSlice
	m := fm.Float2String
	sort.Sort(sort.Float64Slice(keys))

	for _, k := range keys {
		if testFloat >= k {
			testValue = data[m[k]]
		} else {
			break
		}
	}

	testValue = testValue * 100
	return testValue, err, msg
}
Ejemplo n.º 4
0
func (cdf *CDF) Finalize() error {
	cdf.result = make(map[string]float64)

	fm, _ := numeric.ND_Mapper(cdf.counts)
	keys := fm.FloatSlice
	m := fm.Float2String
	totalFloat := fm.TotalFloat
	sort.Sort(sort.Float64Slice(keys))

	sum := float64(0)
	for _, f := range keys {
		sum += cdf.counts[m[f]]
		cdf.result[m[f]] = sum / totalFloat
	}

	return nil
}