Community

I would like to compute the mean queue length over the last 5 time units ( I am modeling a non-stationary system). For this I wanted to use the method StatisticsContinuous.mean( t ). From the API documentation, I thought this would give me the mean at any earlier time in my simulation. By comparing the mean as computed 5 time units ago with the current mean, I can then have the mean over the last 5 minutes. Unfortunately when I call the method with a time earlier than the current time I get an error such as : java.lang.RuntimeException: StatisticsContinuous: The given time is smaller than the time of last update: 5 < 9.994 (this happens at time 10) Is this normal? Is there any other way to compute the mean queue length over the last x time units? Thank you very much for any help! Philippe
Hello, Philippe! Such behavior of [StatisticsContinuous.mean(t)] is normal. The value of the parameter [t] must be greater or equal to the time of the last update (last sample). API Reference says: [StatisticsContinuous.mean(t)] Returns the mean of the statistics at the given time assuming the last value added holds until the given time, or 0 if no samples have been added. The mean is calculated as integral of observed value divided to the difference between times of last and first samples. [StatisticsContinuous.mean(t)] adds (t - timeOfLastSample) * valueOfLastSample to the integral (numerator) and, respectively, (t - timeOfLastSample) to the denominator. As you can see, there is no sense in [t] being less than time of the last sample. Typical usage of [StatisticsContinuous.mean(t)] is mean(time()), which assumes that the observed variable did not change since the last update. Below is the numeric example (I advise you to draw the time chart on a sheet of paper). Assume your model is running and current model time is 5. In your model you have an instance of [StatisticsContinuous] object, and it has the following samples: (0, 1), (2, 2), (4, 1) (it means that at model time = 0 the observed value was equal to 1, then at time = 2 it changed to 2, and so on...). So, mean() would return (2 * 1 + 2 * 2) / 4 =1.5, mean(5) would return (2 * 1 + 2 * 2 + 1 * 1) / 5 = 1.4, mean(10) would return (2 * 1 + 2 * 2 + 6 * 1) / 10 = 1.2. In your case, you can just save mean values at certain moments and then perform any calculations you want. I hope such a long post helped you solve your problem.
Thank you very much! I now understand much better how StatisticsContinuous.mean(t) works, and how to implement what I want.