def exp5_plot(): datadir = Path("data", "exp5") def get_data(name, label, style=dict()): data = SN() data.alg = fym.logging.load(Path(datadir, name)) data.style = dict(label=label, **style) return data def error_plot(data, estkey, optkey, style=dict()): style = dict(data.style, **style) plt.plot( data.alg["i"], np.sqrt( np.square(data.alg[estkey] - data.alg[optkey]).sum(axis=(1, 2))), **style ) plt.yscale("log") kleinman_style = dict(c="k", ls="--", marker="o", markersize=2) sql_style = dict(c="b", ls="-", marker="o", markersize=2) data_stable = [ get_data(name, label, style) for name, label, style in (["kleinman-stable.h5", "Kleinman (stable)", kleinman_style], ["sql-stable.h5", "SQL (stable)", sql_style])] data_unstable = [ get_data(name, label, style) for name, label, style in (["kleinman-unstable.h5", "Kleinman (unstable)", kleinman_style], ["sql-unstable.h5", "SQL (unstable)", sql_style])] subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 # Figure 1 (stable) figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [error_plot(d, "P", "Popt") for d in data_stable] plt.ylabel(r"${P}$ error") plt.legend() plot.subplot(pos, 1, sharex=ax) [error_plot(d, "K", "Kopt") for d in data_stable] plt.ylabel(r"${K}$ error") plt.legend() plt.xlabel("Iteration") # Figure 2 (unstable) figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [error_plot(d, "P", "Popt") for d in data_unstable] plt.ylabel(r"${P}$ error") plt.legend() plot.subplot(pos, 1, sharex=ax) [error_plot(d, "K", "Kopt") for d in data_unstable] plt.ylabel(r"${K}$ error") plt.legend() plt.xlabel("Iteration") # Save imgdir = Path("img", datadir.relative_to("data")) imgdir.mkdir(exist_ok=True) plt.figure(1) plt.savefig(Path(imgdir, "figure_1.pdf"), bbox_inches="tight") plt.figure(2) plt.savefig(Path(imgdir, "figure_2.pdf"), bbox_inches="tight") plt.show()
def exp1_plot(): def get_data(datadir): data = SN() env, info = fym.logging.load(list(datadir.glob("*env.h5"))[0], with_info=True) data.env = env data.info = info agentlist = list(datadir.glob("*agent.h5")) if agentlist != []: data.agent = fym.logging.load(agentlist[0]) data.style = dict(label=info["cfg"].label) return data plt.rc("font", family="Times New Roman") plt.rc("text", usetex=True) plt.rc("lines", linewidth=1) plt.rc("axes", grid=True) plt.rc("grid", linestyle="--", alpha=0.8) datadir = Path("data", "exp1") mrac = get_data(Path(datadir, "data00")) hmrac = get_data(Path(datadir, "data01")) data = [mrac, hmrac] basestyle = dict(c="k", lw=0.7) cmdstyle = dict(basestyle, c="r", ls="--", label="Command") mrac.style.update(basestyle, c="g", ls="-") hmrac.style.update(basestyle, c="k", ls="-") # Figure common setup t_range = (0, 50) # All in inches subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 # ================= # States and inputs # ================= figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(311, position=pos[0]) lines = [] lines += plt.plot(mrac.env["t"], mrac.env["c"][:, 0], **cmdstyle) lines += [plot.states_and_input(d, "x", 0)[0] for d in data] plt.ylabel(r"$x_1$") plt.ylim(-2, 2) plt.figlegend( lines, [line.get_label() for line in lines], bbox_to_anchor=(0.99, 0.78) ) plt.subplot(312, sharex=ax, position=pos[1]) [plot.states_and_input(d, "x", 1) for d in data] plt.ylabel(r"$x_2$") plt.ylim(-2, 2) plt.subplot(313, sharex=ax, position=pos[2]) [plot.states_and_input(d, "u", 0) for d in data] plt.ylabel(r'$u$') plt.xlabel("Time, sec") plt.xlim(t_range) plt.ylim(-80, 80) for ax in plt.gcf().get_axes(): ax.label_outer() # ==================== # Parameter estimation # ==================== figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(211, position=pos[0]) # [plot.parameters(d, (0, 1, 8, 9, 10)) for d in data] plot.parameters(mrac) plt.ylabel(r"$W$") # plt.ylim(0, 0.6) plt.legend(loc='best') plt.subplot(212, sharex=ax, position=pos[1]) # [plot.parameters(d, (2, 3, 4, 5, 6, 7)) for d in data] plot.parameters(hmrac) plt.ylabel(r"$W$") plt.legend(loc='best') plt.xlabel("Time, sec") plt.xlim(t_range) # plt.ylim(0, 85) # =============================================== # Tracking and parameter estimation errors (norm) # =============================================== figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(211, position=pos[0]) [plot.tracking_error(d) for d in data] plt.ylabel(r"$||e||$") plt.ylim(0, 0.2) plt.legend(loc='best') plt.subplot(212, sharex=ax, position=pos[1]) [plot.estimation_error(d) for d in data] plt.ylabel(r"$||\tilde{W}||$") plt.xlabel("Time, sec") plt.xlim(t_range) plt.ylim(0, 85) # ================= # Performance index # ================= figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(211, position=pos[0]) [plot.performance_index(d) for d in data] plt.ylabel(r"J") plt.xlim(t_range) plt.legend(loc="best") plt.subplot(211, sharex=ax, position=pos[1]) [plot.HJB_error(d) for d in data] plt.ylabel(r"$\epsilon_{\mathrm{HJB}}$") plt.xlabel("Time, sec") # Saving # basedir = Path("img") # basedir.mkdir(exist_ok=True) # plt.figure(1) # plt.savefig(Path(basedir, "figure_1.pdf"), bbox_inches="tight") # plt.figure(2) # plt.savefig(Path(basedir, "figure_2.pdf"), bbox_inches="tight") plt.show()
def exp4_plot(): datadir = Path("data", "exp4") zlearner = plot.get_data(Path(datadir, "data00")) qlearner = plot.get_data(Path(datadir, "data01")) zlearner_na = plot.get_data(Path(datadir, "data02")) qlearner_na = plot.get_data(Path(datadir, "data03")) data = [zlearner, qlearner] data_na = [zlearner_na, qlearner_na] basestyle = dict(c="k", lw=0.7) refstyle = dict(basestyle, c="r", ls="--") zstyle = dict(basestyle, c="y", ls="-") qstyle = dict(basestyle, c="b", ls="-.") zlearner.style.update(zstyle) qlearner.style.update(qstyle) zlearner_na.style.update(zstyle) qlearner_na.style.update(qstyle) # Figure common setup cfg = linear.cfg linear.load_config() t_range = (0, cfg.final_time) # All in inches subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 # ================= # States and inputs # ================= figsize, pos = plot.posing(5, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "x", 0)[0] for d in data] plt.ylabel(r"$x_1$") # plt.ylim(-2, 2) plt.legend() plot.subplot(pos, 1, sharex=ax) [plot.vector_by_index(d, "x", 1) for d in data] plt.ylabel(r"$x_2$") # plt.ylim(-2, 2) plot.subplot(pos, 2, sharex=ax) [plot.vector_by_index(d, "u", 0) for d in data] plt.ylabel(r'$u$') # plt.ylim(-80, 80) # ==================== # Parameter estimation # ==================== ax = plot.subplot(pos, 3) plot.all(qlearner, "K", style=dict(refstyle, label="True")) for d in data: plot.all( d, "K", is_agent=True, style=dict(marker="o", markersize=2) ) plt.ylabel(r"$\hat{K}$") plt.legend() # plt.ylim(-70, 30) plot.subplot(pos, 4, sharex=ax) plot.all(qlearner, "P", style=dict(qlearner.style, c="r", ls="--")) for d in data: plot.all( d, "P", is_agent=True, style=dict(marker="o", markersize=2) ) plt.ylabel(r"$\hat{P}$") # plt.ylim(-70, 30) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # ================================== # States and inputs (Non-Admissible) # ================================== figsize, pos = plot.posing(5, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "x", 0)[0] for d in data_na] plt.ylabel(r"$x_1$") # plt.ylim(-2, 2) plt.legend() plot.subplot(pos, 1, sharex=ax) [plot.vector_by_index(d, "x", 1) for d in data_na] plt.ylabel(r"$x_2$") # plt.ylim(-2, 2) plot.subplot(pos, 2, sharex=ax) [plot.vector_by_index(d, "u", 0) for d in data_na] plt.ylabel(r'$u$') # plt.ylim(-80, 80) # ===================================== # Parameter estimation (Non-Admissible) # ===================================== ax = plot.subplot(pos, 3) plot.all(qlearner_na, "K", style=dict(refstyle, label="True")) for d in data_na: plot.all( d, "K", is_agent=True, style=dict(marker="o", markersize=2) ) plt.ylabel(r"$\hat{K}$") plt.legend() # plt.ylim(-70, 30) plot.subplot(pos, 4, sharex=ax) plot.all(qlearner_na, "P", style=refstyle) for d in data_na: plot.all( d, "P", is_agent=True, style=dict(marker="o", markersize=2) ) plt.ylabel(r"$\hat{P}$") # plt.ylim(-70, 30) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() imgdir = Path("img", datadir.relative_to("data")) imgdir.mkdir(exist_ok=True) plt.figure(1) plt.savefig(Path(imgdir, "figure_1.pdf"), bbox_inches="tight") plt.figure(2) plt.savefig(Path(imgdir, "figure_2.pdf"), bbox_inches="tight") plt.show()
def exp3_plot(): def get_data(datadir): data = SN() env, info = fym.logging.load(list(datadir.glob("*env.h5"))[0], with_info=True) data.env = env data.info = info agentlist = list(datadir.glob("*agent.h5")) if agentlist != []: data.agent = fym.logging.load(agentlist[0]) data.style = dict(label=info["cfg"].label) return data plt.rc("font", family="Times New Roman") plt.rc("text", usetex=True) plt.rc("lines", linewidth=1) plt.rc("axes", grid=True) plt.rc("grid", linestyle="--", alpha=0.8) datadir = Path("data", "exp3") mrac = get_data(Path(datadir, "data00")) vlmrac = get_data(Path(datadir, "data01")) data = [mrac, vlmrac] basestyle = dict(c="k", lw=0.7) cmdstyle = dict(basestyle, c="r", ls="--", label="Command") mrac.style.update(basestyle, c="g", ls="-") vlmrac.style.update(basestyle, c="b", ls="-") # Figure common setup cfg = wingrock.cfg wingrock.load_config() t_range = (0, cfg.final_time) # All in inches subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 # ================= # States and inputs # ================= figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(311, position=pos[0]) lines = [] lines += plt.plot(mrac.env["t"], mrac.env["c"][:, 0], **cmdstyle) lines += [plot.states_and_input(d, "x", 0)[0] for d in data] plt.ylabel(r"$x_1$") plt.ylim(-2, 2) plt.figlegend( lines, [line.get_label() for line in lines], bbox_to_anchor=(0.99, 0.78) ) plt.subplot(312, sharex=ax, position=pos[1]) [plot.states_and_input(d, "x", 1) for d in data] plt.ylabel(r"$x_2$") plt.ylim(-2, 2) plt.subplot(313, sharex=ax, position=pos[2]) [plot.states_and_input(d, "u", 0) for d in data] plt.ylabel(r'$u$') plt.ylim(-80, 80) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # ==================== # Parameter estimation # ==================== figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) plot.all(mrac, "Wcirc", style=cmdstyle) plot.all(mrac, "W", style=dict(mrac.style, c="k")) plt.ylim(-70, 30) plot.subplot(pos, 1, sharex=ax) plot.all(mrac, "Wcirc", style=cmdstyle) plot.all(vlmrac, "W", style=dict(mrac.style, c="k")) plot.all(vlmrac, "F", style=dict(mrac.style, c="b")) plot.all(vlmrac, "What", is_agent=True, style=dict(mrac.style, c="g")) plt.ylim(-70, 30) plt.xlabel("Time, sec") plt.xlim(t_range) plt.show()
def exp2_plot(): def get_data(datadir): data = SN() env, info = fym.logging.load(list(datadir.glob("*env.h5"))[0], with_info=True) data.env = env data.info = info agentlist = list(datadir.glob("*agent.h5")) if agentlist != []: data.agent = fym.logging.load(agentlist[0]) data.style = dict(label=info["cfg"].label) return data cfg = multirotor.cfg multirotor.load_config() plt.rc("font", family="Times New Roman") plt.rc("text", usetex=True) plt.rc("lines", linewidth=1) plt.rc("axes", grid=True) plt.rc("grid", linestyle="--", alpha=0.8) datadir = Path("data", "exp2") mrac = get_data(Path(datadir, "data00")) hmrac = get_data(Path(datadir, "data01")) data = [mrac, hmrac] basestyle = dict(c="k", lw=0.7) cmdstyle = dict(basestyle, c="r", ls="--", label="Command") refstyle = dict(basestyle, c="k", ls="-", label="Ref. Model") mrac.style.update(basestyle, c="g", ls="-") hmrac.style.update(basestyle, c="b", ls="-") # Figure common setup t_range = (0, cfg.final_time) # t_range = (0, 15) # All in inches subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 r2d = np.rad2deg(1) # ================= # States and inputs # ================= figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(311, position=pos[0]) lines = [] # lines += plt.plot(mrac.env["t"], mrac.env["c"][:, 0], **cmdstyle) lines += plot.vector_by_index(mrac, "c", 0, mult=r2d, style=cmdstyle) lines += plot.vector_by_index(mrac, "xr", 0, mult=r2d, style=refstyle) lines += [plot.vector_by_index(d, "x", 0, r2d)[0] for d in data] plt.ylabel(r"$p$ [deg/s]") # plt.ylim(-40, 40) plt.figlegend( lines, [line.get_label() for line in lines], bbox_to_anchor=(0.99, 0.78) ) plt.subplot(312, sharex=ax, position=pos[1]) plot.vector_by_index(mrac, "c", 1, mult=r2d, style=cmdstyle) plot.vector_by_index(mrac, "xr", 1, mult=r2d, style=refstyle) [plot.vector_by_index(d, "x", 1, r2d) for d in data] plt.ylabel(r"$q$ [deg/s]") # plt.ylim(-40, 40) plt.subplot(313, sharex=ax, position=pos[2]) plot.vector_by_index(mrac, "c", 2, mult=r2d, style=cmdstyle) plot.vector_by_index(mrac, "xr", 2, mult=r2d, style=refstyle) [plot.vector_by_index(d, "x", 2, r2d) for d in data] plt.ylabel(r"$r$ [deg/s]") # plt.ylim(-40, 40) # plt.subplot(414, sharex=ax, position=pos[3]) # [plot.all(d, "u") for d in data] # plt.ylabel(r'$u$') # plt.ylim(1.07, 1.47) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # ======================================= # Tracking error and parameter estimation # ======================================= figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plt.subplot(311, position=pos[0]) [plot.tracking_error(d) for d in data] plt.ylabel(r"$||e||$") # plt.ylim(0, 0.2) plt.legend(loc='best') plt.subplot(312, sharex=ax, position=pos[1]) [plot.all(d, "W") for d in data] plt.ylabel(r"$W$") # plt.ylim(0, 85) # plt.subplot(313, sharex=ax, position=pos[2]) # plot.all(hmrac, "What") # plt.ylabel(r"$\hat{W}$") # plt.ylim(0, 85) plt.subplot(313, sharex=ax, position=pos[2]) [plot.all(d, "u") for d in data] plt.ylabel(r'$u$') # plt.ylim(1.07, 1.47) plt.xlabel("Time, sec") plt.xlim(t_range) plt.show()
def comp(sqldir, klmdir): # Data 001 ~ Data 002 sql = plot.get_data(Path(datadir, sqldir)) klm = plot.get_data(Path(datadir, klmdir)) data = [sql, klm] # data_na = [] basestyle = dict(c="k", lw=0.7) refstyle = dict(basestyle, c="r", ls="--") klm_style = dict(basestyle, c="y", ls="-") sql_style = dict(basestyle, c="b", ls="-.") klm.style.update(klm_style) sql.style.update(sql_style) # zlearner_na.style.update(klm_style) # qlearner_na.style.update(sql_style) # Figure common setup t_range = (0, sql.info["cfg"].env_kwargs.max_t) # All in inches subsize = (4.05, 0.946) width = 4.94 top = 0.2 bottom = 0.671765 left = 0.5487688 hspace = 0.2716 # ================= # States and inputs # ================= figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "x", 0)[0] for d in data] plt.ylabel(r"$x_1$") # plt.ylim(-2, 2) plt.legend() plot.subplot(pos, 1, sharex=ax) [plot.vector_by_index(d, "x", 1) for d in data] plt.ylabel(r"$x_2$") # plt.ylim(-2, 2) plot.subplot(pos, 2, sharex=ax) [plot.vector_by_index(d, "x", 2) for d in data] plt.ylabel(r'$x_3$') # plt.ylim(-80, 80) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # ==================== # Parameter estimation # ==================== figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "u", 0) for d in data] plt.ylabel(r'$\delta_t$') plot.subplot(pos, 1, sharex=ax) plot.all(sql, "K", style=dict(refstyle, label="True")) for d in data: plot.all(d, "K", is_agent=True, style=dict(marker="o", markersize=2)) plt.ylabel(r"$\hat{K}$") plt.legend() # plt.ylim(-70, 30) plot.subplot(pos, 2, sharex=ax) plot.all(sql, "P", style=dict(sql.style, c="r", ls="--")) for d in data: plot.all(d, "P", is_agent=True, style=dict(marker="o", markersize=2)) plt.ylabel(r"$\hat{P}$") # plt.ylim(-70, 30) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer()
def exp6_plot(): def get_data(name, style=dict(), with_info=False): path = Path(datadir, name) style = datastyle | style dataset = SN() if with_info: data, info = fym.logging.load(path, with_info=with_info) dataset.info = info dataset.style = style | dict(label=info["cfg"].label) else: data = fym.logging.load(path) dataset.style = style dataset.data = data return dataset # ------ Exp Setup ------ # expdir = Path("data", "exp6") basestyle = dict(c="k", lw=0.7) refstyle = basestyle | dict(c="r", ls="--") sql_style = basestyle | dict(c="b", ls="-.") klm_style = basestyle | dict(c="g", ls="-.") test_style = basestyle | dict(c="k", ls="--") # ------ Data 001 ------ # datadir = Path(expdir, "data-001") datastyle = sql_style sql_env = get_data("env.h5", with_info=True) sql_agent = get_data("sql-agent.h5", style=sql_env.style) sql_test = get_data("test-learnt-env.h5", style=sql_env.style) datastyle = test_style lqr_test = get_data("test-lqr-env.h5", style=dict(label="LQR")) # ------ Data 002 ------ # datadir = Path(expdir, "data-002") datastyle = klm_style klm_env = get_data("env.h5", with_info=True) klm_agent = get_data("klm-agent.h5", style=klm_env.style) klm_test = get_data("test-learnt-env.h5", style=klm_env.style) data_train = [sql_env, klm_env] data_agent = [sql_agent, klm_agent] data_test = [sql_test, klm_test, lqr_test] # Figure common setup t_range = (0, sql_env.info["cfg"].env_kwargs.max_t) # All in inches subsize = (4.05, 0.946) width, top, bottom, left = (4.94, 0.2, 0.671765, 0.5487688) hspace = 0.2716 # ============================ # States and inputs (Training) # ============================ figsize, pos = plot.posing(6, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "x", 0)[0] for d in data_train] plt.ylabel(r"$V_T$, m/s") # plt.ylim(19, 23) plt.legend() plot.subplot(pos, 1, sharex=ax) [plot.vector_by_index(d, "x", 1, mult=np.rad2deg(1)) for d in data_train] plt.ylabel(r"$\alpha$, deg") # plt.ylim(-5, 8) plot.subplot(pos, 2, sharex=ax) [plot.vector_by_index(d, "x", 2, mult=np.rad2deg(1)) for d in data_train] plt.ylabel(r"$q$, deg/s") # plt.ylim(-50, 50) plot.subplot(pos, 3, sharex=ax) [plot.vector_by_index(d, "x", 3, mult=np.rad2deg(1)) for d in data_train] plt.ylabel(r"$\gamma$, deg") # plt.ylim(-5, 23) plot.subplot(pos, 4, sharex=ax) [plot.vector_by_index(d, "u", 0) for d in data_train] plt.ylabel(r"$\delta_t$") # plt.ylim(0, 0.2) plot.subplot(pos, 5, sharex=ax) [plot.vector_by_index(d, "u", 1, mult=np.rad2deg(1)) for d in data_train] plt.ylabel(r'$\delta_e$, deg') # plt.ylim(-15, 5) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # =============================== # Parameter estimation (Training) # =============================== figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) plot.subplot(pos, 0, sharex=ax) plot.all(sql_env, "K", style=dict(refstyle, label="True")) for d in data_agent: plot.all(d, "K", is_agent=True, style=dict(marker="o", markersize=2)) plt.ylabel(r"$\hat{K}$") plt.legend() plt.ylim(-15, 7) plot.subplot(pos, 1, sharex=ax) plot.all(sql_env, "P", style=dict(sql_env.style, c="r", ls="--")) for d in data_agent: plot.all(d, "P", is_agent=True, style=dict(marker="o", markersize=2)) plt.ylabel(r"$\hat{P}$") plt.ylim(-12, 28) plt.xlabel("Time, sec") plt.xlim(t_range) for ax in plt.gcf().get_axes(): ax.label_outer() # ======================== # States and inputs (Test) # ======================== figsize, pos = plot.posing(6, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) ax = plot.subplot(pos, 0) [plot.vector_by_index(d, "x", 0)[0] for d in data_test] plt.ylabel(r"$V_T$, m/s") plt.ylim(19, 23) plt.legend() plot.subplot(pos, 1, sharex=ax) [plot.vector_by_index(d, "x", 1, mult=np.rad2deg(1)) for d in data_test] plt.ylabel(r"$\alpha$, deg") plt.ylim(-5, 8) plot.subplot(pos, 2, sharex=ax) [plot.vector_by_index(d, "x", 2, mult=np.rad2deg(1)) for d in data_test] plt.ylabel(r"$q$, deg/s") plt.ylim(-50, 50) plot.subplot(pos, 3, sharex=ax) [plot.vector_by_index(d, "x", 3, mult=np.rad2deg(1)) for d in data_test] plt.ylabel(r"$\gamma$, deg") plt.ylim(-5, 23) plot.subplot(pos, 4, sharex=ax) [plot.vector_by_index(d, "u", 0) for d in data_test] plt.ylabel(r"$\delta_t$") plt.ylim(0, 0.2) plot.subplot(pos, 5, sharex=ax) [plot.vector_by_index(d, "u", 1, mult=np.rad2deg(1)) for d in data_test] plt.ylabel(r'$\delta_e$, deg') plt.ylim(-15, 5) plt.xlabel("Time, sec") plt.xlim(0, 5) for ax in plt.gcf().get_axes(): ax.label_outer() # ================= # Performance Index # ================= figsize, pos = plot.posing(1, subsize, width, top, bottom, left, hspace) plt.figure(figsize=figsize) plot.subplot(pos, 0) [plot.vector_by_index(d, "PI", 0)[0] for d in data_test] plt.ylabel(r"Performance Index") plt.ylim(-1, 20) plt.legend() plt.xlabel("Time, sec") plt.xlim(0, 5) for ax in plt.gcf().get_axes(): ax.label_outer() # # ================================== # # States and inputs (Non-Admissible) # # ================================== # figsize, pos = plot.posing(5, subsize, width, top, bottom, left, hspace) # plt.figure(figsize=figsize) # ax = plot.subplot(pos, 0) # [plot.vector_by_index(d, "x", 0)[0] for d in data_na] # plt.ylabel(r"$x_1$") # # plt.ylim(-2, 2) # plt.legend() # plot.subplot(pos, 1, sharex=ax) # [plot.vector_by_index(d, "x", 1) for d in data_na] # plt.ylabel(r"$x_2$") # # plt.ylim(-2, 2) # plot.subplot(pos, 2, sharex=ax) # [plot.vector_by_index(d, "u", 0) for d in data_na] # plt.ylabel(r'$u$') # # plt.ylim(-80, 80) # # ===================================== # # Parameter estimation (Non-Admissible) # # ===================================== # ax = plot.subplot(pos, 3) # plot.all(qlearner_na, "K", style=dict(refstyle, label="True")) # for d in data_na: # plot.all( # d, "K", is_agent=True, # style=dict(marker="o", markersize=2) # ) # plt.ylabel(r"$\hat{K}$") # plt.legend() # # plt.ylim(-70, 30) # plot.subplot(pos, 4, sharex=ax) # plot.all(qlearner_na, "P", style=refstyle) # for d in data_na: # plot.all( # d, "P", is_agent=True, # style=dict(marker="o", markersize=2) # ) # plt.ylabel(r"$\hat{P}$") # # plt.ylim(-70, 30) # plt.xlabel("Time, sec") # plt.xlim(t_range) # for ax in plt.gcf().get_axes(): # ax.label_outer() imgdir = Path("img", datadir.relative_to("data")) imgdir.mkdir(exist_ok=True) plt.figure(1) plt.savefig(Path(imgdir, "figure_1.pdf"), bbox_inches="tight") plt.figure(2) plt.savefig(Path(imgdir, "figure_2.pdf"), bbox_inches="tight") plt.figure(3) plt.savefig(Path(imgdir, "figure_3.pdf"), bbox_inches="tight") plt.show()