Exemplo n.º 1
0
            def wrapper(*args, **kwargs):
                import matplotlib.pyplot as plt
                from pymake.plot import _linestyle, _markers
                if len(groups) == 0:
                    group = '_expe_id'
                else:
                    group = groups[0]
                self = args[0]
                expe = self.expe
                discr_args = []
                if len(args) > 1:
                    discr_args = args[1].split('/')

                # Init Figs Sink
                if not hasattr(self.gramexp, '_figs'):
                    figs = dict()
                    for c in self.gramexp.get_set(group):
                        figs[c] = ExpSpace()
                        figs[c].group = c
                        figs[c].fig = plt.figure()
                        figs[c].linestyle = _linestyle.copy()
                        figs[c].markers = _markers.copy()

                    self.gramexp._figs = figs

                frame = self.gramexp._figs[expe[group]]
                frame.ax = lambda: frame.fig.gca()

                kernel = fun(self, frame, *args[1:])

                # Set title and filename
                title = ' '.join('{{{0}}}'.format(w)
                                 for w in groups).format(**self.specname(expe))
                frame.base = '%s_%s' % (fun.__name__, title.replace(' ', '_'))
                frame.args = discr_args
                if 'title' in frame:
                    # if multipolot
                    #plt.suptitle(frame.title)
                    frame.ax().set_title(frame.title)
                else:
                    frame.ax().set_title(title)

                # Save on last call
                if self._it == self.expe_size - 1:
                    if expe._write:
                        self.write_frames(self.gramexp._figs)

                return kernel
Exemplo n.º 2
0
    def __init__(self, pt, expe, expdesign, gramexp):
        ''' Sandbox class for scripts/actions.

            Parameters
            ----------
            pt: int
                Positional indicator for current run
            expe: ExpSpace
                Current spec (or equivalently accessible with `self.s`
            expdesign: ExpDesign
                Current design class
            gramexp: Global pmk object

            Methods
            -------
            log_expe: none
                overwrite the header message before each run.
            is_first_expe: none
                return true if the current run is the first.
            is_last_expe: none
                return true if the current run is the last.
            get_expe_len: int
                the total number of expe
            get_expe_it: int
                the current expe iteration
            load_frontend: none
                load the data frontend for the current expe.
            load_model: none
                the model for the current expe.
            load_data: matrix
                load data based on extension

            Decorator
            --------
            plot: none
                plot control on expe
            table: none
                table control on expe

        '''

        self._expdesign = expdesign

        # Global
        self.expe_size = len(gramexp)
        self.gramexp = gramexp
        self.D = self.gramexp.D  # Global conteneur
        # Local
        self.pt = pt
        self.expe = expe
        self.spec = expe
        self.s = expe

        # Plot utils
        from pymake.plot import _linestyle, _markers, _colors
        self.linestyles = _linestyle.copy()
        self.markers = _markers.copy()
        self.colors = _colors.copy()

        # to exploit / Vizu
        self._it = pt['expe']
        self.corpus_pos = pt.get('corpus')
        self.model_pos = pt.get('model')
        self.output_path = self.expe['_output_path']
        self.input_path = self.expe['_input_path']

        if expe.get('_expe_silent'):
            self.log_silent()
        else:
            self.log.info('-' * 10)
            self.log.info(
                ''.join([colored('Expe %d/%d', 'red'), ' : ',
                         self.log_expe()]) % (
                             self._it + 1,
                             self.expe_size,
                         ))
            self.log.info('-' * 10)

        self._set_measures()
