(self, fig=None, iabscissa=1, iteridx=None, plot_mean=True,  # TODO: plot_mean default should be False
             foffset=1e-19, x_opt = None, fontsize=10)
return self
plot data from a `CMADataLogger` (using the files written by the logger).

        Arguments
        ---------
            `fig`
                figure number, by default 325
            `iabscissa`
                ``0==plot`` versus iteration count,
                ``1==plot`` versus function evaluation number
            `iteridx`
                iteration indices to plot

        Return `CMADataLogger` itself.

        Examples
        --------
        ::

            import cma
            logger = cma.CMADataLogger()  # with default name
            # try to plot the "default logging" data (e.g. from previous fmin calls)
            logger.plot() # to continue you might need to close the pop-up window
                          # once and call plot() again.
                          # This behavior seems to disappear in subsequent
                          # calls of plot(). Also using ipython with -pylab
                          # option might help.
            cma.savefig('fig325.png')  # save current figure
            logger.closefig()

        Dependencies: matlabplotlib/pylab.
plot data from a `CMADataLogger` (using the files written by the logger).
plot data from a CMADataLogger ( using the files written by the logger ) .
def plot(self, fig=None, iabscissa=1, iteridx=None, plot_mean=True,  # TODO: plot_mean default should be False
             foffset=1e-19, x_opt = None, fontsize=10):
        """
        plot data from a `CMADataLogger` (using the files written by the logger).

        Arguments
        ---------
            `fig`
                figure number, by default 325
            `iabscissa`
                ``0==plot`` versus iteration count,
                ``1==plot`` versus function evaluation number
            `iteridx`
                iteration indices to plot

        Return `CMADataLogger` itself.

        Examples
        --------
        ::

            import cma
            logger = cma.CMADataLogger()  # with default name
            # try to plot the "default logging" data (e.g. from previous fmin calls)
            logger.plot() # to continue you might need to close the pop-up window
                          # once and call plot() again.
                          # This behavior seems to disappear in subsequent
                          # calls of plot(). Also using ipython with -pylab
                          # option might help.
            cma.savefig('fig325.png')  # save current figure
            logger.closefig()

        Dependencies: matlabplotlib/pylab.

        """

        dat = self.load(self.name_prefix)

        try:
            # pylab: prodedural interface for matplotlib
            from  matplotlib.pylab import figure, ioff, ion, subplot, semilogy, hold, plot, grid, \
                 axis, title, text, xlabel, isinteractive, draw, gcf

        except ImportError:
            ImportError('could not find matplotlib.pylab module, function plot() is not available')
            return

        if fontsize and pylab.rcParams['font.size'] != fontsize:
            print('global variable pylab.rcParams[\'font.size\'] set (from ' +
                  str(pylab.rcParams['font.size']) + ') to ' + str(fontsize))
            pylab.rcParams['font.size'] = fontsize  # subtracted in the end, but return can happen inbetween

        if fig:
            figure(fig)
        else:
            figure(325)
            # show()  # should not be necessary
        self.fighandle = gcf()  # fighandle.number

        if iabscissa not in (0,1):
            iabscissa = 1
        interactive_status = isinteractive()
        ioff() # prevents immediate drawing

        if 11 < 3:
            dat.x = dat.xrecent
            if len(dat.x) < 2:
                print('not enough data to plot')
                return {}
        # if plot_mean:
        dat.x = dat.xmean    # this is the genotyp
        if iteridx is not None:
            dat.f = dat.f[np.where([x in iteridx for x in dat.f[:,0]])[0],:]
            dat.D = dat.D[np.where([x in iteridx for x in dat.D[:,0]])[0],:]
            iteridx.append(dat.x[-1,1])  # last entry is artificial
            dat.x = dat.x[np.where([x in iteridx for x in dat.x[:,0]])[0],:]
            dat.std = dat.std[np.where([x in iteridx for x in dat.std[:,0]])[0],:]

        if iabscissa == 0:
            xlab = 'iterations'
        elif iabscissa == 1:
            xlab = 'function evaluations'

        # use fake last entry in x and std for line extension-annotation
        if dat.x.shape[1] < 100:
            minxend = int(1.06*dat.x[-2, iabscissa])
            # write y-values for individual annotation into dat.x
            dat.x[-1, iabscissa] = minxend  # TODO: should be ax[1]
            idx = np.argsort(dat.x[-2,5:])
            idx2 = np.argsort(idx)
            if x_opt is None:
                dat.x[-1,5+idx] = np.linspace(np.min(dat.x[:,5:]),
                            np.max(dat.x[:,5:]), dat.x.shape[1]-5)
            else:
                dat.x[-1,5+idx] = np.logspace(np.log10(np.min(abs(dat.x[:,5:]))),
                            np.log10(np.max(abs(dat.x[:,5:]))), dat.x.shape[1]-5)
        else:
            minxend = 0

        if len(dat.f) == 0:
            print('nothing to plot')
            return

        # not in use anymore, see formatter above
        # xticklocs = np.arange(5) * np.round(minxend/4., -int(np.log10(minxend/4.)))

        # dfit(dfit<1e-98) = NaN;

        ioff() # turns update off

        # TODO: if abscissa==0 plot in chunks, ie loop over subsets where dat.f[:,0]==countiter is monotonous

        subplot(2,2,1)
        self.plotdivers(dat, iabscissa, foffset)

        # TODO: modularize also the remaining subplots
        subplot(2,2,2)
        hold(False)
        if x_opt is not None:  # TODO: differentate neg and pos?
            semilogy(dat.x[:, iabscissa], abs(dat.x[:,5:]) - x_opt, '-')
        else:
            plot(dat.x[:, iabscissa], dat.x[:,5:],'-')
        hold(True)
        grid(True)
        ax = array(axis())
        # ax[1] = max(minxend, ax[1])
        axis(ax)
        ax[1] -= 1e-6
        if dat.x.shape[1] < 100:
            yy = np.linspace(ax[2]+1e-6, ax[3]-1e-6, dat.x.shape[1]-5)
            #yyl = np.sort(dat.x[-1,5:])
            idx = np.argsort(dat.x[-1,5:])
            idx2 = np.argsort(idx)
            if x_opt is not None:
                semilogy([dat.x[-1, iabscissa], ax[1]], [abs(dat.x[-1,5:]), yy[idx2]], 'k-') # line from last data point
                semilogy(np.dot(dat.x[-2, iabscissa],[1,1]), array([ax[2]+1e-6, ax[3]-1e-6]), 'k-')
            else:
                # plot([dat.x[-1, iabscissa], ax[1]], [dat.x[-1,5:], yy[idx2]], 'k-') # line from last data point
                plot(np.dot(dat.x[-2, iabscissa],[1,1]), array([ax[2]+1e-6, ax[3]-1e-6]), 'k-')
            # plot(array([dat.x[-1, iabscissa], ax[1]]),
            #      reshape(array([dat.x[-1,5:], yy[idx2]]).flatten(), (2,4)), '-k')
            for i in range(len(idx)):
                # TODOqqq: annotate phenotypic value!?
                # text(ax[1], yy[i], 'x(' + str(idx[i]) + ')=' + str(dat.x[-2,5+idx[i]]))
                text(dat.x[-1,iabscissa], dat.x[-1,5+i], 'x(' + str(i) + ')=' + str(dat.x[-2,5+i]))

        i = 2  # find smallest i where iteration count differs (in case the same row appears twice)
        while i < len(dat.f) and dat.f[-i][0] == dat.f[-1][0]:
            i += 1
        title('Object Variables (' + ('mean' if plot_mean else 'curr best') +
                ', ' + str(dat.x.shape[1]-5) + '-D, popsize~' +
                (str(int((dat.f[-1][1] - dat.f[-i][1]) / (dat.f[-1][0] - dat.f[-i][0])))
                    if len(dat.f.T[0]) > 1 and dat.f[-1][0] > dat.f[-i][0] else 'NA')
                + ')')
        # pylab.xticks(xticklocs)

        # Scaling
        subplot(2,2,3)
        hold(False)
        semilogy(dat.D[:, iabscissa], dat.D[:,5:], '-b')
        hold(True)
        grid(True)
        ax = array(axis())
        # ax[1] = max(minxend, ax[1])
        axis(ax)
        title('Scaling (All Main Axes)')
        # pylab.xticks(xticklocs)
        xlabel(xlab)

        # standard deviations
        subplot(2,2,4)
        hold(False)
        # remove sigma from stds (graphs become much better readible)
        dat.std[:,5:] = np.transpose(dat.std[:,5:].T / dat.std[:,2].T)
        # ax = array(axis())
        # ax[1] = max(minxend, ax[1])
        # axis(ax)
        if 1 < 2 and dat.std.shape[1] < 100:
            # use fake last entry in x and std for line extension-annotation
            minxend = int(1.06*dat.x[-2, iabscissa])
            dat.std[-1, iabscissa] = minxend  # TODO: should be ax[1]
            idx = np.argsort(dat.std[-2,5:])
            idx2 = np.argsort(idx)
            dat.std[-1,5+idx] = np.logspace(np.log10(np.min(dat.std[:,5:])),
                            np.log10(np.max(dat.std[:,5:])), dat.std.shape[1]-5)

            dat.std[-1, iabscissa] = minxend  # TODO: should be ax[1]
            yy = np.logspace(np.log10(ax[2]), np.log10(ax[3]), dat.std.shape[1]-5)
            #yyl = np.sort(dat.std[-1,5:])
            idx = np.argsort(dat.std[-1,5:])
            idx2 = np.argsort(idx)
            # plot(np.dot(dat.std[-2, iabscissa],[1,1]), array([ax[2]+1e-6, ax[3]-1e-6]), 'k-') # vertical separator
            # vertical separator
            plot(np.dot(dat.std[-2, iabscissa],[1,1]), array([np.min(dat.std[-2,5:]), np.max(dat.std[-2,5:])]), 'k-')
            hold(True)
            # plot([dat.std[-1, iabscissa], ax[1]], [dat.std[-1,5:], yy[idx2]], 'k-') # line from last data point
            for i in xrange(len(idx)):
                # text(ax[1], yy[i], ' '+str(idx[i]))
                text(dat.std[-1, iabscissa], dat.std[-1, 5+i], ' '+str(i))
        semilogy(dat.std[:, iabscissa], dat.std[:,5:], '-')
        grid(True)
        title('Standard Deviations in All Coordinates')
        # pylab.xticks(xticklocs)
        xlabel(xlab)
        draw()  # does not suffice
        if interactive_status:
            ion()  # turns interactive mode on (again)
            draw()
        show()

        return self
