Skip to content

Commit

Permalink
V3 solver std dev fix (#407)
Browse files Browse the repository at this point in the history
* Fixed an issued with the combining of result paths affecting the standard deviation. Also fixed the seed not being assigned from opening a recent/saved.

* Updated SemEnginTests results

* assign stdDev
  • Loading branch information
pressr-inl authored Jan 17, 2025
1 parent 06ae1d3 commit 3762288
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 379 deletions.
1 change: 1 addition & 0 deletions EMRALD_Sim/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ private void PopulateSettingsFromJson()
tbSavePath.Text = _currentModelSettings.BasicResultsLocation;
tbSavePath2.Text = _currentModelSettings.PathResultsLocation;
tbSeed.Text = _currentModelSettings.Seed;
LoadLib.SetSeed(tbSeed.Text);
tbLogRunStart.Text = _currentModelSettings.DebugFromRun.ToString();
tbLogRunEnd.Text = _currentModelSettings.DebugToRun.ToString();

Expand Down
2 changes: 1 addition & 1 deletion SimulationEngine/CurrentStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public Dictionary<string, TimeSpan> GetKeyStatePaths(EmraldModel model, Dictiona

addToRes = keyResMap[curStatePath.state.name].pathsLookup;
//add the time for the key state overall result
keyResMap[curStatePath.state.name].AddTime(curStatePath.times[curStatePath.times.Count - 1]);
//keyResMap[curStatePath.state.name].AddTime(curStatePath.times[curStatePath.times.Count - 1]);

retStateResults.Add(curStatePath.state.name, curStatePath.times[curStatePath.times.Count - 1]);
}
Expand Down
4 changes: 3 additions & 1 deletion SimulationEngine/ResultObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public TimeSpan timeMean {
[JsonProperty(Order = 7)]
public TimeSpan timeStdDeviation
{
get { return GetTimeStdDev(); }
get { return GetTimeStdDev(); }
set { _stdDev = value; }
}
[JsonProperty(Order = 8)]
Expand Down Expand Up @@ -401,6 +401,7 @@ public void Collapse()
this._totalTime = TimeSpan.FromSeconds(0);
this._timeMin = TimeSpan.FromSeconds(0);
this._timeMax = TimeSpan.FromSeconds(0);
this._stdDev = null;

this.AddTime(newTime);
}
Expand Down Expand Up @@ -455,6 +456,7 @@ public void ShallowCopy(ResultStateBase toCopy)
_rate95th = toCopy._rate95th;
_timeMin = toCopy._timeMin;
_timeMax = toCopy._timeMax;
_stdDev = null;
}

public virtual void Merge(ResultStateBase other, int totCnt)
Expand Down
132 changes: 85 additions & 47 deletions UnitTesting_Simulation/SimEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,52 +700,90 @@ public void VarAccruTest()
Compare(dir, testName, optionsJ);
}

[Fact]
//Make sure StdDev Calculation is working
public void ResultsCalcTest()
{
//string testName = GetCurrentMethodName(); //function name must match the name of the test model and saved in the models folder.

////Setup directory for unit test
//string dir = SetupTestDir(testName);
////initial options, and optional results to save/test
//JObject optionsJ = SetupJSON(dir, testName, false);

//set up fake result info for testing
ResultStateBase results = new ResultStateBase("test", true);
results.AddTime(TimeSpan.FromMinutes(581.1));
results.AddTime(TimeSpan.FromMinutes(274.2));
results.AddTime(TimeSpan.FromMinutes(1290.8));
results.AddTime(TimeSpan.FromMinutes(959.8));
results.AddTime(TimeSpan.FromMinutes(1295.2));
results.AddTime(TimeSpan.FromMinutes(152.6));
results.AddTime(TimeSpan.FromMinutes(533.9));

results.CalcStats(100);
double mean = results.timeMean.TotalHours;
double th5 = results.cRate5th;
double t95 = results.cRate95th;
double timeStd = results.GetTimeStdDev().TotalHours;





//Uncomment to update the validation files after they verified correct
//CopyToValidated(dir, testName, optionsJ);

//compare the test result and optionally the paths and json if assigned
//Compare(dir, testName, optionsJ);
}


//[Fact]
//public void DistEvent_Exponential()
//{
// string testName = GetCurrentMethodName(); //function name must match the name of the test model and saved in the models folder.