Exemplo n.º 3
0
            def wrapper(*args, **kwargs):
                import matplotlib.pyplot as plt
                from pymake.plot import _linestyle, _markers

                self = args[0]
                discr_args = []  # discriminant keys (to distinguish filename)
                if len(args) == 1:
                    groups = ['corpus']
                    attribute = '_entropy'
                else:
                    groups = args[1].split(':')
                    if len(groups) == 1:
                        attribute = groups[0]
                        groups = None
                    else:
                        attribute = groups.pop(-1)
                        groups = groups[0]

                    if len(args) > 2:
                        discr_args = args[2].split('/')

                if '@' in attribute:
                    attribute, opts = attribute.split('@')
                    repeatkey = opts[0]
                else:
                    repeatkey = None

                if groups:
                    groups = groups.split('/')
                    self._groups = groups
                    ggroup = self.get_current_group()
                else:
                    ggroup = None

                # Init Figs Sink
                if not hasattr(self.gramexp, '_figs'):
                    figs = dict()
                    if groups:
                        gset = product(*filter(
                            None, [self.gramexp.get_set(g) for g in groups]))
                    else:
                        gset = [None]

                    for g in gset:
                        gg = '-'.join(sorted(map(str, g))) if g else None
                        figs[gg] = ExpSpace()
                        figs[gg].group = g
                        figs[gg].fig = plt.figure()
                        figs[gg].linestyle = _linestyle.copy()
                        figs[gg].markers = _markers.copy()
                        if repeatkey:
                            figs[gg].is_errorbar = True
                            figs[gg].repeatkey = repeatkey
                        else:
                            figs[gg].is_errorbar = False

                    self.gramexp._figs = figs

                frame = self.gramexp._figs[ggroup]
                frame.ax = lambda: frame.fig.gca()

                kernel = fun(self, frame, attribute)

                # Set title and filename
                if groups and self.expe.get(groups[0]):
                    #title = ' '.join('{{{0}}}'.format(w) for w in groups).format(**self.specname(self.expe))
                    ctitle = tuple(
                        filter(
                            None,
                            map(lambda x: self.specname(self.expe.get(x, x)),
                                groups)))
                    s = '_'.join(['%s'] * len(ctitle))
                    title = s % ctitle
                else:
                    title = ' '.join(self.gramexp.get_nounique_keys())
                    title = '%s %s' % tuple(
                        map(lambda x: self.expe.get(x, x),
                            ['corpus', 'model']))

                frame.base = '%s_%s' % (fun.__name__, attribute)
                frame.args = discr_args

                if 'fig_xaxis' in frame or self.expe.get('fig_xaxis'):
                    xaxis_name = frame.get('xaxis', self.expe.get('fig_xaxis'))
                    frame.ax().set_xlabel(xaxis_name)
                else:
                    frame.ax().set_xlabel('iterations')

                if 'fig_yaxis' in frame or self.expe.get('fig_yaxis'):
                    yaxis_name = frame.get('yaxis',
                                           self.expe.get('fig_yaxis')).get(
                                               attribute, attribute)
                    frame.ax().set_ylabel(yaxis_name)
                else:
                    frame.ax().set_ylabel(attribute)

                if 'title_size' in self.expe:
                    ts = float(self.expe['title_size'])
                else:
                    ts = 15

                if 'title' in frame:
                    plt.suptitle(frame.title, fontsize=ts)
                else:
                    frame.ax().set_title(title, fontsize=ts)

                if 'ticks_size' in self.expe:
                    plt.xticks(fontsize=float((self.expe['ticks_size'])))

                # Save on last call
                if self._it == self.expe_size - 1:
                    if self.expe._write:
                        self.write_frames(self.gramexp._figs)

                return kernel
