def write_table_subfig(nrows, ncols, allcells={},
                allcols=None, allrows=None, introws=None, intcols=None,
                firstrow=None, firstcol=None, intcells={},
                label_prefix=None):
    """ Like write_table(), but use subfigures """
    
    param_table = get_param_table(nrows, ncols, allcells, allcols, allrows,
                                  introws, intcols, firstrow, firstcol, intcells)

#    with latex_fragment(sys.stdout, graphics_path=get_resources_dir()) as frag:
#        for r, param_row in enumerate(param_table):
#            for c, param_cell in enumerate(param_row):
#                internal = c > 0 and r > 0
#                if internal:
#                    if label_prefix is not None:
#                        label = '%s-%s' % (r, c)
#                        label = label_prefix + '-' + label
#                    else:
#                        label = None
#                        
#                    with frag.subfigure(caption="", label=label) as subfigure:
#                        call_template(subfigure, param_cell)                    
#                else:
# #                    with frag.minipage() as minip:
#                    call_template(frag, param_cell)
#            frag.parbreak()
    
    
    alignment = ['r'] + ['c'] * ncols   
    with latex_fragment(sys.stdout, graphics_path=get_resources_dir()) as frag:
        with frag.tabular(alignment=alignment) as tabular:
            for r, param_row in enumerate(param_table):
                with tabular.row() as tex_row:
                    for c, param_cell in enumerate(param_row):
                        with tex_row.cell() as cell:
                            # print r, c, param_cell
                            logger.debug('%s %s : %s' % (r, c, param_cell))
#                            call_template(cell, param_cell)
                            internal = c > 0 and r > 0
                            if label_prefix is not None:
                                label = '%s-%s' % (r, c)
                                label = label_prefix + '-' + label
                            else:
                                label = None
                            if internal:
                                with cell.subfigure(caption="", label=label) as subfigure:
                                    call_template(subfigure, param_cell)
                            else:
                                call_template(cell, param_cell)
def write_table(nrows, ncols, allcells={},
                allcols=None, allrows=None, introws=None, intcols=None,
                firstrow=None, firstcol=None, intcells={}):
    """
        Use as follows:
        
        Example 1: show correlation table
        
          write_table(common=dict(id_set='id_set'),
                      rows=[dict(id_robot='robot1'),
                            dict(id_robot='robot2')],
                      cols=[dict(id_agent='bdse1'),
                            dict(id_agent='bdse2')],
                      header_row = dict(template='agent_name'),
                      header_col = dict(template='robot_name'),
                      cells=dict(template='predict_y_dot_corr'))
            
        Example 2: show P and correlation for one agent
        
          write_table(common=dict(id_set='id_set', id_agent='id_agent'),
                      rows=[dict(id_robot='robot1'),
                            dict(id_robot='robot2')],
                      cols=[dict(template='bds_P'),
                            dict(template='bds_T0'),
                            dict(template='predict_y_dot_corr')],
                      header_row = dict(template='empty'),
                      header_col = dict(template='robot_name'),
                      cells=dict())
                      
    """
    
    param_table = get_param_table(nrows, ncols, allcells, allcols, allrows,
                                  introws, intcols, firstrow, firstcol, intcells)

    alignment = ['r'] + ['c'] * ncols   
    with latex_fragment(sys.stdout, graphics_path=get_resources_dir()) as frag:
        with frag.tabular(alignment=alignment) as tabular:
            for r, param_row in enumerate(param_table):
                with tabular.row() as tex_row:
                    for c, param_cell in enumerate(param_row):
                        with tex_row.cell() as cell:
                            # print r, c, param_cell
                            logger.debug('%s %s : %s' % (r, c, param_cell))
                            call_template(cell, param_cell)
Beispiel #3
0
def bvtemplate(name, **params):
    """ Prints a string. Can be used from TeX code. """    
    with latex_fragment(sys.stdout, graphics_path=get_resources_dir()) as frag:
        params['template'] = name
        call_template(frag, params)
Beispiel #4
0
def bvvehicleimage(id_set, id_robot, width_em=3.5):
    with latex_fragment(sys.stdout, graphics_path=get_resources_dir()) as frag:
        create_robot_figure(frag, id_set, id_robot, width_em, write_world=False)
Beispiel #5
0
def bds_learn_reportA(id_set, agent, robot, width="3cm"):
    """ This just prints on standard output """
    report = load_report_phase(id_set=id_set, agent=agent, robot=robot, phase="learn")

    prefix = "%s-%s-%s" % (id_set, robot, agent)
    #
    #     bds_learn_reportA_frag(report, prefix=prefix, agent, robot, width=width,
    #                            stream=sys.stdout,
    #                            graphics_path=get_resources_dir())

    stream = sys.stdout
    graphics_path = get_resources_dir()

    # def bds_learn_reportA_frag(report, prefix, agent, robot, width, stream=sys.stdout,
    #                            graphics_path=None):
    #
    #     if graphics_path is None:
    #         graphics_path = ()
    #

    assert isinstance(report, Node)

    def save_data(node, gid):
        fig.save_graphics_data(node.raw_data, node.mime, gid)

    with latex_fragment(stream, graphics_path) as frag:
        caption = (
            "BDS learning and prediction statistics for the agent "
            "\\bvid{%r} interacting with the robot \\bvid{%r}. \\bvseelegend" % (agent, robot)
        )
        label = "fig:%s-learn-rA" % prefix

        with frag.figure(caption=caption, label=label, placement="p") as fig:
            tsize = "3cm"
            height = "3cm"

            fig.hfill()
            with fig.subfigure(caption="\\texttt{%s}" % robot, label="%s-%s" % (label, "vehicle")) as sub:

                with sub.minipage("3cm", align="b") as mp:
                    mp.tex("\\vspace{0pt}\n")
                    mp.tex("\\centering")
                    create_robot_figure(mp, id_set, robot)

            display_k_tensor(
                fig,
                report["estimator/tensors/U/value"].raw_data,
                gid_pattern="%s-U%%d" % (prefix),
                label_patterns="fig:%s" % prefix + "-U%d",
                caption_patterns="$\TUe^{s}_{%d}$",
                width=tsize,
                xlabel="s",
                ylabel="\TUe^{s}",
            )

            # fig.hfill() # added by display_k_tensor
            fig.parbreak()

            fig.hfill()

            with fig.subfigure(caption="$\Tcove^{sv}$", label="%s-%s" % (label, "P")) as sub:
                gid = "%s-P" % (prefix)
                save_data(report["estimator/tensors/P/png"], gid)
                tensor_figure(sub, gid=gid, xlabel="s", ylabel="v", width=width, label="P^{sv}")

            display_3tensor(
                fig,
                V=report["estimator/tensors/T/value"].raw_data,
                gid_pattern=prefix + "-T%d",
                label_patterns="fig:%s" % prefix + "-T%d",
                caption_patterns="\TTe^{s\,v\,%d}",
                width=width,
                label="\TTe^{s\,v\,%d}",
                xlabel="s",
                ylabel="v",
            )

            # fig.hfill() # added by display_3_tensor
            fig.parbreak()

            fig.hfill()
            from .prediction import tab_predict_u_corr

            with fig.subfigure(caption="\\labelpredu", label="%s-%s" % (label, "ucorr")) as sub:
                # fig_predict_u_corr(sub, id_set, agent, robot, "1cm")
                tab_predict_u_corr(sub, id_set, agent, robot)

            display_k_tensor(
                fig,
                report["estimator/model/N/value"].raw_data,
                gid_pattern=prefix + "-N%d",
                label_patterns="fig:%s" % prefix + "-N%d",
                caption_patterns="$\TNe^{s}_{%d}$",
                width=tsize,
                xlabel="s",
                ylabel="\TNe^{s}",
            )

            fig.hfill()
            fig.parbreak()

            fig.hfill()
            from .prediction import fig_predict_corr

            with fig.subfigure(caption="\\labelpredydot", label="%s-%s" % (label, "corr")) as sub:
                fig_predict_corr(sub, id_set, agent, robot, width=width, height=height)

            display_3tensor(
                fig,
                V=report["estimator/model/M/value"].raw_data,
                gid_pattern=prefix + "-M%d",
                label_patterns="fig:%s" % prefix + "-M%d",
                caption_patterns="\TMe^s_{v\,%d}",
                width=width,
                label="\TMe^s_{v\,%d}",
                xlabel="s",
                ylabel="v",
            )
            fig.hfill()