Skip to content
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

Add support for reproducible pseudo random number sequences #2768

Closed
plonk75 opened this issue Oct 14, 2020 · 2 comments · Fixed by #2801
Closed

Add support for reproducible pseudo random number sequences #2768

plonk75 opened this issue Oct 14, 2020 · 2 comments · Fixed by #2801
Labels
enhancement Something new (not a bug fix) is being requested

Comments

@plonk75
Copy link

plonk75 commented Oct 14, 2020

As far as I understand, there is currently no way to seed the PRNG with an arbitrary seed. I've searched the code for "random" and found what I think is the random number generator delegate in /kOS.Safe/Function/Math.cs, but I see no way to actually seed it to get reproducible random number sequences.

I believe to understand how the current MATH:RANDOM() method works internally when I read the existing C# code, but as I'm not particularly familiar with C# or the overall design of kOS, I don't see where to inject a seed value and how to keep the seeded Random object in the right scope, making it even reseedable. So I can't make a PR myself.

Background:
When my sparetime allows it, I'm "working" on a self improving spaceplane launch script, basically using a "randomize last best parameter set - run scripts - evaluate flight - pick next best parameter set - repeat" approach. IIRC, it was Kevin Gisi who published a video on YT where a script finds a transfer orbit from Kerbin to the Mun using this or a very similar approach.

Problem is: The required number of flights to probe the parameter space is exponentially growing with every dimension in parameter space. That's where the fun part starts, finding optimizations.
When optimizing, e.g. using the accumulated results of several flights to extrapolate some kind of gradient in parameter space and cost function value, and using this data to do a less random "quasi conjugate gradient" approach, I see no way of actually repeating the randomized modifications on the parameters, and this makes assessment of optimizations very difficult.

At this point reproducible pseudo random number sequences would be extremely nice.

Please excuse my clunky wording and language. I hope you get the idea.

@Dunbaratu Dunbaratu added the enhancement Something new (not a bug fix) is being requested label Oct 18, 2020
@Dunbaratu
Copy link
Member

It shouldn't be too hard to make an option to force a seed.

@Dunbaratu
Copy link
Member

This should have been closed by PR #2801 but I had a typo in the "Fixes #" tag there so I have to close it manually now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new (not a bug fix) is being requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants