The SIM.JS library provides three utility classes for recording and analyzing statistics: Data Series, Time Series and Population.
Data Series is a collection of discrete, time-independent observations, for example, grades of each student in a class, length of rivers in United States. The DataSeries() class provides a convenient API for recording and analyzing such observations, such as finding maximum and minimum values, statistical properties like average and standard deviation and so on.
Time Series is a collection of discrete time-dependent observations. That is, each observation value is associated with a discrete time instance (the time at which the observation was made). For example, the size of queue at time t during the simulation run, number of customers in a restaurant at time t during evening hours. Note that the time instances when the observations are made are discrete. Also note the difference between Data Series statistics which records time independent statistics. The TimeSeries() class provides a convenient API for recording and analyzing such observations, such as finding maximum and minimum values, statistical properties like time-averaged mean and standard deviation and so on.
Population is actually a composite of the above two statistics, which models the behavior of population growth and decline. Consider a room where people may enter, stay for a while and then leave. The enter event will increase the population count, while the leave will decrease the population count of the room. For this room, we are interested in two statistics:
The Population statistics is used very often to study the behaviors of queues.
Data Series is a collection of discrete, time-independent observations, and the DataSeries() class provides an API for recording and analyzing statistics.
An object of the DataSeries() is created for each observation set:
var studentGrades = new Sim.DataSeries("Student Grades");
var riverLengths = new Sim.DataSeries("Length of Rivers in US");
The observation values are recorded through the record() function. This function optionally takes a weight parameter to adjust the weight of the given observation:
studentGrades.record(3.0); // Alice
riverLengths.record(2320.0); // Mississippi (miles)
experimentData.record(1.5, 0.8); // Value = 1.5, Weight = 0.8
The DataSeries class computes statistical properties of the observation values, including count(), min(), max(), sum(), sumWeighted(), average() (mean), deviation() (standard deviation) and variance(). Data can be recorded as histograms via the setHistogram() function.
An example:
var data = new Sim.DataSeries('Simple Data');
for (var i = 1; i <= 100; i++) {
data.record(i);
}
data.count(); // = 100
data.min(); // = 1.0
data.max(); // = 100.0
data.range(); // = 99.0
data.sum(); // = 5050.0
data.average(); // 50.5
data.deviation(); // = 28.86607004772212
data.variance(); // = 833.25
name is an optional parameter used for identifying the statistics in a report.
Records an observation value and an optional weight. If the weight argument is omitted, it is assigned the default value of 1.0.
Resets the statistics. If a histogram was set earlier with setHistogram(), then the histogram settings (lower bound, upper bound and number of buckets) are retained, but the count for each bucket is reset to 0.
The number of observations recorded so far.
The minimum value from all observations recorded so far.
The maximum value from all the observations recorded so far.
The sum of all observation values recorded so far. Note that this does not consider the weight for the values. See sumWeighted() for weighted sum.
The weighted sum of all observation values recorded so far.
The weighted average of all observation values recorded so far.
The standard deviation of observation values recorded so far.
The variance of the observation values recorded so far.
Prepares a histogram for recording frequency of occurrence of values. The histogram has nbucket number of buckets, spanning the range of [lower, upper].
Only the values that are recorded (via the record() function) after the histogram was created will be taken into account. It is therefore recommended that setHistogram is called before recording values.
If a histogram already existed by an earlier call to setHistogram, that previous histogram will be deleted. Also, as noted above, only the recorded values from this point on will be entered in the new histogram.
When the statistic is reset (via the reset() function), the DataSeries object will remember the histogram structure (the lower, upper and nbuckets values) but the values themselves will be reset to 0. That is, there is no need to call setHistogram after the reset function is called.
Return the histogram as an array. The size of the array will be (nbuckets + 2). The index 0 of the array counts the number of observations that were below the lower value (as defined in setHistogram()), the last index of the array counts the number of observations that were greater than the upper value.
Note
The returned array should be treated as read-only.
Time Series is a collection of discrete, time-dependent observations, and the TimeSeries() class provides an API for recording and analyzing statistics.
An object of the TimeSeries() class is created for each observation set:
var queueSize = new Sim.TimeSeries("Queue Size");
var customers = new Sim.TimeSeries("Customers at Restaurant");
The observation values are recorded through the record() function. Each observation is a combination of (a) the value to record, and (b) the time when the observation was made. For example,
queueSize.record(0, 0); // size is 0 at 0 sec
queueSize.record(1, 1.5); // size is 1 at 1.4 sec
queueSize.record(2, 1.8); // size is 2 at 1.8 sec
customer.record(15, 1800); // 15 customers at 6 pm
customer.record(50, 2100); // 50 customers at 9 pm
customer.record(5, 2315); // 5 customers at 11:15 pm
Few notes on the semantics of observations: when an observation (v1, t1) is recorded, it means that the value of the system is v1, starting at time t1, and will remain so until the next observation is recorded.
For the customer example above, the observation will look like this:
The three circles represent the three observations recorded. Note how the observations are discrete with respect to time.
Also observe that (v1, t1) record will not be “committed” until a next observation (v2, t2) is made (since only then we will know that the value v1 was applicable for the duration t1 - t2). The finalize() function can be used to commit the last observation.
The TimeSeries class computes statistical properties of the observation values, including count(), min(), max(), sum(), average() (mean), deviation() (standard deviation) and variance(). Data can be recorded as histograms via the setHistogram() function.
Note that the average, deviation and variance statistics are averaged over time.
name is an optional parameter used for identifying the statistics in a report.
Records an observation value made at time timestamp.
Call this function after the last observation was recorded.
Resets the statistics. If a histogram was set earlier with setHistogram(), then the histogram settings (lower bound, upper bound and number of buckets) are retained, but the count for each bucket is reset to 0.
The number of observations recorded so far.
The minimum value from all observations recorded so far.
The maximum value from all the observations recorded so far.
The sum of all observation values recorded so far.
The time average of all observation values recorded so far.
The standard deviation of observation values recorded so far.
The variance of the observation values recorded so far.
Prepares a histogram for recording frequency of occurrence of values. The histogram has nbucket number of buckets, spanning the range of [lower, upper].
Only the values that are recorded (via the record() function) after the histogram was created will be taken into account. It is therefore recommended that setHistogram is called before recording values.
If a histogram already existed by an earlier call to setHistogram, that previous histogram will be deleted. Also, as noted above, only the recorded values from this point on will be entered in the new histogram.
When the statistic is reset (via the reset() function), the DataSeries object will remember the histogram structure (the lower, upper and nbuckets values) but the values themselves will be reset to 0. That is, there is no need to call setHistogram after the reset function is called.
Return the histogram as an array. The size of the array will be (nbuckets + 2). The index 0 of the array counts the number of observations that were below the lower value (as defined in setHistogram()), the last index of the array counts the number of observations that were greater than the upper value.
Note
The returned array should be treated as read-only.
Population models the behavior of population growth and decline. This class supports two basic operations:
Population itself is a composite of two statistics:
Consider the following example:
var motel0 = new Sim.Population("Motel 0");
motel0.enter(1600); // one person entered at 4:00 pm
motel0:enter(1600); // second person entered at 4:00 pm
motel0.leave(1600, 1601); // one person who entered at 4:00 pm, left at 4:01 pm
motel0.enter(1630); // another person entered at 4:30 pm
motel0.leave(1630, 1700); // person who entered at 4:30 pm left at 5:00 pm
motel0.finalize(1700); // No more observations after this
motel0.current(); // current population = 1
motel0.sizeSeries.average(); // average population in motel
motel0.durationSeries.average(); // average stay duration in motel
name is an optional parameter used for identifying the statistics in a report.
A statistic of Sim.TimeSeries() type that records the size of the population of the system. Refer to Time Series for the APIs for this attribute.
A statistic of Sim.DataSeries() type that records the stay duration of the entities. Refer to Data Series for the APIs for this attribute.
The current population of the system.
An entity has entered the system at timestamp.
An entity that entered the system at enteredAt will leave at leaveAt.
Call this function after the last observation was recorded.
Resets the statistics.