Skip to content

Decrease Variance of LogNormal to Converge on Expected Value Sooner #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

carlaKC
Copy link
Contributor

@carlaKC carlaKC commented Aug 14, 2025

See rationale here.

This PR makes a fix to the way we pick our LogNormal distribution's parameters which results in our getting to an average of our expected_payment_amount much sooner.

As this changes the way we pick payments, the hard-coded ordering of some of our tests has to change.
While I'm here, I also make some changes to long-running unit tests to speed them up a bit.

Previously we created our normal distribution with a very large sigma,
which would result in our samples taking a long time to converge on
our expected payment amount (around 100,000 samples required to get
close with previous values).

This commit changes our variance to still depend on payment channel
size, but do so more gently. The values picked in this PR are somewhat
reverse engineered - we ran a few experiments to find acceptable
variance ranges, took a look at typical channel sizes in lightning and
then worked backwards to find a relation between channel size and
acceptable variance that would fit.
Speed up this test by using our sim clock that can speed up the
simulation. The downside of this clock is that we may stop one payment
over/under if we try to match exactly to the number of payments that
we expect in a given period of time.

Instead, we generate our set of expected payment and then run the
simulation for much longer than we need to get this expected list, so
we should always get at least this subset. We then just assert that the
payments we get exactly match this first set.
@carlaKC
Copy link
Contributor Author

carlaKC commented Aug 14, 2025

Review note: I don't expect folks to go through the math of this one, Clara and I did it offline before this came up and she's been over the code.

General review of code, any under/over flows that we could have with this math, test coverage etc is still very appreciated!

@carlaKC carlaKC requested review from f3r10 and elnosh August 14, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant