Skip to content

Commit fe32105

Browse files
committed
routing: add test for small scale
This test demonstrates that the current bimodal model leads to numerical inaccuracies in a certain regime of successes and failures.
1 parent 615b617 commit fe32105

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

routing/probability_bimodal_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,39 @@ func TestSuccessProbability(t *testing.T) {
242242
})
243243
}
244244

245+
// TestSmallScale tests that the probability formula works with small scale
246+
// values.
247+
func TestSmallScale(t *testing.T) {
248+
var (
249+
// We use the smallest possible scale value together with a
250+
// large capacity. This is an extreme form of a bimodal
251+
// distribution.
252+
scale lnwire.MilliSatoshi = 1
253+
capacity lnwire.MilliSatoshi = 7e+09
254+
255+
// Success and failure amounts are chosen such that the expected
256+
// balance must be somewhere in the middle of the channel, a
257+
// value not expected when dealing with a bimodal distribution.
258+
// In this case, the bimodal model fails to give good forecasts
259+
// due to the numerics of the exponential functions, which get
260+
// evaluated to exact zero floats.
261+
successAmount lnwire.MilliSatoshi = 1.0e+09
262+
failAmount lnwire.MilliSatoshi = 4.0e+09
263+
)
264+
265+
estimator := BimodalEstimator{
266+
BimodalConfig: BimodalConfig{BimodalScaleMsat: scale},
267+
}
268+
269+
// An amount that's close to the success amount should have a very high
270+
// probability.
271+
amtCloseSuccess := successAmount + 1
272+
_, err := estimator.probabilityFormula(
273+
capacity, successAmount, failAmount, amtCloseSuccess,
274+
)
275+
require.ErrorContains(t, err, "normalization factor is zero")
276+
}
277+
245278
// TestIntegral tests certain limits of the probability distribution integral.
246279
func TestIntegral(t *testing.T) {
247280
t.Parallel()

0 commit comments

Comments
 (0)