def plot ( self , fig = None , iabscissa = 1 , iteridx = None , plot_mean = True , # TODO: plot_mean default should be False foffset = 1e-19 , x_opt = None , fontsize = 10 ) : dat = self . load ( self . name_prefix ) try : # pylab: prodedural interface for matplotlib from matplotlib . pylab import figure , ioff , ion , subplot , semilogy , hold , plot , grid , axis , title , text , xlabel , isinteractive , draw , gcf except ImportError : ImportError ( 'could not find matplotlib.pylab module, function plot() is not available' ) return if fontsize and pylab . rcParams [ 'font.size' ] != fontsize : print ( 'global variable pylab.rcParams[\'font.size\'] set (from ' + str ( pylab . rcParams [ 'font.size' ] ) + ') to ' + str ( fontsize ) ) pylab . rcParams [ 'font.size' ] = fontsize # subtracted in the end, but return can happen inbetween if fig : figure ( fig ) else : figure ( 325 ) # show()  # should not be necessary self . fighandle = gcf ( ) # fighandle.number if iabscissa not in ( 0 , 1 ) : iabscissa = 1 interactive_status = isinteractive ( ) ioff ( ) # prevents immediate drawing if 11 < 3 : dat . x = dat . xrecent if len ( dat . x ) < 2 : print ( 'not enough data to plot' ) return { } # if plot_mean: dat . x = dat . xmean # this is the genotyp if iteridx is not None : dat . f = dat . f [ np . where ( [ x in iteridx for x in dat . f [ : , 0 ] ] ) [ 0 ] , : ] dat . D = dat . D [ np . where ( [ x in iteridx for x in dat . D [ : , 0 ] ] ) [ 0 ] , : ] iteridx . append ( dat . x [ - 1 , 1 ] ) # last entry is artificial dat . x = dat . x [ np . where ( [ x in iteridx for x in dat . x [ : , 0 ] ] ) [ 0 ] , : ] dat . std = dat . std [ np . where ( [ x in iteridx for x in dat . std [ : , 0 ] ] ) [ 0 ] , : ] if iabscissa == 0 : xlab = 'iterations' elif iabscissa == 1 : xlab = 'function evaluations' # use fake last entry in x and std for line extension-annotation if dat . x . shape [ 1 ] < 100 : minxend = int ( 1.06 * dat . x [ - 2 , iabscissa ] ) # write y-values for individual annotation into dat.x dat . x [ - 1 , iabscissa ] = minxend # TODO: should be ax[1] idx = np . argsort ( dat . x [ - 2 , 5 : ] ) idx2 = np . argsort ( idx ) if x_opt is None : dat . x [ - 1 , 5 + idx ] = np . linspace ( np . min ( dat . x [ : , 5 : ] ) , np . max ( dat . x [ : , 5 : ] ) , dat . x . shape [ 1 ] - 5 ) else : dat . x [ - 1 , 5 + idx ] = np . logspace ( np . log10 ( np . min ( abs ( dat . x [ : , 5 : ] ) ) ) , np . log10 ( np . max ( abs ( dat . x [ : , 5 : ] ) ) ) , dat . x . shape [ 1 ] - 5 ) else : minxend = 0 if len ( dat . f ) == 0 : print ( 'nothing to plot' ) return # not in use anymore, see formatter above # xticklocs = np.arange(5) * np.round(minxend/4., -int(np.log10(minxend/4.))) # dfit(dfit<1e-98) = NaN; ioff ( ) # turns update off # TODO: if abscissa==0 plot in chunks, ie loop over subsets where dat.f[:,0]==countiter is monotonous subplot ( 2 , 2 , 1 ) self . plotdivers ( dat , iabscissa , foffset ) # TODO: modularize also the remaining subplots subplot ( 2 , 2 , 2 ) hold ( False ) if x_opt is not None : # TODO: differentate neg and pos? semilogy ( dat . x [ : , iabscissa ] , abs ( dat . x [ : , 5 : ] ) - x_opt , '-' ) else : plot ( dat . x [ : , iabscissa ] , dat . x [ : , 5 : ] , '-' ) hold ( True ) grid ( True ) ax = array ( axis ( ) ) # ax[1] = max(minxend, ax[1]) axis ( ax ) ax [ 1 ] -= 1e-6 if dat . x . shape [ 1 ] < 100 : yy = np . linspace ( ax [ 2 ] + 1e-6 , ax [ 3 ] - 1e-6 , dat . x . shape [ 1 ] - 5 ) #yyl = np.sort(dat.x[-1,5:]) idx = np . argsort ( dat . x [ - 1 , 5 : ] ) idx2 = np . argsort ( idx ) if x_opt is not None : semilogy ( [ dat . x [ - 1 , iabscissa ] , ax [ 1 ] ] , [ abs ( dat . x [ - 1 , 5 : ] ) , yy [ idx2 ] ] , 'k-' ) # line from last data point semilogy ( np . dot ( dat . x [ - 2 , iabscissa ] , [ 1 , 1 ] ) , array ( [ ax [ 2 ] + 1e-6 , ax [ 3 ] - 1e-6 ] ) , 'k-' ) else : # plot([dat.x[-1, iabscissa], ax[1]], [dat.x[-1,5:], yy[idx2]], 'k-') # line from last data point plot ( np . dot ( dat . x [ - 2 , iabscissa ] , [ 1 , 1 ] ) , array ( [ ax [ 2 ] + 1e-6 , ax [ 3 ] - 1e-6 ] ) , 'k-' ) # plot(array([dat.x[-1, iabscissa], ax[1]]), #      reshape(array([dat.x[-1,5:], yy[idx2]]).flatten(), (2,4)), '-k') for i in range ( len ( idx ) ) : # TODOqqq: annotate phenotypic value!? # text(ax[1], yy[i], 'x(' + str(idx[i]) + ')=' + str(dat.x[-2,5+idx[i]])) text ( dat . x [ - 1 , iabscissa ] , dat . x [ - 1 , 5 + i ] , 'x(' + str ( i ) + ')=' + str ( dat . x [ - 2 , 5 + i ] ) ) i = 2 # find smallest i where iteration count differs (in case the same row appears twice) while i < len ( dat . f ) and dat . f [ - i ] [ 0 ] == dat . f [ - 1 ] [ 0 ] : i += 1 title ( 'Object Variables (' + ( 'mean' if plot_mean else 'curr best' ) + ', ' + str ( dat . x . shape [ 1 ] - 5 ) + '-D, popsize~' + ( str ( int ( ( dat . f [ - 1 ] [ 1 ] - dat . f [ - i ] [ 1 ] ) / ( dat . f [ - 1 ] [ 0 ] - dat . f [ - i ] [ 0 ] ) ) ) if len ( dat . f . T [ 0 ] ) > 1 and dat . f [ - 1 ] [ 0 ] > dat . f [ - i ] [ 0 ] else 'NA' ) + ')' ) # pylab.xticks(xticklocs) # Scaling subplot ( 2 , 2 , 3 ) hold ( False ) semilogy ( dat . D [ : , iabscissa ] , dat . D [ : , 5 : ] , '-b' ) hold ( True ) grid ( True ) ax = array ( axis ( ) ) # ax[1] = max(minxend, ax[1]) axis ( ax ) title ( 'Scaling (All Main Axes)' ) # pylab.xticks(xticklocs) xlabel ( xlab ) # standard deviations subplot ( 2 , 2 , 4 ) hold ( False ) # remove sigma from stds (graphs become much better readible) dat . std [ : , 5 : ] = np . transpose ( dat . std [ : , 5 : ] . T / dat . std [ : , 2 ] . T ) # ax = array(axis()) # ax[1] = max(minxend, ax[1]) # axis(ax) if 1 < 2 and dat . std . shape [ 1 ] < 100 : # use fake last entry in x and std for line extension-annotation minxend = int ( 1.06 * dat . x [ - 2 , iabscissa ] ) dat . std [ - 1 , iabscissa ] = minxend # TODO: should be ax[1] idx = np . argsort ( dat . std [ - 2 , 5 : ] ) idx2 = np . argsort ( idx ) dat . std [ - 1 , 5 + idx ] = np . logspace ( np . log10 ( np . min ( dat . std [ : , 5 : ] ) ) , np . log10 ( np . max ( dat . std [ : , 5 : ] ) ) , dat . std . shape [ 1 ] - 5 ) dat . std [ - 1 , iabscissa ] = minxend # TODO: should be ax[1] yy = np . logspace ( np . log10 ( ax [ 2 ] ) , np . log10 ( ax [ 3 ] ) , dat . std . shape [ 1 ] - 5 ) #yyl = np.sort(dat.std[-1,5:]) idx = np . argsort ( dat . std [ - 1 , 5 : ] ) idx2 = np . argsort ( idx ) # plot(np.dot(dat.std[-2, iabscissa],[1,1]), array([ax[2]+1e-6, ax[3]-1e-6]), 'k-') # vertical separator # vertical separator plot ( np . dot ( dat . std [ - 2 , iabscissa ] , [ 1 , 1 ] ) , array ( [ np . min ( dat . std [ - 2 , 5 : ] ) , np . max ( dat . std [ - 2 , 5 : ] ) ] ) , 'k-' ) hold ( True ) # plot([dat.std[-1, iabscissa], ax[1]], [dat.std[-1,5:], yy[idx2]], 'k-') # line from last data point for i in xrange ( len ( idx ) ) : # text(ax[1], yy[i], ' '+str(idx[i])) text ( dat . std [ - 1 , iabscissa ] , dat . std [ - 1 , 5 + i ] , ' ' + str ( i ) ) semilogy ( dat . std [ : , iabscissa ] , dat . std [ : , 5 : ] , '-' ) grid ( True ) title ( 'Standard Deviations in All Coordinates' ) # pylab.xticks(xticklocs) xlabel ( xlab ) draw ( ) # does not suffice if interactive_status : ion ( ) # turns interactive mode on (again) draw ( ) show ( ) return self