Issue with Lognormal distribution

166 views
Skip to first unread message

Karim Van den broek

unread,
Jan 5, 2024, 8:02:41 AM1/5/24
to JaamSim Users Discussion Group
Dear Harry, 

First, thank you for including the location parameter in the Lognormal, Loglogistic and Beta distribution in the newest Jaamsim version. 

Despite the integration of the location parameter in the system, I'm still encountering a problem with the lognormal distribution. If I use SciPy to obtain the mu and sigma for the underlying normal distribution I obtain the following params: mu = 4,24; sigma (s) = 0.219 and location = 0.21 (min)). To verify the outcome of this fitting procedure I randomly generated 16000 datapoints and plotted these in a histogram as shown in the included screenshot, thereby verifying the fitting outcome. 

However, if I test the duration of the distribution with a simple simulation in Jaamsim using an entity generator, queue, entity processor and entity sink, over a period of a year (8760 hours), the number added by the entitysink is 372469, indicating a production capacity of approximately 42.5 units per hour, which is highly inaccurate. My question is how should I fix this problem to prevent it from happening?

The obtained parameters are already for the underlying normal distribution and Python does generate correct outcomes. 

Best regards, 

Karim 

Capture_1.PNG

Harry King

unread,
Jan 18, 2024, 9:38:39 PM1/18/24
to JaamSim Users Discussion Group
Karim,

Please post a simple example model with the inputs you are using for the LogNormalDistribution. Show in the post how you calculated the inputs from the SciPy values.

Harry

Karim Van den broek

unread,
Jan 31, 2024, 5:18:27 AM1/31/24
to JaamSim Users Discussion Group
Dear Harry, 

An example would be the calculated python outcomes using the following function. For confidentiality  reasons, I cannot share the full code: loc = 0.21401309307042476, Mu = 4.2443968903613944, Sigma = 0.21896308539130055

def plot_lognormal(data, size=500):
    # Fit the lognormal distribution and get parameters
    shape, loc, scale = stats.lognorm.fit(data)
    mu = np.log(scale)
    sigma = shape

    return loc, mu, sigma

Filling in the values as follows to the lognormal distribution in JaamSim:
location = loc 
NormalMean = Mu
NormalStandardDeviation = Sigma

We obtain very low processing time values that seem unrealistic and don't align with our data. 

Best, 

Karim 


Op vrijdag 19 januari 2024 om 03:38:39 UTC+1 schreef d.harr...@gmail.com:

Harry King

unread,
Jan 31, 2024, 3:49:39 PM1/31/24
to JaamSim Users Discussion Group
Karim,

You need to give me enough information to check your result. I need the following:
  1. The values for the SciPy lognormal parameters: s, loc, and scale that you fitted to your data set
  2. The values for the mean and standard deviation that SciPy calculates for the fitted distribution
  3. The values for the JaamSim inputs Location, Scale, NormalMean, and NormalStandardDeviation that you are using
You can do one test yourself by comparing the JaamSim outputs for CalculatedMean and CalculatedStandardDeviation to the values from SciPy in (2) above. They should be exactly equal.

The last step is to build a JaamSim model that samples the LogNormalDistribution a few million times and check that the SampleMean and the SampleStandardDeviation outputs are close to the CalculatedMean and CalculatedStandardDeviation values.

The following image shows the results for this test model using the LogNormalDistribution inputs you provide. After about 5 million samples, the values for SampleMean and the SampleStandardDeviation outputs are very close to those for CalculatedMean and CalculatedStandardDeviation. The input file for this model is attached.

LogNormal Test.png

Harry

LogNormal Test.cfg

Karim Van den broek

unread,
Feb 1, 2024, 4:18:23 AM2/1/24
to JaamSim Users Discussion Group
Dear Harry, 

Thank you for your rapid response. 

1) The SciPy fitted values are s = 0.21896308539130055 ; 
loc = 0.21401309307042476 (min);
scale = 69.71370245658527 

2) The SciPy calculated:
mean = 71.6177570093458 min;
 standard deviation = 15.829446730132336 min

3) JaamSim values used: 
 Location = 0.21401309307042476 (min);
Scale = 69.71370245658527;
NormalMean = 4.2443968903613944;
NormalStandardDeviation = 0.21896308539130055

Filling in these values, I obtained the same output you did. However, the problem is encountered when I want to convert to TimeUnit instead of dimensionless units. In that case, the outputs are as follows; 

Output 1.PNG

I know it's technically possible to just use the distribution with a dimensionless Unittype and use [LogNormalDistribution].value [min] to convert it to a time unit in the service time of entity processors. However, given the size of my simulation, this would be highly inefficient. 

Best, 

Karim




Op woensdag 31 januari 2024 om 21:49:39 UTC+1 schreef d.harr...@gmail.com:

Harry King

unread,
Feb 1, 2024, 2:21:57 PM2/1/24
to JaamSim Users Discussion Group
HI Karim,

Okay, now we are getting somewhere.

The problem is that you have set the Scale input to 69.71370245658527, when it should have been left at 1.0. If you use the Units button to set the TimeUnit to minutes, you will see the the values in the Output Viewer are different from the ones that I showed in my previous post.

The Scale input for the LogNormalDistribution is used only to select the units in which the distribution returns its values. In your case, since your values are in minutes, the Scale input should be set to  1.0 min. The full set on inputs are shown below:

Picture1.png

When these inputs are used in the example model, the output values are as follows:

Picture2.png

Note the values for the SampleMean and SampleStandardDeviation outputs are consistent with the values calculated by SimPy in item (2) of your last post.

Harry

Karim Van den broek

unread,
Feb 2, 2024, 12:01:22 PM2/2/24
to JaamSim Users Discussion Group
Dear Harry, 

I see, thank you for your answer!

Op donderdag 1 februari 2024 om 20:21:57 UTC+1 schreef d.harr...@gmail.com:
Reply all
Reply to author
Forward
0 new messages