// //Setup directory for unit test
// string dir = SetupTestDir(testName);
// //initial options, and optional results to save/test
// JObject optionsJ = SetupJSON(dir, testName, true);

// //Change the default settings as needed for the test seed default set to 0 for testing.
// optionsJ["inpfile"] = MainTestDir() + ModelFolder() + testName + ".json";
// optionsJ["runct"] = 100000;
// JSONRun testRun = new JSONRun(optionsJ.ToString());
// Assert.True(TestRunSim(testRun));

// //Uncomment to update the validation files after they verified correct
// //CopyToValidated(dir, testName, optionsJ);

// //compare the test result and optionally the paths and json if assigned
// Compare(dir, testName, optionsJ);
//}

//[Fact]
//public void DistEvent_Exponential_Vars()
//{
// string testName = GetCurrentMethodName(); //function name must match the name of the test model and saved in the models folder.

// //Setup directory for unit test
// string dir = SetupTestDir(testName);
// //initial options, and optional results to save/test
// JObject optionsJ = SetupJSON(dir, testName, true);

// //Change the default settings as needed for the test seed default set to 0 for testing.
// optionsJ["inpfile"] = MainTestDir() + ModelFolder() + testName + ".json";
// optionsJ["runct"] = 100000;
// JSONRun testRun = new JSONRun(optionsJ.ToString());
// Assert.True(TestRunSim(testRun));

// //Uncomment to update the validation files after they verified correct
// //CopyToValidated(dir, testName, optionsJ);

// //compare the test result and optionally the paths and json if assigned
// Compare(dir, testName, optionsJ);
//}

}
//[Fact]
//public void DistEvent_Exponential()
//{
// string testName = GetCurrentMethodName(); //function name must match the name of the test model and saved in the models folder.

// //Setup directory for unit test
// string dir = SetupTestDir(testName);
// //initial options, and optional results to save/test
// JObject optionsJ = SetupJSON(dir, testName, true);

// //Change the default settings as needed for the test seed default set to 0 for testing.
// optionsJ["inpfile"] = MainTestDir() + ModelFolder() + testName + ".json";
// optionsJ["runct"] = 100000;
// JSONRun testRun = new JSONRun(optionsJ.ToString());
// Assert.True(TestRunSim(testRun));

// //Uncomment to update the validation files after they verified correct
// //CopyToValidated(dir, testName, optionsJ);

// //compare the test result and optionally the paths and json if assigned
// Compare(dir, testName, optionsJ);
//}

//[Fact]
//public void DistEvent_Exponential_Vars()
//{
// string testName = GetCurrentMethodName(); //function name must match the name of the test model and saved in the models folder.

// //Setup directory for unit test
// string dir = SetupTestDir(testName);
// //initial options, and optional results to save/test
// JObject optionsJ = SetupJSON(dir, testName, true);

// //Change the default settings as needed for the test seed default set to 0 for testing.
// optionsJ["inpfile"] = MainTestDir() + ModelFolder() + testName + ".json";
// optionsJ["runct"] = 100000;
// JSONRun testRun = new JSONRun(optionsJ.ToString());
// Assert.True(TestRunSim(testRun));

// //Uncomment to update the validation files after they verified correct
// //CopyToValidated(dir, testName, optionsJ);

