Skip to content

Commit f168a71

Browse files
committed
fix some value calculators and add docs
1 parent 6d43f34 commit f168a71

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

epsilon_value_calculators.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import (
88

99
// --- Definitions -----------------------
1010

11+
// Structs implementing this interface are used to convert the average response time for a host
12+
// into a score that can be used to weight hosts in the epsilon greedy hostpool. Lower response
13+
// times should yield higher scores (we want to select the faster hosts more often) The default
14+
// LinearEpsilonValueCalculator just uses the reciprocal of the response time. In practice, any
15+
// decreasing function from the positive reals to the positive reals should work.
1116
type EpsilonValueCalculator interface {
1217
CalcValueFromAvgResponseTime(float64) float64
1318
}
@@ -26,9 +31,10 @@ func (c *LinearEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) f
2631
}
2732

2833
func (c *LogEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) float64 {
29-
return math.Log(c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(v))
34+
// we need to add 1 to v so that this will be defined on all positive floats
35+
return c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(math.Log(v + 1.0))
3036
}
3137

3238
func (c *PolynomialEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) float64 {
33-
return math.Pow(c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(v), c.Exp)
39+
return c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(math.Pow(v, c.Exp))
3440
}

0 commit comments

Comments
 (0)