def main(args):
e = Eligibility(length=args.length)
if args.mode == "dexp":
e.efunc_ = e.efunc_double_exp
elif args.mode == "rect":
e.efunc_ = e.efunc_rect
elif args.mode == "ramp":
e.efunc_ = e.efunc_ramp
elif args.mode == "exp":
e.efunc_ = e.efunc_exp
e.gen_efunc_table()
x = np.arange(args.length)
print x
et = e.efunc(x)
# plot and test with array argument
cmstr = "ko"
pl.plot(x, et, cmstr, lw=1.)
if args.mode == "rect":
# negative time for readability without lines
pl.plot(np.arange(-5, x[0]), np.zeros(5,), cmstr, lw=1.)
# pl.plot([-10, -1, x[0]], [0, 0, et[0]], cmstr, lw=1.)
pl.plot([x[-1], x[0] + args.length], [et[-1], 0.], cmstr, lw=1.)
pl.plot(x + args.length, np.zeros((len(et))), cmstr, lw=1.)
pl.ylim((-0.005, np.max(et) * 1.1))
# pl.plot(x, et, "k-", lw=1.)
# pl.yticks([])
# line at zero
# pl.axhline(0., c="black")
pl.xlabel("t [steps]")
pl.ylabel("Eligibility")
if args.plotsave:
pl.gcf().set_size_inches((6, 2))
pl.gcf().savefig("eligibility_window.pdf", dpi=300, bbox_inches="tight")
pl.show()
# check perf: loop, test with single integer arguments
import time
now = time.time()
for i in range(100):
for j in range(args.length):
e.efunc(j)
print "table took:", time.time() - now
now = time.time()
for i in range(100):
for j in range(args.length):
e.efunc_(j)
print "feval took:", time.time() - now
评论列表
文章目录