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

Random number generation seeding structure refactor #1168

Merged
merged 22 commits into from
Nov 18, 2024

Conversation

rnugent3
Copy link
Contributor

No description provided.

Verified

This commit was signed with the committer’s verified signature.
sagikazarmark Márk Sági-Kazár

Verified

This commit was signed with the committer’s verified signature.
sagikazarmark Márk Sági-Kazár

Verified

This commit was signed with the committer’s verified signature.
sagikazarmark Márk Sági-Kazár

Verified

This commit was signed with the committer’s verified signature.
sagikazarmark Márk Sági-Kazár
@rnugent3 rnugent3 marked this pull request as ready for review November 15, 2024 18:09
@rnugent3
Copy link
Contributor Author

Checking build and tests on GitHub because ACE-IT told me no. Please hold off review.

@Brennan1994 Brennan1994 force-pushed the RandomNumberGenerationSeedingStructureRefactor branch from d3f236d to ab1a995 Compare November 15, 2024 18:32
@@ -618,14 +618,13 @@ private async Task<List<UncertainPairedData>> ComputeStageDamageFunctionsAsync(S

ScenarioStageDamage scenarioStageDamage = new(impactAreaStageDamages);
int seed = 1234;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seed never used.

@@ -51,9 +51,8 @@ public static Task ComputeScenario(IASElement elem, Scenario scenario, Action<IA
return Task.Run(() =>
{
int seed = 1234;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seed never used

@@ -343,18 +346,13 @@ private PairedData IdentifyCentralStageFrequencyAtIndexLocation()
/// <param name="inventoryAndWaterTupled"></param>
/// <param name="profileProbabilities"></param>
/// <returns></returns>
private List<StudyAreaConsequencesBinned> ComputeDamageWithUncertaintyAllCoordinates(string damageCategory, IProvideRandomNumbers randomProvider, (Inventory, List<float[]>) inventoryAndWaterTupled, List<double> profileProbabilities)
private List<StudyAreaConsequencesBinned> ComputeDamageWithUncertaintyAllCoordinates(string damageCategory, (Inventory, List<float[]>) inventoryAndWaterTupled, List<double> profileProbabilities, bool computeIsDeterministic)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to talk about whether we still need this bool.

@@ -637,7 +635,7 @@ public void ReportProgress(object sender, ProgressReportEventArgs e)
internal List<string> ProduceImpactAreaStructureDetails(Dictionary<int, string> impactAreaNames)
{
//this list will be the size of the number of structures + 1 where the first string is the header
List<DeterministicOccupancyType> deterministicOccupancyTypes = Inventory.SampleOccupancyTypes(new compute.MedianRandomProvider(), computeIsDeterministic: true);
List<DeterministicOccupancyType> deterministicOccupancyTypes = Inventory.SampleOccupancyTypes(iteration:1, computeIsDeterministic: true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we previously wanted the mean here. now we're getting the iteration 1 sample. Are we still good?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comments to note that iteration is ignored for compute is deterministic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added public XML comments on all of the objects that can be sampled

@Brennan1994
Copy link
Collaborator

There's more here than i can chew on. Lets chat about a few things in your office today, and we'll approve or identify changes after that

@rnugent3 rnugent3 merged commit 4c76657 into main Nov 18, 2024
1 check passed
@rnugent3 rnugent3 deleted the RandomNumberGenerationSeedingStructureRefactor branch November 18, 2024 23:09
@Brennan1994
Copy link
Collaborator

Brennan1994 commented Dec 4, 2024

The suspected result changing modification here is moving from a sampling schema which samples a small number of samples from a large number of random number generators to a new schema of a single random number generator with many samples.

The results appear better distributed after the changes in this request. The design choice between these two sampling schemes was presented in a code review with computer scientists outside the HEC-FDA team including Senior Computer Scientist Alex Kennedy, and checked against industry best practices as documented by Microsoft. Generating many values from a single generator is the proper use of Random.cs.

"Both to improve performance and to avoid inadvertently creating separate random number generators that generate identical numeric sequences, we recommend that you create one Random object to generate many random numbers over time, instead of creating new Random objects to generate one random number." - Microsoft docs
https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-random

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.

None yet

2 participants