@@ -109,10 +109,51 @@ var y = dist.logpdf( 0.8 );
109
109
<!-- eslint no-undef: "error" -->
110
110
111
111
``` javascript
112
- var objectKeys = require ( ' @stdlib/utils/keys' );
112
+ var Float64Array = require ( ' @stdlib/array/float64' );
113
+ var randomExponential = require ( ' @stdlib/random/array/exponential' );
114
+ var dcusum = require ( ' @stdlib/blas/ext/base/dcusum' );
113
115
var exponential = require ( ' @stdlib/stats/base/dists/exponential' );
114
116
115
- console .log ( objectKeys ( exponential ) );
117
+ // Simulate interarrival times of customers entering a store:
118
+ var lambda = 0.5 ; // Average rate (customers per minute)
119
+ var numCustomers = 10 ;
120
+
121
+ // Generate interarrival times using the exponential distribution:
122
+ var interarrivalTimes = randomExponential ( numCustomers, lambda, {
123
+ ' dtype' : ' float64'
124
+ });
125
+
126
+ console .log ( ' Simulated interarrival times for ' + numCustomers + ' customers:' );
127
+ console .log ( interarrivalTimes );
128
+
129
+ // Calculate cumulative arrival times by computing the cumulative sum of interarrival times:
130
+ var arrivalTimes = new Float64Array ( interarrivalTimes .length );
131
+ dcusum ( interarrivalTimes .length , 0.0 , interarrivalTimes, 1 , arrivalTimes, 1 );
132
+
133
+ console .log ( ' \n Customer arrival times:' );
134
+ console .log ( arrivalTimes );
135
+
136
+ // Probability that a customer arrives within two minutes:
137
+ var x = 2.0 ;
138
+ var prob = exponential .cdf ( x, lambda );
139
+ console .log ( ' \n Probability that a customer arrives within ' + x + ' minutes: ' + prob .toFixed (4 ) );
140
+
141
+ // Expected time until the next customer arrives:
142
+ var mean = exponential .mean ( lambda );
143
+ console .log ( ' Expected interarrival time: ' + mean + ' minutes' );
144
+
145
+ var dist = new exponential.Exponential ( lambda );
146
+
147
+ var median = dist .median ;
148
+ console .log ( ' Median interarrival time: ' + median + ' minutes' );
149
+
150
+ // Evaluate the PDF at x = 1.0:
151
+ var out = dist .pdf ( 1.0 );
152
+ console .log ( ' PDF at x = 1: ' + out .toFixed (4 ) );
153
+
154
+ // Evaluate the MGF at t = 0.1:
155
+ out = dist .mgf ( 0.1 );
156
+ console .log ( ' MGF at t = 0.5: ' + out .toFixed (4 ) );
116
157
```
117
158
118
159
</section >
0 commit comments