Exemplo n.º 4
0
    def __init__(self, pt, expe, expdesign, gramexp):
        ''' Sandbox class for scripts/actions.

            Parameters
            ----------
            pt: int
                Positional indicator for current run
            expe: ExpSpace
                Current spec
            expdesign: ExpDesign
                Current design class
            gramexp: Global pmk object

            Methods
            -------
            log_expe:
                overwrite the header message before each run.
            is_first_expe:
                return true if the current run is the first.
            is_last_expe:
                return true if the current run is the last.
            load_frontend:
                load the data frontend for the current expe.
            load_model:
                the model for the current expe.

            Decorator
            --------
            plot:
                plot control on expe
            table:
                table control on expe

        '''

        self._expdesign = expdesign

        # @debug this, I dont know whyiam in lib/package sometimes, annoying !
        os.chdir(os.getenv('PWD'))

        # Global
        self.expe_size = len(gramexp)
        self.gramexp = gramexp
        self.D = self.gramexp.D  # Global conteneur
        # Local
        self.pt = pt
        self.expe = expe

        # Plot utils
        from pymake.plot import _linestyle, _markers, _colors
        self.linestyles = _linestyle.copy()
        self.markers = _markers.copy()
        self.colors = _colors.copy()

        # to exploit / Vizu
        self._it = pt['expe']
        self.corpus_pos = pt.get('corpus')
        self.model_pos = pt.get('model')
        self.output_path = self.expe['_output_path']
        self.input_path = self.expe['_input_path']

        if expe.get('_expe_silent'):
            self.log_silent()
        else:
            self.log.info('-' * 10)
            self.log.info(
                ''.join([colored('Expe %d/%d', 'red'), ' : ',
                         self.log_expe()]) % (
                             self._it + 1,
                             self.expe_size,
                         ))
            self.log.info('-' * 10)
Exemplo n.º 5
0
            def wrapper(*args, **kwargs):
                import matplotlib.pyplot as plt
                from pymake.plot import _linestyle, _markers

                self = args[0]
                discr_args = []  # discriminant keys (to distinguish filename)
                if len(args) == 1:
                    groups = ['corpus']
                    attribute = '_entropy'
                else:
                    groups = args[1].split(':')
                    if len(groups) == 1:
                        attribute = groups[0]
                        groups = None
                    else:
                        attribute = groups.pop(-1)
                        groups = groups[0]
                    if len(args) > 2:
                        discr_args = args[2].split('/')

                if groups:
                    groups = groups.split('/')
                    ggroup = self._file_part(
                        [self.expe.get(g) for g in groups], sep='-')
                else:
                    ggroup = None

                # Init Figs Sink
                if not hasattr(self.gramexp, '_figs'):
                    figs = dict()
                    if groups:
                        gset = product(*filter(
                            None, [self.gramexp.get_set(g) for g in groups]))
                    else:
                        gset = [None]

                    for g in gset:
                        gg = '-'.join(map(str, g)) if g else None
                        figs[gg] = ExpSpace()
                        figs[gg].fig = plt.figure()
                        figs[gg].linestyle = _linestyle.copy()
                        figs[gg].markers = _markers.copy()

                    self.gramexp._figs = figs

                frame = self.gramexp._figs[ggroup]
                frame.ax = lambda: frame.fig.gca()

                kernel = fun(self, frame, attribute, **kwargs)

                # Set title and filename
                if groups and self.expe.get(groups[0]):
                    #title = ' '.join('{{{0}}}'.format(w) for w in groups).format(**self.specname(self.expe))
                    ctitle = tuple(
                        filter(
                            None,
                            map(lambda x: self.specname(self.expe.get(x, x)),
                                groups)))
                    s = '_'.join(['%s'] * len(ctitle))
                    title = s % ctitle
                else:
                    title = ' '.join(self.gramexp.get_nounique_keys())
                    if not title:
                        title = '%s %s' % tuple(
                            map(lambda x: self.expe.get(x, x),
                                ['corpus', 'model']))

                frame.base = '%s_%s' % (fun.__name__, attribute)
                frame.args = discr_args
                frame.ax().set_xlabel('iterations')
                frame.ax().set_ylabel(attribute)
                if 'title' in frame:
                    plt.suptitle(frame.title)
                else:
                    frame.ax().set_title(title)

                # Save on last call
                if self._it == self.expe_size - 1:
                    if self.expe._write:
                        self.write_frames(self.gramexp._figs)

                return kernel