Skip to content

Commit

Permalink
changes reviewed and polished
Browse files Browse the repository at this point in the history
  • Loading branch information
rnugent3 committed Nov 15, 2024
1 parent debc618 commit d3f236d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 30 deletions.
1 change: 1 addition & 0 deletions HEC.FDA.Model/compute/RandomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace HEC.FDA.Model.compute
{
//TODO: I think that this class can be ripped out, this is a wrapper around Random with little added functionality
public class RandomProvider : IProvideRandomNumbers
{
private Random _randomNumberGenerator;
Expand Down
2 changes: 1 addition & 1 deletion HEC.FDA.Model/metrics/ImpactAreaScenarioResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public double AssuranceOfAEP(int thresholdID, double exceedanceProbability)
}
public DynamicHistogram GetAEPHistogramForPlotting(int thresholdID)
{
return PerformanceByThresholds.GetThreshold(thresholdID).SystemPerformanceResults.GetAEPHistogramForPlotting();
return PerformanceByThresholds.GetThreshold(thresholdID).SystemPerformanceResults.GetAEPHistogram();
}
public double LongTermExceedanceProbability(int thresholdID, int years)
{
Expand Down
21 changes: 1 addition & 20 deletions HEC.FDA.Model/metrics/SystemPerformanceResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ public class SystemPerformanceResults : ValidationErrorLogger
#region Fields
private const string AEP_ASSURANCE_TYPE = "AEP";
private const string STAGE_ASSURANCE_TYPE = "STAGE";
private const string AEP_ASSURANCE_FOR_PLOTTING = "AEP_PLOT";
private const double AEP_BIN_WIDTH = 0.0002;
private const double STAGE_BIN_WIDTH = 0.001;
private const double AEP_FOR_PLOTTING_BIN_WIDTH = 0.02;
private readonly bool _CalculatePerformanceForLevee;
private readonly UncertainPairedData _SystemResponseFunction;
private readonly ConvergenceCriteria _ConvergenceCriteria;
Expand All @@ -38,8 +36,6 @@ public SystemPerformanceResults()
Assurances = new List<AssuranceResultStorage>();
AssuranceResultStorage dummyAEP = new(AEP_ASSURANCE_TYPE, 0);
Assurances.Add(dummyAEP);
AssuranceResultStorage dummyPlottingAEP = new(AEP_ASSURANCE_FOR_PLOTTING, 0);
Assurances.Add(dummyPlottingAEP);
double[] standardNonExceedanceProbabilities = new double[] { .9, .96, .98, .99, .996, .998 };
foreach (double probability in standardNonExceedanceProbabilities)
{
Expand All @@ -53,8 +49,6 @@ public SystemPerformanceResults(ConvergenceCriteria convergenceCriteria)
Assurances = new List<AssuranceResultStorage>();
AssuranceResultStorage aepAssurance = new(AEP_ASSURANCE_TYPE, AEP_BIN_WIDTH, convergenceCriteria);
Assurances.Add(aepAssurance);
AssuranceResultStorage aepAssuranceForPlotting = new(AEP_ASSURANCE_FOR_PLOTTING, AEP_FOR_PLOTTING_BIN_WIDTH, convergenceCriteria);
Assurances.Add(aepAssuranceForPlotting);
}
public SystemPerformanceResults(UncertainPairedData systemResponseFunction, ConvergenceCriteria convergenceCriteria)
{
Expand All @@ -70,8 +64,6 @@ public SystemPerformanceResults(UncertainPairedData systemResponseFunction, Conv
Assurances = new List<AssuranceResultStorage>();
AssuranceResultStorage aepAssurance = new(AEP_ASSURANCE_TYPE, AEP_BIN_WIDTH, convergenceCriteria);
Assurances.Add(aepAssurance);
AssuranceResultStorage aepAssuranceForPlotting = new(AEP_ASSURANCE_FOR_PLOTTING, AEP_FOR_PLOTTING_BIN_WIDTH, convergenceCriteria);
Assurances.Add(aepAssuranceForPlotting);
_ConvergenceCriteria = convergenceCriteria;
}

Expand Down Expand Up @@ -112,22 +104,12 @@ public void AddStageAssuranceHistogram(double standardNonExceedanceProbability,
Assurances.Add(assurance);
}
}
/// <summary>
/// This method returns the thread safe inline histogram of AEPs
/// This method is only used to get the histogram for plotting purposes.
/// </summary>
/// <returns></returns>
public DynamicHistogram GetAEPHistogramForPlotting()
{
DynamicHistogram aepHistogram = GetAssurance(AEP_ASSURANCE_TYPE).AssuranceHistogram;
return aepHistogram;
}
public DynamicHistogram GetAssuranceOfThresholdHistogram(double standardNonExceedanceProbability)
{
DynamicHistogram stageHistogram = GetAssurance(STAGE_ASSURANCE_TYPE, standardNonExceedanceProbability).AssuranceHistogram;
return stageHistogram;
}
internal DynamicHistogram GetAEPHistogramForMetrics()
internal DynamicHistogram GetAEPHistogram()
{
DynamicHistogram aepHistogram = GetAssurance(AEP_ASSURANCE_TYPE).AssuranceHistogram;
return aepHistogram;
Expand All @@ -136,7 +118,6 @@ internal DynamicHistogram GetAEPHistogramForMetrics()
public void AddAEPForAssurance(double aep, int iteration)
{
GetAssurance(AEP_ASSURANCE_TYPE).AddObservation(aep, iteration);
GetAssurance(AEP_ASSURANCE_FOR_PLOTTING).AddObservation(aep, iteration);
}
public void AddStageForAssurance(double standardNonExceedanceProbability, double stage, int iteration)
{
Expand Down
1 change: 1 addition & 0 deletions HEC.FDA.Model/stageDamage/ScenarioStageDamage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public ScenarioStageDamage(List<ImpactAreaStageDamage> impactAreaStageDamages)
#region Methods
/// <summary>
/// Begins the outermost loop of the Scenario Stage Damage Compute.
/// At this time, the compute engine can run a deterministic stage-damage compute, but the user interface does not avail that option.
/// Scenario SD <--
/// Impact Area SD
/// Damage Catagory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public void ComputeMeanEADWithIterations_Test(int iterations, int seed, double e
.WithStageDamages(stageDamageList)
.Build();

RandomProvider randomProvider = new RandomProvider(seed);
ConvergenceCriteria convergenceCriteria = new ConvergenceCriteria(minIterations: 100, maxIterations: iterations);
ImpactAreaScenarioResults results = simulation.Compute(convergenceCriteria);
double difference = expected - results.ConsequenceResults.MeanDamage(damCat, assetCat, impactAreaID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void TrackStageDamageTest(double[] expectedResDamage, double[] expectedCo
double relativeTolerance = 0.05;
foreach (UncertainPairedData stageDamageFunction in stageDamageFunctions)
{
IPairedData pairedData = stageDamageFunction.SamplePairedData(0.5);
IPairedData pairedData = stageDamageFunction.SamplePairedData(iterationNumber:1, retrieveDeterministicRepresentation:true);
if (stageDamageFunction.CurveMetaData.DamageCategory == residentialDamAndOccType)
{
if (stageDamageFunction.CurveMetaData.AssetCategory == structureAssetType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ private double[] getXValues()
{
if (_data.FlipXAxisValues)
{
foreach (double x in Function.SamplePairedData(0.5).Xvals) //TODO: Clean this up. This is stupid to sample to paired data twice.
foreach (double x in Function.SamplePairedData(iteration:1, computeIsDeterministic:true).Xvals) //TODO: Clean this up. This is stupid to sample to paired data twice.
{
xVals.Add(1 - x);
}
}
else
{
xVals.AddRange(Function.SamplePairedData(.5).Xvals);
xVals.AddRange(Function.SamplePairedData(iteration: 1, computeIsDeterministic: true).Xvals);
}
}

Expand All @@ -175,7 +175,7 @@ private double[] getYValues()
double[] yVals = Array.Empty<double>();
if (Function != null)
{
PairedData pd = Function.SamplePairedData(.5);
PairedData pd = Function.SamplePairedData(iteration: 1, computeIsDeterministic: true);
yVals = pd.Yvals;
}
return yVals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void UpdateYAxisLabel()
{
if (Function != null)
{
PairedData pd = Function.SamplePairedData(0.5);
PairedData pd = Function.SamplePairedData(iteration: 1, computeIsDeterministic: true);
UpdateYAxisLabel(pd.MetaData.YLabel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public LP3HistogramDataProvider(UncertainPairedData upd, bool isStrictMonotonic)
/// <param name="inputFunctionVals"></param>
public void OverwriteInputFunctionVals(UncertainPairedData inputFunctionVals)
{
PairedData deterministicInputFunc = inputFunctionVals.SamplePairedData(0.5);
deterministicInputFunc.SortToIncreasingXVals();
PairedData medianInputFunction = inputFunctionVals.SamplePairedData(0.5);
medianInputFunction.SortToIncreasingXVals();
for (int i = 0; i < Data.Count; i++)
{
LP3HistogramRow row = (LP3HistogramRow)Data[i];
double probability = row.X;
row.InputFunctionY = deterministicInputFunc.f(probability);
row.InputFunctionY = medianInputFunction.f(probability);
}
}

Expand Down

0 comments on commit d3f236d

Please sign in to comment.