// //compare the test result and optionally the paths and json if assigned
// Compare(dir, testName, optionsJ);
//}

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Simulation = UnitTestActions
Runtime = 00.00:00:02
Runs = 10 of 10
OK Occurred 5 times, Rate =0.5, MeanTime = 00.00:00:10 +/- 00.00:00:00.00
Fail Occurred 5 times, Rate =0.5, MeanTime = 00.00:00:10 +/- 00.00:00:00.00
OK Occurred 5 times, Probability =0.5, MeanTime = 00.00:00:10 +/- 00.00:00:00.00
Fail Occurred 5 times, Probability =0.5, MeanTime = 00.00:00:10 +/- 00.00:00:00.00
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Simulation = DefaultVars
Runtime = 00.00:00:00
Runs = 10 of 10
CntGood Occurred 10 times, Rate =1, MeanTime = 00.01:00:00 +/- 00.00:00:00.00
CurTimeGood Occurred 10 times, Rate =1, MeanTime = 00.01:00:00 +/- 00.00:00:00.00
CntGood Occurred 10 times, Probability =1, MeanTime = 00.01:00:00 +/- 00.00:00:00.00
CurTimeGood Occurred 10 times, Probability =1, MeanTime = 00.01:00:00 +/- 00.00:00:00.00
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cRate95th": 0.9988134,
"count": 99858,
"timeMean": "27.05:49:05.2071829",
"timeStdDeviation": "45.20:50:33.4431489",
"timeStdDeviation": "32.10:24:47.8727932",
"timeMin": "07:17:15.1886119",
"timeMax": "364.16:17:13.2211549",
"watchVariables": {},
Expand Down Expand Up @@ -44,7 +44,7 @@
"cRate95th": 1.0,
"count": 99858,
"timeMean": "27.05:49:05.2071829",
"timeStdDeviation": "45.20:50:33.4431489",
"timeStdDeviation": "32.10:24:47.8727932",
"timeMin": "07:17:15.1886119",
"timeMax": "364.16:17:13.2211549",
"watchVariables": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = DistEvTest1
Runtime = 00.00:00:02
Runtime = 00.00:00:03
Runs = 100000 of 100000
Event Occurred 99858 times, Rate =0.99858, MeanTime = 27.05:49:05 +/- 45.20:50:33.44
Event Occurred 99858 times, Probability =0.99858, MeanTime = 27.05:49:05 +/- 32.10:24:47.87
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cRate95th": 0.9988134,
"count": 99858,
"timeMean": "27.05:49:05.2071829",
"timeStdDeviation": "45.20:50:33.4431489",
"timeStdDeviation": "32.10:24:47.8727932",
"timeMin": "07:17:15.1886119",
"timeMax": "364.16:17:13.2211549",
"watchVariables": {},
Expand Down Expand Up @@ -44,7 +44,7 @@
"cRate95th": 1.0,
"count": 99858,
"timeMean": "27.05:49:05.2071829",
"timeStdDeviation": "45.20:50:33.4431489",
"timeStdDeviation": "32.10:24:47.8727932",
"timeMin": "07:17:15.1886119",
"timeMax": "364.16:17:13.2211549",
"watchVariables": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = DistEvTest1
Runtime = 00.00:00:03
Runs = 100000 of 100000
Event Occurred 99858 times, Rate =0.99858, MeanTime = 27.05:49:05 +/- 45.20:50:33.44
Event Occurred 99858 times, Probability =0.99858, MeanTime = 27.05:49:05 +/- 32.10:24:47.87
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cRate95th": 1.0,
"count": 100000,
"timeMean": "12:00:01.3361307",
"timeStdDeviation": "01:25:19.1759728",
"timeStdDeviation": "01:00:19.8070473",
"timeMin": "07:59:10.2038675",
"timeMax": "16:29:06.1663836",
"watchVariables": {},
Expand Down Expand Up @@ -44,7 +44,7 @@
"cRate95th": 1.0,
"count": 100000,
"timeMean": "12:00:01.3361307",
"timeStdDeviation": "01:25:19.1759728",
"timeStdDeviation": "01:00:19.8070473",
"timeMin": "07:59:10.2038675",
"timeMax": "16:29:06.1663836",
"watchVariables": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = DistEvTest1
Runtime = 00.00:00:02
Runtime = 00.00:00:03
Runs = 100000 of 100000
Event Occurred 100000 times, Rate =1, MeanTime = 00.12:00:01 +/- 00.01:25:19.17
Event Occurred 100000 times, Probability =1, MeanTime = 00.12:00:01 +/- 00.01:00:19.80
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cRate95th": 1.0,
"count": 100000,
"timeMean": "12:00:01.3361307",
"timeStdDeviation": "01:25:19.1759728",
"timeStdDeviation": "01:00:19.8070473",
"timeMin": "07:59:10.2038675",
"timeMax": "16:29:06.1663836",
"watchVariables": {},
Expand Down Expand Up @@ -44,7 +44,7 @@
"cRate95th": 1.0,
"count": 100000,
"timeMean": "12:00:01.3361307",
"timeStdDeviation": "01:25:19.1759728",
"timeStdDeviation": "01:00:19.8070473",
"timeMin": "07:59:10.2038675",
"timeMax": "16:29:06.1663836",
"watchVariables": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = DistEvTest1
Runtime = 00.00:00:02
Runs = 100000 of 100000
Event Occurred 100000 times, Rate =1, MeanTime = 00.12:00:01 +/- 00.01:25:19.17
Event Occurred 100000 times, Probability =1, MeanTime = 00.12:00:01 +/- 00.01:00:19.80
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Simulation = EventsTest
Runtime = 00.00:00:00
Runs = 100 of 100
MoveInDetected Occurred 100 times, Rate =1, MeanTime = 00.00:05:00 +/- 00.00:00:00.00
MoveOutDetected Occurred 100 times, Rate =1, MeanTime = 00.00:10:00 +/- 00.00:00:00.00
MoveInDetected Occurred 100 times, Probability =1, MeanTime = 00.00:05:00 +/- 00.00:00:00.00
MoveOutDetected Occurred 100 times, Probability =1, MeanTime = 00.00:10:00 +/- 00.00:00:00.00
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Simulation = ExpDistTest8
Runtime = 00.00:00:03
Runtime = 00.00:00:04
Runs = 100000 of 100000
OverMean Occurred 50119 times, Rate =0.50119, MeanTime = 00.00:10:08 +/- 00.00:08:30.39
UnderFifth Occurred 4989 times, Rate =0.04989, MeanTime = 00.00:00:09 +/- 00.00:00:07.53
OverMean Occurred 50119 times, Probability =0.50119, MeanTime = 00.00:10:08 +/- 00.00:06:00.90
UnderFifth Occurred 4989 times, Probability =0.04989, MeanTime = 00.00:00:09 +/- 00.00:00:05.32
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = TestTimers
Runtime = 00.00:00:00
Runs = 1 of 1
Key Occurred 1 times, Rate =1, MeanTime = 00.00:07:00 +/- 00.00:00:00.00
Key Occurred 1 times, Probability =1, MeanTime = 00.00:07:00 +/- 00.00:00:00.00
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = JsonVarExeTest
Runtime = 00.00:00:03
Runs = 10 of 10
LT Occurred 10 times, Rate =1, MeanTime = 00.00:01:00 +/- 00.00:00:00.00
LT Occurred 10 times, Probability =1, MeanTime = 00.00:01:00 +/- 00.00:00:00.00
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Simulation = NormDistTest
Runtime = 00.00:00:03
Runtime = 00.00:00:04
Runs = 100000 of 100000
AboveMean Occurred 49987 times, Rate =0.49987, MeanTime = 01.00:08:01 +/- 00.00:08:34.71
UnderFifth Occurred 5047 times, Rate =0.05047, MeanTime = 00.23:39:13 +/- 00.00:05:18.46
AboveMean Occurred 49987 times, Probability =0.49987, MeanTime = 01.00:08:01 +/- 00.00:06:03.95
UnderFifth Occurred 5047 times, Probability =0.05047, MeanTime = 00.23:39:13 +/- 00.00:03:45.19
---------------------------
- End Sim Variable Values -
---------------------------
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Simulation = SelfLoopTest
Runtime = 00.00:00:00
Runs = 1 of 1
MadeCnt Occurred 1 times, Rate =1, MeanTime = 00.09:00:00 +/- 00.00:00:00.00
MadeCnt Occurred 1 times, Probability =1, MeanTime = 00.09:00:00 +/- 00.00:00:00.00
- Variable Values -
Run Idx, Int_Cnt
1, 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"cRate95th": 1.0,
"count": 100,
"timeMean": "1.00:04:37.1552042",
"timeStdDeviation": "01:31:31.7523466",
"timeStdDeviation": "01:04:45.3835611",
"timeMin": "21:07:28.2271363",
"timeMax": "1.02:22:27.4269141",
"watchVariables": {
Expand Down Expand Up @@ -454,7 +454,7 @@
"cRate95th": 1.0,
"count": 100,
"timeMean": "1.00:04:37.1552042",
"timeStdDeviation": "01:31:31.7523466",
"timeStdDeviation": "01:04:45.3835611",
"timeMin": "21:07:28.2271363",
"timeMax": "1.02:22:27.4269141",
"watchVariables": {
Expand Down
Loading

0 comments on commit 3762288

Please sign in to comment.