(self, idx=100)
displays selected data from (files written by) the class `CMADataLogger`.

        Arguments
        ---------
           `idx`
               indices corresponding to rows in the data file;
               if idx is a scalar (int), the first two, then every idx-th,
               and the last three rows are displayed. Too large index values are removed.
               If ``len(idx) == 1``, only a single row is displayed, e.g. the last
               entry when ``idx == [-1]``.

        Example
        -------
        >>> import cma, numpy as np
        >>> res = cma.fmin(cma.fcts.elli, 7 * [0.1], 1, verb_disp=1e9)  # generate data
        >>> assert res[1] < 1e-9
        >>> assert res[2] < 4400
        >>> l = cma.CMADataLogger()  # == res[-1], logger with default name, "points to" above data
        >>> l.disp([0,-1])  # first and last
        >>> l.disp(20)  # some first/last and every 20-th line
        >>> l.disp(np.r_[0:999999:100, -1]) # every 100-th and last
        >>> l.disp(np.r_[0, -10:0]) # first and ten last
        >>> cma.disp(l.name_prefix, np.r_[0::100, -10:])  # the same as l.disp(...)

        Details
        -------
        The data line with the best f-value is displayed as last line.

        :See: `disp()`
displays selected data from (files written by) the class `CMADataLogger`.
displays selected data from ( files written by ) the class CMADataLogger .
def disp(self, idx=100):  # r_[0:5,1e2:1e9:1e2,-10:0]):
        """displays selected data from (files written by) the class `CMADataLogger`.

        Arguments
        ---------
           `idx`
               indices corresponding to rows in the data file;
               if idx is a scalar (int), the first two, then every idx-th,
               and the last three rows are displayed. Too large index values are removed.
               If ``len(idx) == 1``, only a single row is displayed, e.g. the last
               entry when ``idx == [-1]``.

        Example
        -------
        >>> import cma, numpy as np
        >>> res = cma.fmin(cma.fcts.elli, 7 * [0.1], 1, verb_disp=1e9)  # generate data
        >>> assert res[1] < 1e-9
        >>> assert res[2] < 4400
        >>> l = cma.CMADataLogger()  # == res[-1], logger with default name, "points to" above data
        >>> l.disp([0,-1])  # first and last
        >>> l.disp(20)  # some first/last and every 20-th line
        >>> l.disp(np.r_[0:999999:100, -1]) # every 100-th and last
        >>> l.disp(np.r_[0, -10:0]) # first and ten last
        >>> cma.disp(l.name_prefix, np.r_[0::100, -10:])  # the same as l.disp(...)

        Details
        -------
        The data line with the best f-value is displayed as last line.

        :See: `disp()`

        """

        filenameprefix=self.name_prefix

        def printdatarow(dat, iteration):
            """print data of iteration i"""
            i = np.where(dat.f[:, 0] == iteration)[0][0]
            j = np.where(dat.std[:, 0] == iteration)[0][0]
            print('%5d' % (int(dat.f[i,0])) + ' %6d' % (int(dat.f[i,1])) + ' %.14e' % (dat.f[i,5]) +
                  ' %5.1e' % (dat.f[i,3]) +
                  ' %6.2e' % (max(dat.std[j,5:])) + ' %6.2e' % min(dat.std[j,5:]))

        dat = CMADataLogger(filenameprefix).load()
        ndata = dat.f.shape[0]

        # map index to iteration number, is difficult if not all iteration numbers exist
        # idx = idx[np.where(map(lambda x: x in dat.f[:,0], idx))[0]] # TODO: takes pretty long
        # otherwise:
        if idx is None:
            idx = 100
        if np.isscalar(idx):
            # idx = np.arange(0, ndata, idx)
            if idx:
                idx = np.r_[0, 1, idx:ndata-3:idx, -3:0]
            else:
                idx = np.r_[0, 1, -3:0]

        idx = array(idx)
        idx = idx[idx<=ndata]  # TODO: shouldn't this be "<"?
        idx = idx[-idx<=ndata]
        iters = dat.f[idx, 0]
        idxbest = np.argmin(dat.f[:,5])
        iterbest = dat.f[idxbest, 0]
        if len(iters) == 1:
            printdatarow(dat, iters[0])
        else:
            self.disp_header()
            for i in iters:
                printdatarow(dat, i)
            self.disp_header()
            printdatarow(dat, iterbest)
        sys.stdout.flush()
def disp ( self , idx = 100 ) : # r_[0:5,1e2:1e9:1e2,-10:0]): filenameprefix = self . name_prefix def printdatarow ( dat , iteration ) : """print data of iteration i""" i = np . where ( dat . f [ : , 0 ] == iteration ) [ 0 ] [ 0 ] j = np . where ( dat . std [ : , 0 ] == iteration ) [ 0 ] [ 0 ] print ( '%5d' % ( int ( dat . f [ i , 0 ] ) ) + ' %6d' % ( int ( dat . f [ i , 1 ] ) ) + ' %.14e' % ( dat . f [ i , 5 ] ) + ' %5.1e' % ( dat . f [ i , 3 ] ) + ' %6.2e' % ( max ( dat . std [ j , 5 : ] ) ) + ' %6.2e' % min ( dat . std [ j , 5 : ] ) ) dat = CMADataLogger ( filenameprefix ) . load ( ) ndata = dat . f . shape [ 0 ] # map index to iteration number, is difficult if not all iteration numbers exist # idx = idx[np.where(map(lambda x: x in dat.f[:,0], idx))[0]] # TODO: takes pretty long # otherwise: if idx is None : idx = 100 if np . isscalar ( idx ) : # idx = np.arange(0, ndata, idx) if idx : idx = np . r_ [ 0 , 1 , idx : ndata - 3 : idx , - 3 : 0 ] else : idx = np . r_ [ 0 , 1 , - 3 : 0 ] idx = array ( idx ) idx = idx [ idx <= ndata ] # TODO: shouldn't this be "<"? idx = idx [ - idx <= ndata ] iters = dat . f [ idx , 0 ] idxbest = np . argmin ( dat . f [ : , 5 ] ) iterbest = dat . f [ idxbest , 0 ] if len ( iters ) == 1 : printdatarow ( dat , iters [ 0 ] ) else : self . disp_header ( ) for i in iters : printdatarow ( dat , i ) self . disp_header ( ) printdatarow ( dat , iterbest ) sys . stdout . flush ( )