-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20180527-imse865advsim-prj4-stat-dchristensen-3-2.py
691 lines (578 loc) · 22.6 KB
/
20180527-imse865advsim-prj4-stat-dchristensen-3-2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 05 15:21:44 2017
@author: Derek Christensen
"""
from __future__ import print_function
from __future__ import division
#import random
import math
import scipy.stats as stats
import inspect
def lineno():
"""Returns the current line number in our program."""
return(inspect.currentframe().f_back.f_lineno)
######################################
### INTER-ARRIVAL TIME DIST. FUNCTIONS
######################################
### inter-arriavel time determination
def arrtime(tnow):
arrmean = 3 #avg time b/t arr in hrs - i.e. 3 hrs b/t arr = 180 min
arrlambda = 1/arrmean #arr RATE per hr
# 1/3 of a unit will arrive per hr
funcrand = arrgetrand(arrlambda) #time till next arr in addittional hrs
funcrandmin = funcrand * 60 #time till next arr in additional min
# print('arr funcrandmin =', funcrandmin)
nextarr = tnow + funcrandmin #system clock time calc for next arrival
# print('nextarr =', nextarr)
# print()
return(nextarr) #returns system clock time for next arrival
### calculates time till next arrival in hours
### random number convertor from Uniform into Function
def arrgetrand(arrlambda):
arr364x2rand = 4 * (arrlcg())**(1/3) #convert Uni to 364x2
return (arr364x2rand) #returns time till next arr in additional hours
### Inter-arrival time dist Linear Congruential Generator (LCG)
def arrlcg():
a = 100801 #the multiplier
c = 103319 #the increment
m = 193723 #the modulus
global curarrseed #current Z value (seed)
curarrseed = (a*curarrseed + c) % m #calcualtion of next arr Z value
arrlcgnum = curarrseed / m #calculation of Uniform value
return(arrlcgnum) #Uniform value returned to distribution converter
################################
### SERVICE TIME DIST. FUNCTIONS
################################
### service time determination
def deptime(tnow):
depmean = 2 #avg service time in hrs - i.e. 2 hrs to service = 120 min
depsigma = 0.25
# depmu = 1/depmean #service RATE per hr
# 1/2 of a unit will be served per hr
depmu = depmean
normrand = depgetrand(depmu, depsigma) #time for next serv in add hrs
normrandmin = normrand * 60 #time for necxt service in additional min
# print('dept normrandmin =', normrandmin)
normrandmin_ar.append(normrandmin)
# print('tnow = ', tnow)
nextdep = tnow + normrandmin #system clock time calc for next departure
# print('nextdep =', nextdep)
# print()
return(nextdep) #returns system clock time for next departure
### calculates time till next departure in hours
### random number convertor from Uniform into Normal
def depgetrand(depmu, depsigma):
# depnormrand = -math.log(1.0 - deplcg()) / depmu #convert Uni to Norm
u1 = 0
u2 = 0
w = 0
# deplcg(u1, u2)
u1, u2 = deplcg()
v1 = (2*u1) - 1
v2 = (2*u2) - 1
w = v1**2 + v2**2
# print('u1 = ', u1)
# print('u2 = ', u2)
# print('v1 = ', v1)
# print('v2 = ', v2)
# print('w = ', w)
if w > 1:
# print('bad w = ', w)
return depgetrand(depmu, depsigma) #recursive call
Y = math.sqrt( (-2) * ( ( math.log(w) ) / w ) )
X1 = v1*Y
# X2 = v2*Y
depnormrand1 = depmu + depsigma*X1
# print('Y = ', Y)
# print('X1 = ', X1)
# print('depmu = ', depmu)
# print('depsigma = ', depsigma)
# print('depnormrand1 = ', depnormrand1)
# print('depnormrand1 * 60 = ', depnormrand1*60)
# print()
# depnormrand2 = depmu + depsigma*X2
return (depnormrand1) #returns time till next dep in additional hours
### Service time dist Linear Congruential Generator (LCG)
#def deplcg(u1, u2):
def deplcg():
global curdepseed #current Z value (seed)
a = 7000313 #the multiplier
c = 0 #the increment
m = 9004091 #the modulus
u1 = curdepseed / m #calculation of Uniform value #1
# print('curdepseed = ', curdepseed)
curdepseed = (a*curdepseed + c) % m #calcualtion of next dep Z value
# print('new curdepseed = ', curdepseed)
origdepseed_ar.append(curdepseed)
u2 = curdepseed / m #calculation of Uniform value #2
return(u1, u2) #Uniform value returned to distribution converter
######
# main
######
#if __name__ == '__main__':
# print('line number ', lineno())
avgqtimeary = []
avgsystimeary = []
avgqlenary = []
avgutilary = []
global origarrseed
global origdepseed
origarrseed = 50001
origdepseed = 94907
origdepseed_ar = []
origdepseed_ar.append(origdepseed)
global curarrseed #current seed for inter-arrival dist.
global curdepseed #current seed for service time dist.
curarrseed = 50001 #inital Z(0) seed for inter-arrival dist.
curdepseed = 94907 #inital Z(0) seed for service time dist.
#-------------------------
nextarr_hr_ar = []
#-------------------------
#-------------------------
# nextdep_hr_ar = []
nextdepmin_hr_ar = []
#-------------------------
# normrandmin_ar = []
#33333333333333333333333333333333333
#nextarr_ar = []
nextarrvar_ar = []
nextdep_ar = []
nextdep_ar = []
nextarrvar_ar.append(0)
first_tnow_rep_ar = []
nextarr_dif_ar = []
nextdep_dif_ar = []
#33333333333333333333333333333333333
############
# start reps
############
numreps = 30
for rep in range (0,numreps):
# print()
# print('(---------------rep = ', rep,'--------------)')
hours = 500
tmax = hours * 60 #max time to end program in minutes #9600
told = 0 #the most recent current time in minutes
tnow = 0 #the current time in minutes
util = 0
q = 0
waittime = 0
cumutil = 0
cumsystime = 0
cumarr = 0
avgqtime = 0
avgsystime = 0
avgqlen = 0
avgutil = 0
#-------------------------
nextarr_ar = []
# nextarr_ar.append(0)
nextarr_sum = 0
nextarr_avg = 0
#-------------------------
#-------------------------
# nextdep_ar = []
# nextdep_ar.append(0)
# nextdep_sum = 0
# nextdep_avg = 0
normrandmin_ar = []
nextdepmin_sum = 0
nextdepmin_avg = 0
#-------------------------
nextdep = 1000000000 #set nextdep to a Big M time in minutes
nextarr = arrtime(tnow)
#---------------------------
nextarr_ar.append(nextarr)
#---------------------------
#33333333333333333333333333333333333
nextarrvar_ar.append(nextarr)
# print('nextarrvar_ar = ', nextarr)
first_tnow_rep = 0
cnt = 0
#33333333333333333333333333333333333
while tnow < tmax: #while the current time < max time run while loop
if nextarr < nextdep:
tnow = nextarr
if util == 1:
cumutil = cumutil + (tnow - told)
if q > 0:
waittime = waittime + (q * (tnow - told))
if util == 1:
cumsystime = cumsystime + ((util + q) * (tnow - told))
if tnow == nextarr:
cumarr += 1
if util == 0: #i.e. - if no one is being serviced
util = 1 #since no cur serv & 1 arr -> now serv/util = 1
nextdep = deptime(tnow) #put in serv -> now determine dep
#---------------------------
# nextdep_ar.append(nextdep)
# normrandmin_ar.append(nextdep)
#---------------------------
#33333333333333333333333333333333333
if cnt == 0:
first_tnow_rep = tnow
first_tnow_rep_ar.append(first_tnow_rep)
# print()
# print('tnow = ', tnow)
# print('first_tnow_rep = ', first_tnow_rep)
# print('first_tnow_rep_ar = ', first_tnow_rep_ar)
# print()
nextdep_ar.append(nextdep)
# print('nextdep_ar = ', nextdep)
cnt += 1
#33333333333333333333333333333333333
else: #since util != 0/i.e. someone is in serv, must go into q
q += 1
nextarr = arrtime(tnow)
#---------------------------
nextarr_ar.append(nextarr)
#---------------------------
#33333333333333333333333333333333333
nextarrvar_ar.append(nextarr)
# print('nextarrvar_ar = ', nextarr)
#33333333333333333333333333333333333
told = tnow
else: #since nextarr !< nextdep must run nextdep
tnow = nextdep
if util == 1:
cumutil = cumutil + (tnow - told)
if q > 0:
waittime = waittime + (q * (tnow - told))
if util == 1:
cumsystime = cumsystime + ((util + q) * (tnow - told))
if tnow == nextarr:
cumarr += 1
if q >= 1:
q -= 1
nextdep = deptime(tnow)
#---------------------------
# nextdep_ar.append(nextdep)
# normrandmin_ar.append(nextdep)
#---------------------------
#33333333333333333333333333333333333
if cnt == 0:
first_tnow_rep = tnow
first_tnow_rep_ar.append(first_tnow_rep)
# print()
# print('tnow = ', tnow)
# print('first_tnow_rep = ', first_tnow_rep)
# print('first_tnow_rep_ar = ', first_tnow_rep_ar)
# print()
nextdep_ar.append(nextdep)
# print('nextdep_ar = ', nextdep)
cnt += 1
#33333333333333333333333333333333333
else:
util = 0
nextdep = 1000000000
told = tnow
#------------------------------------------
cumarr -= 1
avgqtime = waittime / cumarr
avgsystime = cumsystime / cumarr
avgqlen = waittime / tnow
avgutil = cumutil / tnow
avgqtimeary.append(avgqtime)
avgsystimeary.append(avgsystime)
avgqlenary.append(avgqlen)
avgutilary.append(avgutil)
#-------------------------------------------
#---------------------------------------
# print()
# print('tnow = ', tnow)
# print('curarrseed = ', curarrseed)
# print('curdepseed = ', curdepseed)
# print()
#---------------------------------------
#--------------------------------------------------
# print('nextarr_ar = ', nextarr_ar)
# print('nextarr_ar length = ', (len(nextarr_ar)-1))
#nextarr_sum = sum(i for i in nextarr_ar)
nextarr_sum = sum([t - s for s, t in zip(nextarr_ar, nextarr_ar[1:])])
nextarr_avg = nextarr_sum / (len(nextarr_ar)-1)
nextarr_hr = 0
nextarr_hr = nextarr_avg / 60
nextarr_hr_ar.append(nextarr_hr)
# print('nextarr_sum = ', nextarr_sum)
# print('nextarr_avg = ', nextarr_avg)
# print('nextarr_hr = ', nextarr_hr)
# print()
#---------------------------------------------------
#--------------------------------------------------
# print('nextdep_ar = ', nextdep_ar)
# print('normrandmin_ar = ', normrandmin_ar)
# print()
# print(*nextdep_ar, sep = '\n')
# print()
# print('nextdep_ar length = ', (len(nextdep_ar)-1))
# print('normrandmin_ar length = ', (len(normrandmin_ar)-1))
#nextarr_sum = sum(i for i in nextarr_ar)
# nextdep_sum = sum([t - s for s, t in zip(nextdep_ar, nextdep_ar[1:])])
# nextdepmin_sum = sum([t - s for s, t in zip(normrandmin_ar, normrandmin_ar[1:])])
nextdepmin_sum = sum(i for i in normrandmin_ar)
# newsumnextdep_ar = 0
# print('newsumnextdep_ar = ', newsumnextdep_ar)
# for i in range(0,len(nextdep_ar)):
# print('nextdep_ar[',i,'] = ', nextdep_ar[i])
# newsumnextdep_ar += nextdep_ar[i]
# print('newsumnextdep_ar = ', newsumnextdep_ar)
# nextdep_avg = nextdep_sum / (len(nextdep_ar)-1)
nextdepmin_avg = nextdepmin_sum / len(normrandmin_ar)
# nextdep_hr = 0
nextdepmin_hr = 0
# nextdep_hr = nextdep_avg / 60
nextdepmin_hr = nextdepmin_avg / 60
# nextdep_hr_ar.append(nextdep_hr)
nextdepmin_hr_ar.append(nextdepmin_hr)
# print('nextdep_sum = ', nextdep_sum)
# print('nextdep_avg = ', nextdep_avg)
# print('nextdep_hr = ', nextdep_hr)
# print()
# print('nextdepmin_sum = ', nextdepmin_sum)
# print('nextdepmin_avg = ', nextdepmin_avg)
# print('nextdepmin_hr = ', nextdepmin_hr)
# print()
#------------------------------------------------------
#---------------------------------------------
#print('#--------------------------------------------')
#print('final tnow = ', tnow)
sumq = 0
sumtime = 0
sumlen = 0
sumutil = 0
for rep in range (0,numreps):
sumq += avgqtimeary[rep]
sumtime += avgsystimeary[rep]
sumlen += avgqlenary[rep]
sumutil += avgutilary[rep]
avgqtimereps = sumq / numreps
avgsystimereps = sumtime / numreps
avgqlenreps = sumlen / numreps
avgutilreps = sumutil / numreps
print()
print('avgutilreps = ', avgutilreps)
print()
#---------------------------------------------
#--------------------------------------------------------------------
#a. Perform a t-Test to determine whether or not there is a statistical
# difference between the simulated data and the expected value
# You can either do this for util or expected number of people in line
# Utilization
# t test stat = xbar - mu / sqrt(s^2/m)
# xbar = avgutilreps
# mu = expected util
# expected util = lambda / mu = arrlambda / depmu
tstat = 0
m = numreps
df = m-1
arrmean = 3 #avg time b/t arr in hrs - i.e. 3 hrs b/t arr = 180 min
arrlambda = 1/arrmean #arr RATE per hr
# 1/3 of a unit will arrive per hr
depmean = 2 #avg service time in hrs - i.e. 2 hrs to service = 120 min
depmu = 1/depmean #service RATE per hr
# 1/2 of a unit will be served per hr
alpha = 0.10 # 1 - Confidence Level
cl = 1 - alpha
q = 1 - alpha/2 #stats.t.ppf parameter
print('CL = ', cl,', ','alpha = ', alpha, ', CI = ', q)
expecutil = arrlambda / depmu #the expected utilization rate
expeclenq = (arrlambda/depmu)**2 / (1 - (arrlambda/depmu)) #E(x) Len Q
print('expecutil = ', expecutil)
#print('expeclenq = ', expeclenq)
# s^2 = sum(mi - xbar)^2 / (m-1)
# s^2 = sum(avgutilary[i] - avgutilreps)^2 / (m-1)
ssqr = 0 #variable for s-squared
for i in range (0, numreps): #sum the sqared diff b/t each mi & xbar
ssqr += (avgutilary[i] - avgutilreps)**2
#print('sssqr = ', ssqr)
ssqr /= (m-1)
#print()
print('sssqr = ', ssqr)
#print()
print('m = ', m)
print('hours = ', hours)
tstat += abs((avgutilreps - expecutil) / (ssqr/m)**0.5) #Calculate T-Stat
print('tstat = ', tstat)
t_critical = stats.t.ppf(q = q, df=df) # Get the t-critical value*
print('t-critical value:') # Check the t-critical value
print(t_critical)
#if tstat < t_critical:
# print('T-Stat < Critical Value, Fail to Reject Null Hypothesis')
#elif t_critical < tstat:
# print('Critical Value < T-Stat, Reject Null Hypothesis')
#else:
# print('T-Stat = Critical Value')
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#####################
# CONFIDENCE INTERVAL
#####################
#CI: (xbarmod - xbarsys) +- (T(m-1,1 - alpha/2) * SQRT(ssqr/m))
# xbarmod = avgutilreps
# xbarsys = expecutil
# T(m-1,1 - alpha/2) = t_critical
# SQRT(ssqr/m) = math.sqrt(ssrq/m)
LB = 0 #lower CI
UB = 0 #upper CI
LB = (avgutilreps - expecutil) - (t_critical * math.sqrt(ssqr/m))
UB = (avgutilreps - expecutil) + (t_critical * math.sqrt(ssqr/m))
print('CI LB = ', LB)
print('CI UB = ', UB)
print('CI = [',LB,', ',UB,']')
#print('#-------------------------------------------------')
#----------------------------------------------------------------------
#----------------------------------------------------------------------
#####################################
# SUMMARY STATS FOR FUNC & NORM DISTS
#####################################
#---------------------------------------------------
nextarr_hr_ar_avg = sum(i for i in nextarr_hr_ar) / len(nextarr_hr_ar)
#nextarr_sum = sum(i for i in nextarr_ar)
# print('nextarr_hr_ar = ', nextarr_hr_ar)
## print(nextarr_hr_ar)
# print()
#print('nextarr_hr_ar = ', nextarr_hr_ar)
#print('nextarr_hr_ar_avg = ', nextarr_hr_ar_avg)
#print()
#---------------------------------------------------
#------------------------------------------------------------
# nextdep_hr_ar_avg = sum(i for i in nextdep_hr_ar) / len(nextdep_hr_ar)
#nextdep_sum = sum(i for i in nextdep_ar)
nextdepmin_hr_ar_avg = sum(i for i in nextdepmin_hr_ar) / len(nextdepmin_hr_ar)
#nextdepmin_sum = sum(i for i in nextdep_ar)
# print('nextdep_hr_ar = ', nextdep_hr_ar)
# print('nextdep_hr_ar_avg = ', nextdep_hr_ar_avg)
# print()
#print('nextdepmin_hr_ar = ', nextdepmin_hr_ar)
#print('nextdepmin_hr_ar_avg = ', nextdepmin_hr_ar_avg)
#print()
# print()
# print('normrandmin_ar = ', normrandmin_ar)
# print()
# print(*normrandmin_ar, sep = '\n')
# print()
#--------------------------------------------------------------
#333333333333333333333333333333333333333333333333333333333333333333
nextarr_dif = 0
nextdep_dif = 0
nextarr_ar_sum = 0
nextarr_ar_len = len(nextarrvar_ar)
#print('nextarr_sum_len = ', nextarr_ar_len)
for i in range (1, nextarr_ar_len):
if nextarrvar_ar[i] > nextarrvar_ar[i-1]:
nextarr_dif = nextarrvar_ar[i] - nextarrvar_ar[i-1]
nextarr_ar_sum += nextarr_dif
nextarr_dif_ar.append(nextarr_dif)
# print('nextarr_ar_sum = ', nextarr_ar_sum)
elif nextarrvar_ar[i] < nextarrvar_ar[i-1]:
nextarr_dif = nextarrvar_ar[i] - 0
nextarr_ar_sum += nextarr_dif
nextarr_dif_ar.append(nextarr_dif)
# print('(-----------NEXT REP---------------)')
# print('nextarr_ar_sum = ', nextarr_ar_sum)
# print()
else:
nextarr_dif = 0
nextarr_ar_sum += nextarr_dif
nextarr_dif_ar.append(nextarr_dif)
# print('nextarr_ar_sum = ', nextarr_ar_sum)
#print()
#print('nextarr_ar_sum = ', nextarr_ar_sum)
#print()
nextdep_ar_sum = 0
nextdep_ar_len = len(nextdep_ar)
#print('nextdep_ar_len = ', nextdep_ar_len)
#
#print()
#print('first_tnow_rep_ar = ', first_tnow_rep_ar)
#print()
#333333333333333333333333333333333333333333333333333333333333333333
#333333333333333333333333333333333333333333333333333333333333333333
jcnt = 0
for i in range (0, nextdep_ar_len):
if i == 0:
nextdep_dif = nextdep_ar[i] - first_tnow_rep_ar[jcnt]
nextdep_ar_sum += nextdep_ar[i] - first_tnow_rep_ar[jcnt]
nextdep_dif_ar.append(nextdep_dif)
# print('nextdep_ar_sum = ', nextdep_ar_sum)
jcnt += 1
elif nextdep_ar[i] > nextdep_ar[i-1]:
nextdep_dif = nextdep_ar[i] - nextdep_ar[i-1]
nextdep_ar_sum += nextdep_dif
nextdep_dif_ar.append(nextdep_dif)
# print('nextdep_ar_sum = ', nextdep_ar_sum)
elif nextdep_ar[i] < nextdep_ar[i-1]:
# print()
# print('jcnt = ', jcnt)
# print('first_tnow_rep_ar[jcnt] = ', first_tnow_rep_ar[jcnt])
nextdep_dif = nextdep_ar[i] - first_tnow_rep_ar[jcnt]
nextdep_ar_sum += nextdep_dif
nextdep_dif_ar.append(nextdep_dif)
# print('nextdep_ar_sum = ', nextdep_ar_sum)
jcnt += 1
else:
nextdep_dif = 0
nextdep_ar_sum += nextdep_dif
nextdep_dif_ar.append(nextdep_dif)
# print('nextdep_ar_sum = ', nextdep_ar_sum)
#333333333333333333333333333333333333333333333333333333333333333333
#333333333333333333333333333333333333333333333333333333333333333333
#print('nextdep_ar_sum = ', nextdep_ar_sum)
#print()
#
#print('nextarrvar_ar = ', nextarrvar_ar)
#print()
#print(*nextarrvar_ar, sep = '\n')
#print()
#
#print('nextdep_ar = ', nextdep_ar)
#print()
#print(*nextdep_ar, sep = '\n')
#print()
#
#print('nextarr_dif_ar = ', nextarr_dif_ar)
#print()
#print('nextdep_dif_ar = ', nextdep_dif_ar)
#print()
nextarr_dif_ar_len = len(nextarr_dif_ar)
print('nextarr_dif_ar_len = ', nextarr_dif_ar_len)
#print()
nextdep_dif_ar_len = len(nextdep_dif_ar)
print('nextdep_dif_ar_len = ', nextdep_dif_ar_len)
print()
nextarr_dif_ar_sum = sum(i for i in nextarr_dif_ar)
nextdep_dif_ar_sum = sum(i for i in nextdep_dif_ar)
print('nextarr_dif_ar_sum = ', nextarr_dif_ar_sum)
print('nextdep_dif_ar_sum) = ', nextdep_dif_ar_sum)
print()
nextarr_dif_ar_avg = nextarr_dif_ar_sum / nextarr_dif_ar_len
nextdep_dif_ar_avg = nextdep_dif_ar_sum / nextdep_dif_ar_len
print('nextarr_dif_ar_avg = ', nextarr_dif_ar_avg)
print('nextdep_dif_ar_avg) = ', nextdep_dif_ar_avg)
print()
#333333333333333333333333333333333333333333333333333333333333333333
#333333333333333333333333333333333333333333333333333333333333333333
nextarr_dif_ar_diffsq_ar = []
nextdep_dif_ar_diffsq_ar = []
for i in range(0, nextarr_dif_ar_len):
nextarr_dif_ar_diffsq = (nextarr_dif_ar[i] - nextarr_dif_ar_avg)**2
nextarr_dif_ar_diffsq_ar.append(nextarr_dif_ar_diffsq)
for i in range(0, nextdep_dif_ar_len):
nextdep_dif_ar_diffsq = (nextdep_dif_ar[i] - nextdep_dif_ar_avg)**2
nextdep_dif_ar_diffsq_ar.append(nextdep_dif_ar_diffsq)
nextarr_dif_ar_diffsq_ar_sum = sum(i for i in nextarr_dif_ar_diffsq_ar)
nextdep_dif_ar_diffsq_ar_sum = sum(i for i in nextdep_dif_ar_diffsq_ar)
print('nextarr_dif_ar_diffsq_ar_sum = ', nextarr_dif_ar_diffsq_ar_sum)
print('nextdep_dif_ar_diffsq_ar_sum = ', nextdep_dif_ar_diffsq_ar_sum)
print()
vararr = nextarr_dif_ar_diffsq_ar_sum / (len(nextarr_dif_ar_diffsq_ar)-1)
vardep = nextdep_dif_ar_diffsq_ar_sum / (len(nextdep_dif_ar_diffsq_ar)-1)
print('vararr = ', vararr)
print('vardep = ', vardep)
print()
#333333333333333333333333333333333333333333333333333333333333333333
#print('########################')
#print('###### END PROGRAM #####')
#print('########################')
#print()