def plot(dsList, targets=None, craftingeffort=0., **kwargs): """This function is obsolete? Generates a graph of the run length distribution of an algorithm. We display the empirical cumulative distribution function ECDF of the bootstrapped distribution of the runlength for an algorithm (in number of function evaluations) to reach the target functions value :py:data:`targets`. :param DataSetList dsList: data set for one algorithm :param seq targets: target function values :param float crafting effort: the data will be multiplied by the exponential of this value :param dict kwargs: additional parameters provided to plot function. :returns: handles """ if targets is None: targets = target_values # set above or in config.py try: if np.min(targets) >= 1: ValueError( 'smallest target f-value is not smaller than one, use ``pproc.TargetValues(targets)`` to prevent this error' ) targets = pp.TargetValues(targets) except TypeError: pass res = [] assert len(pp.DataSetList( dsList).dictByDim()) == 1 # We never integrate over dimensions... data = [] maxevals = [] for entry in dsList: for t in targets((entry.funcId, entry.dim)): divisor = entry.dim if divide_by_dimension else 1 x = [np.inf] * perfprofsamplesize runlengthunsucc = [] evals = entry.detEvals([t])[0] runlengthsucc = evals[np.isnan(evals) == False] / divisor runlengthunsucc = entry.maxevals[np.isnan(evals)] / divisor if len(runlengthsucc) > 0: x = toolsstats.drawSP(runlengthsucc, runlengthunsucc, percentiles=[50], samplesize=perfprofsamplesize)[1] data.extend(x) maxevals.extend(runlengthunsucc) # Display data data = np.array(data) data = data[np.isnan(data) == False] # Take away the nans n = len(data) data = data[np.isinf(data) == False] # Take away the infs # data = data[data <= maxval] # Take away rightmost data data = np.exp(craftingeffort) * data # correction by crafting effort CrE if len(data) == 0: # data is empty. res = pprldistr.plotECDF(np.array((1., )), n=np.inf, **kwargs) else: res = pprldistr.plotECDF(np.array(data), n=n, **kwargs) #plotdata(np.array(data), x_limit, maxevals, # CrE=0., **kwargs) if maxevals: # Should cover the case where maxevals is None or empty x3 = np.median(maxevals) if np.any(data > x3): y3 = float(np.sum(data <= x3)) / n h = plt_plot((x3, ), (y3, ), marker='x', markersize=24, markeredgewidth=3, markeredgecolor=plt.getp(res[0], 'color'), ls='', color=plt.getp(res[0], 'color')) h.extend(res) res = h # so the last element in res still has the label. return res
def plotdata(data, maxval=None, maxevals=None, CrE=0., **kwargs): """Draw a normalized ECDF. What means normalized? :param seq data: data set, a 1-D ndarray of runlengths :param float maxval: right-most value to be displayed, will use the largest non-inf, non-nan value in data if not provided :param seq maxevals: if provided, will plot the median of this sequence as a single cross marker :param float CrE: Crafting effort the data will be multiplied by the exponential of this value. :param kwargs: optional arguments provided to plot function. """ #Expect data to be a ndarray. x = data[np.isnan(data) == False] # Take away the nans nn = len(x) x = x[np.isinf(x) == False] # Take away the infs n = len(x) x = np.exp(CrE) * x # correction by crafting effort CrE if n == 0: #res = plt.plot((1., ), (0., ), **kwargs) res = pprldistr.plotECDF(np.array((1., )), n=np.inf, **kwargs) else: dictx = {} # number of appearances of each value in x for i in x: dictx[i] = dictx.get(i, 0) + 1 x = np.array(sorted(dictx)) # x is not a multiset anymore y = np.cumsum(list( dictx[i] for i in x)) # cumsum of size of y-steps (nb of appearences) idx = sum(x <= x_limit**annotation_space_end_relative) - 1 y_last, x_last = y[idx] / float(nn), x[idx] if maxval is None: maxval = max(x) end = np.sum(x <= maxval) x = x[:end] y = y[:end] try: # plot the very last point outside of the "normal" plotting area c = kwargs['color'] plt_plot([x_last] * 2, [y_last] * 2, '.', color=c, markeredgecolor=c) except: pass x2 = np.hstack([np.repeat(x, 2), maxval]) # repeat x-values for each step in the cdf y2 = np.hstack([0.0, np.repeat(y / float(nn), 2)]) res = ppfig.plotUnifLogXMarkers(x2, y2, nbperdecade * 3 / np.log10(maxval), logscale=False, clip_on=False, **kwargs) # res = plotUnifLogXMarkers(x2, y2, nbperdecade, logscale=False, **kwargs) if maxevals: # Should cover the case where maxevals is None or empty x3 = np.median(maxevals) if (x3 <= maxval and # np.any(x2 <= x3) and # maxval < median(maxevals) not plt.getp(res[-1], 'label').startswith('best') ): # TODO: HACK for not considering the best 2009 line try: y3 = y2[x2 <= x3][ -1] # find right y-value for x3==median(maxevals) except IndexError: # median(maxevals) is smaller than any data, can only happen because of CrE? y3 = y2[0] h = plt.plot( (x3, ), (y3, ), marker=median_max_evals_marker_format[0], markersize=median_max_evals_marker_format[1], markeredgewidth=median_max_evals_marker_format[2], # marker='x', markersize=24, markeredgewidth=3, markeredgecolor=plt.getp(res[0], 'color'), ls=plt.getp(res[0], 'ls'), color=plt.getp(res[0], 'color')) h.extend(res) res = h # so the last element in res still has the label. # Only take sequences for x and y! return res
def plot(dsList, dsref, targets=defaulttargets, istoolsstats=False, **kwargs): """Generates a graph showing the performance profile of an algorithm. We display the empirical cumulative distribution function ECDF of the bootstrapped distribution of the expected running time (ERT) for an algorithm to reach the function value :py:data:`targets` normalized by the ERT of the reference algorithm for these targets. :param DataSetList dsList: data set for one algorithm :param DataSetList dsref: reference data set for normalization :param seq targets: target function values :param dict kwargs: additional parameters provided to plot function. :returns: handles """ res = [] assert len( dsList.dictByDim()) == 1 # We never integrate over dimensions... data = [] for entry in dsList: for t in targets: # TODO: alternative: min(dsref[(entry.dim, entry.funcId)].detEvals((t,))[0]) # is the min from the alg with the best ERT flg_ert = 1 if flg_ert: normalizer = dsref[(entry.dim, entry.funcId)].detERT((t, ))[0] else: pass if np.isinf(normalizer): continue if istoolsstats: x = [np.inf] * perfprofsamplesize runlengthunsucc = [] evals = entry.detEvals([t])[0] runlengthsucc = evals[np.isnan(evals) == False] runlengthunsucc = entry.maxevals[np.isnan(evals)] if len(runlengthsucc) > 0: x = toolsstats.drawSP(runlengthsucc, runlengthunsucc, percentiles=[50], samplesize=perfprofsamplesize)[1] data.extend(i / normalizer for i in x) else: x = entry.detERT([t])[0] data.append(x / normalizer) #if (np.array(tmp) < 1e-1).any(): # set_trace() # Display data data = np.array(data) data = data[np.isnan(data) == False] # Take away the nans n = len(data) data = data[np.isinf(data) == False] # Take away the infs # data = data[data <= maxval] # Take away rightmost data #data = np.exp(craftingeffort) * data # correction by crafting effort CrE #set_trace() if len(data) == 0: # data is empty. res = plotECDF(np.array((1., )), n=np.inf, **kwargs) else: plt.plot((min(data), ), (0, ), **kwargs) res = plotECDF(np.array(data), n=n, **kwargs) h = plt.plot((max(data), ), (float(len(data)) / n, ), **kwargs) plt.setp(h, 'marker', 'x') #plotdata(np.array(data), x_limit, maxevals, # CrE=0., kwargs=kwargs) # if maxevals: # Should cover the case where maxevals is None or empty # x3 = np.median(maxevals) # if np.any(data > x3): # y3 = float(np.sum(data <= x3)) / n # h = plt.plot((x3,), (y3,), marker='x', markersize=30, # markeredgecolor=plt.getp(res[0], 'color'), # ls='', color=plt.getp(res[0], 'color')) # h.extend(res) # res = h # so the last element in res still has the label. return res
def plot(dsList, dsref, targets=defaulttargets, istoolsstats=False, **kwargs): """Generates a graph showing the performance profile of an algorithm. We display the empirical cumulative distribution function ECDF of the bootstrapped distribution of the expected running time (ERT) for an algorithm to reach the function value :py:data:`targets` normalized by the ERT of the reference algorithm for these targets. :param DataSetList dsList: data set for one algorithm :param DataSetList dsref: reference data set for normalization :param seq targets: target function values :param dict kwargs: additional parameters provided to plot function. :returns: handles """ res = [] assert len(dsList.dictByDim()) == 1 # We never integrate over dimensions... data = [] for entry in dsList: for t in targets: # TODO: alternative: min(dsref[(entry.dim, entry.funcId)].detEvals((t,))[0]) # is the min from the alg with the best ERT flg_ert = 1 if flg_ert: normalizer = dsref[(entry.dim, entry.funcId)].detERT((t,))[0] else: pass if np.isinf(normalizer): continue if istoolsstats: x = [np.inf] * perfprofsamplesize runlengthunsucc = [] evals = entry.detEvals([t])[0] runlengthsucc = evals[np.isnan(evals) == False] runlengthunsucc = entry.maxevals[np.isnan(evals)] if len(runlengthsucc) > 0: x = toolsstats.drawSP(runlengthsucc, runlengthunsucc, percentiles=[50], samplesize=perfprofsamplesize)[1] data.extend(i/normalizer for i in x) else: x = entry.detERT([t])[0] data.append(x/normalizer) #if (np.array(tmp) < 1e-1).any(): # set_trace() # Display data data = np.array(data) data = data[np.isnan(data)==False] # Take away the nans n = len(data) data = data[np.isinf(data)==False] # Take away the infs # data = data[data <= maxval] # Take away rightmost data #data = np.exp(craftingeffort) * data # correction by crafting effort CrE #set_trace() if len(data) == 0: # data is empty. res = plotECDF(np.array((1., )), n=np.inf, **kwargs) else: plt.plot((min(data), ), (0, ), **kwargs) res = plotECDF(np.array(data), n=n, **kwargs) h = plt.plot((max(data), ), (float(len(data))/n, ), **kwargs) plt.setp(h, 'marker', 'x') #plotdata(np.array(data), x_limit, maxevals, # CrE=0., kwargs=kwargs) # if maxevals: # Should cover the case where maxevals is None or empty # x3 = np.median(maxevals) # if np.any(data > x3): # y3 = float(np.sum(data <= x3)) / n # h = plt.plot((x3,), (y3,), marker='x', markersize=30, # markeredgecolor=plt.getp(res[0], 'color'), # ls='', color=plt.getp(res[0], 'color')) # h.extend(res) # res = h # so the last element in res still has the label. return res
def plot(dsList, targets=None, craftingeffort=0., **kwargs): """This function is obsolete? Generates a graph of the run length distribution of an algorithm. We display the empirical cumulative distribution function ECDF of the bootstrapped distribution of the runlength for an algorithm (in number of function evaluations) to reach the target functions value :py:data:`targets`. :param DataSetList dsList: data set for one algorithm :param seq targets: target function values :param float crafting effort: the data will be multiplied by the exponential of this value :param dict kwargs: additional parameters provided to plot function. :returns: handles """ if targets is None: targets = target_values # set above or in config.py try: if np.min(targets) >= 1: ValueError('smallest target f-value is not smaller than one, use ``pproc.TargetValues(targets)`` to prevent this error') targets = pp.TargetValues(targets) except TypeError: pass res = [] assert len(pp.DataSetList(dsList).dictByDim()) == 1 # We never integrate over dimensions... data = [] maxevals = [] for entry in dsList: for t in targets((entry.funcId, entry.dim)): divisor = entry.dim if divide_by_dimension else 1 x = [np.inf] * perfprofsamplesize runlengthunsucc = [] evals = entry.detEvals([t])[0] runlengthsucc = evals[np.isnan(evals) == False] / divisor runlengthunsucc = entry.maxevals[np.isnan(evals)] / divisor if len(runlengthsucc) > 0: x = toolsstats.drawSP(runlengthsucc, runlengthunsucc, percentiles=[50], samplesize=perfprofsamplesize)[1] data.extend(x) maxevals.extend(runlengthunsucc) # Display data data = np.array(data) data = data[np.isnan(data)==False] # Take away the nans n = len(data) data = data[np.isinf(data)==False] # Take away the infs # data = data[data <= maxval] # Take away rightmost data data = np.exp(craftingeffort) * data # correction by crafting effort CrE if len(data) == 0: # data is empty. res = pprldistr.plotECDF(np.array((1., )), n=np.inf, **kwargs) else: res = pprldistr.plotECDF(np.array(data), n=n, **kwargs) #plotdata(np.array(data), x_limit, maxevals, # CrE=0., **kwargs) if maxevals: # Should cover the case where maxevals is None or empty x3 = np.median(maxevals) if np.any(data > x3): y3 = float(np.sum(data <= x3)) / n h = plt_plot((x3,), (y3,), marker='x', markersize=24, markeredgewidth=3, markeredgecolor=plt.getp(res[0], 'color'), ls='', color=plt.getp(res[0], 'color')) h.extend(res) res = h # so the last element in res still has the label. return res
def plotdata(data, maxval=None, maxevals=None, CrE=0., **kwargs): """Draw a normalized ECDF. What means normalized? :param seq data: data set, a 1-D ndarray of runlengths :param float maxval: right-most value to be displayed, will use the largest non-inf, non-nan value in data if not provided :param seq maxevals: if provided, will plot the median of this sequence as a single cross marker :param float CrE: Crafting effort the data will be multiplied by the exponential of this value. :param kwargs: optional arguments provided to plot function. """ #Expect data to be a ndarray. x = data[np.isnan(data)==False] # Take away the nans nn = len(x) x = x[np.isinf(x)==False] # Take away the infs n = len(x) x = np.exp(CrE) * x # correction by crafting effort CrE if n == 0: #res = plt.plot((1., ), (0., ), **kwargs) res = pprldistr.plotECDF(np.array((1., )), n=np.inf, **kwargs) else: dictx = {} # number of appearances of each value in x for i in x: dictx[i] = dictx.get(i, 0) + 1 x = np.array(sorted(dictx)) # x is not a multiset anymore y = np.cumsum(list(dictx[i] for i in x)) # cumsum of size of y-steps (nb of appearences) idx = sum(x <= x_limit**annotation_space_end_relative) - 1 y_last, x_last = y[idx] / float(nn), x[idx] if maxval is None: maxval = max(x) end = np.sum(x <= maxval) x = x[:end] y = y[:end] try: # plot the very last point outside of the "normal" plotting area c = kwargs['color'] plt_plot([x_last] * 2, [y_last] * 2, '.', color=c, markeredgecolor=c) except: pass x2 = np.hstack([np.repeat(x, 2), maxval]) # repeat x-values for each step in the cdf y2 = np.hstack([0.0, np.repeat(y / float(nn), 2)]) res = ppfig.plotUnifLogXMarkers(x2, y2, nbperdecade * 3 / np.log10(maxval), logscale=False, clip_on=False, **kwargs) # res = plotUnifLogXMarkers(x2, y2, nbperdecade, logscale=False, **kwargs) if maxevals: # Should cover the case where maxevals is None or empty x3 = np.median(maxevals) if (x3 <= maxval and # np.any(x2 <= x3) and # maxval < median(maxevals) not plt.getp(res[-1], 'label').startswith('best') ): # TODO: HACK for not considering the best 2009 line try: y3 = y2[x2<=x3][-1] # find right y-value for x3==median(maxevals) except IndexError: # median(maxevals) is smaller than any data, can only happen because of CrE? y3 = y2[0] h = plt.plot((x3,), (y3,), marker=median_max_evals_marker_format[0], markersize=median_max_evals_marker_format[1], markeredgewidth=median_max_evals_marker_format[2], # marker='x', markersize=24, markeredgewidth=3, markeredgecolor=plt.getp(res[0], 'color'), ls=plt.getp(res[0], 'ls'), color=plt.getp(res[0], 'color')) h.extend(res) res = h # so the last element in res still has the label. # Only take sequences for x and y! return res