# Systems Engineering Wiki (http://seweb.se.wtb.tue.nl)

## CookBook

cookbook:ept:mmept

– Chi file to calculate EPT's from a list of events –

This file is able to calculate the average EPT and its coefficient of variation using algorithm MM developed by Johan Jacobs. It is used in the python script that can be found in EPT.

```from standardlib import *

type event = (real,string,nat)

proc G(chan a!: event, z!: void) =
|[ var r: real, s: string, n: nat
:: *( ??r; ??s
; ( s = "A" or s = "D" -> ??n; a!(r,s,n)
| s = "Q"            -> z! ; delay 1
)
)
]|

proc EPT(chan a?: event, b!: real) =
|[ var n: nat = 0
, nv: 2 * nat = <0,0>, sv: 2 * real = <0.0,0.0>
, ts: [real] = []
, t: real, ad: string, i: nat
, p,q: bool
; ( ad = "A" -> p:= n < 2; q:= nv.i = 0
; (     p and     q -> ts:= ts ++ [ t ]; sv.i:= hd(ts); ts:= tl(ts)
|     p and not q -> ts:= ts ++ [ t ]
| not p and     q -> sv.i:= hd(ts); ts:= tl(ts)
| not p and not q -> skip
)
; n:= n + 1; nv.i:= nv.i + 1
| ad = "D" -> b!t - sv.i
; n:= n - 1; nv.i:= nv.i - 1
; p:= n < 2; q:= nv.i = 0
; (     p and     q -> skip
|     p and not q -> sv.i:= hd(ts); ts:= tl(ts)
| not p and     q -> ts:= ts ++ [ t ]
| not p and not q -> sv.i:= t
)
)
)
]|

proc STAT(chan a?: real, z?: void)=
|[ var i: nat = 0, ept: real, eptmean: real = 0.0
, eptvar, cv: real
:: *(a?ept; i:= i + 1
; ( i <= 1 -> eptvar:= 0.0
| i >  1 -> eptvar:= eptvar * (i - 2) / (i - 1) + (1 / i) * (ept - eptmean)^2
)
; eptmean:= (eptmean * (i - 1) + ept) /i
| z?; cv:= sqrt(eptvar)/eptmean; !!eptmean, "\t", cv, "\n"; eptmean:= -1.0; delay eptmean
)
]|

model S() =
|[ chan a: event, b: real, z: void
:: G(a,z) || EPT(a,b) || STAT(b,z)
]|
```
cookbook/ept/mmept.txt · Last modified: Thursday, 16 November 2006 : 10:56:03 (external edit)