Skip to content

Commit

Permalink
28 lognormalfix (#29)
Browse files Browse the repository at this point in the history
* Fix calculation of sigma
  • Loading branch information
abeham authored Feb 21, 2020
1 parent 76ec06a commit 01609bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/SimSharp/Core/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -530,8 +529,7 @@ public double RandLogNormal(double mu, double sigma) {
/// <returns>A log-normal distributed random value.</returns>
public double RandLogNormal2(IRandom random, double mean, double stdev) {
if (stdev == 0) return mean;
var alpha = Math.Sqrt(mean * stdev) / mean;
var sigma = Math.Sqrt(Math.Log(1 + (alpha * alpha)));
var sigma = Math.Sqrt(Math.Log(stdev * stdev / (mean * mean) + 1));
var mu = Math.Log(mean) - 0.5 * sigma * sigma;
return Math.Exp(RandNormal(random, mu, sigma));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/EnvironmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void PseudoRealtimeEnvTestStopTest() {
var t = Task.Run(() => env.Run(TimeSpan.FromMinutes(1)));
Task.Delay(TimeSpan.FromMilliseconds(200)).Wait();
env.StopAsync();
Task.Delay(TimeSpan.FromMilliseconds(200)).Wait();
Task.Delay(TimeSpan.FromMilliseconds(500)).Wait();
Assert.True(t.IsCompleted);
}

Expand Down

0 comments on commit 01609bc

Please sign in to comment.