ChronoSheaf-Input-Lag / src /phase_schedule.py
PureOne's picture
Add CHRONO-SHEAF III input latency research dataset
987b273 verified
Raw History Blame Contribute Delete
1.53 kB
"""Exact phase-average capture for a periodically repeated schedule, ideal fixed slots."""
import argparse
import json
def compare(period, shifts, width):
if type(period) is not int or period<=0 or not shifts:
raise ValueError("a positive integer period and a nonempty schedule are required")
if not 0<width<period or any(type(x) is not int or not 0<=x<period for x in shifts):
raise ValueError("width must lie in (0,T), shifts in [0,T)")
a=lambda x:min(width,x)
b=lambda x:max(0,x-(period-width))
static=sum(a(x)-b(x) for x in shifts)
switching=sum(max(0,b(shifts[i-1])-a(x)) for i,x in enumerate(shifts))
lost=sum(max(0,a(x)-b(shifts[i-1])) for i,x in enumerate(shifts))
assert lost==static+switching
scale=len(shifts)*period
return dict(lost_start_measure=lost,total_start_measure=scale,
loss_probability=lost/scale,constant_shift_component=static,
switching_component=switching,mean_persistent_gain=sum(shifts)/len(shifts))
def clustered(period, high, enabled, length, width):
if not 0<=enabled<=length or length<1:
raise ValueError("invalid duty")
shifts=[high]*enabled+[0]*(length-enabled)
return shifts,compare(period,shifts,width)
if __name__=="__main__":
p=argparse.ArgumentParser(description=__doc__);p.add_argument("period",type=int)
p.add_argument("width",type=int);p.add_argument("shifts",nargs="+",type=int)
a=p.parse_args();print(json.dumps(compare(a.period,a.shifts,a.width),indent=2))