def plotBarChartPerAlgorithmPerTerrain(data,
                                       dataErr=None,
                                       outfile="",
                                       yAxLabel="",
                                       plotTitle="",
                                       maxVal=0,
                                       legendPos='upper right'):
    assert (len(data) == len(AVAILABLE_ALGORITHMS))

    colors = ColorCyle()
    barWidth = 1.0 / (len(data) + 1)

    fig, ax = plt.subplots()
    ax.set_ylabel(yAxLabel)
    ax.set_title(plotTitle)

    if maxVal > 0:
        ax.set_autoscaley_on(False)
        ax.set_ylim([0, maxVal])

    for algoCount, algoName in enumerate(AVAILABLE_ALGORITHMS):
        algoData = data[algoName]
        algoErr = None
        if dataErr != None:
            algoErr = dataErr[algoName]

        leftBorders = [
            i + (algoCount * barWidth) for i in xrange(len(algoData))
        ]
        rects = ax.bar(leftBorders,
                       algoData,
                       yerr=algoErr,
                       width=barWidth,
                       label=ALGORITHM_NAMES[algoName],
                       color=colors.next())
        # add value label on top of bars
        for rect in rects:
            barHeight = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() / 2.0,
                    1.0 * barHeight,
                    '%.1f' % barHeight,
                    ha='center',
                    va='bottom')

    ax.set_xticks([(i + (len(data) * barWidth) / 2)
                   for i in xrange(len(AVAILABLE_WORLDS))])
    ax.set_xticklabels(getWorldNames())
    ax.legend(loc=legendPos)

    fig.set_size_inches(9.6, 5.4)

    if len(outfile) > 0:
        plt.savefig(outfile, dpi=100)
    else:
        plt.show()
Example #2
0
def plot_ranking(rankings, optimum=0, title="", log=False,
                 save="", y_min=0, y_max=0, figsize=(16, 6), legend_ncols=4,
                 colors=None, markers=None, markersize=6, linewidth=3):
    # check if all optimizers have the same number of runs
    # if np.mean([name[1] for name in name_list]) != name_list[0][1]:
    #    raise Exception("All optimizers must have the same numbers of "
    #                    "experiment runs! %s" % name_list)


    fig = plt.figure(dpi=600, figsize=figsize)
    ax = plt.subplot(111)

    if colors is None:
        colors = plot_util.get_plot_colors()
    if markers is None:
        markers = plot_util.get_empty_iterator()

    for i, optimizer in enumerate(rankings):
        ax.plot(range(0, rankings[optimizer].shape[0]),
                rankings[optimizer],
                marker=markers.next(), markersize=markersize,
                color=colors.next(), linewidth=linewidth,
                label=optimizer.replace("\\", "").
                replace("learned", "d_c").replace("l1", "d_p"))

    ax.legend(loc='upper center',  #bbox_to_anchor=(0.5, -0.05),
              fancybox=True, shadow=True, ncol=legend_ncols,
              labelspacing=0.25, fontsize=12)
    ax.set_xlabel("#Function evaluations")
    ax.set_ylabel("Average rank")
    box = ax.get_position()

    #ax.set_position([box.x0, box.y0 + box.height * 0.1,
    #                 box.width, box.height * 0.9])

    if save != "":
        plt.savefig(save, facecolor='w', edgecolor='w',
                    orientation='portrait', papertype=None, format=None,
                    transparent=False, bbox_inches="tight", pad_inches=0.1)
    else:
        plt.show()
    plt.close(fig)
Example #3
0
    # linFitYvals=np.empty(len(xValsToFit))
    # linFitYvals.fill(np.NAN)
    #
    # j=0
    # for i in xValsToFit:
    #   linFitYvals[j] = M*i + b
    #   j+=1

    #############
    # Plot Things
    #############
    qDataPI = np.array([convertQ(qq, trackLength) for qq in range(0, qLen)])
    maxQrad = convertQ(maxQ, trackLength)
    ax1 = plt.subplot(211)
    m = markers.next()
    c = colors.next()
    ax1.plot(qDataPI,
             convertW(fitFWHM / 2.0, fftSamples),
             color=c,
             linestyle='',
             marker=m,
             label=densityString)
    #ax1.plot(qDataPI,convertW(fitFWHM/2.0,fftSamples),color=c,linestyle='',marker=m,label=trackString)
    # plt.plot(gamma,convertW(fitFWHM,fftSamples)/2.0,'g.')
    # plt.plot(gamma,gamma,'b')
    #plt.plot(xValsToFit,linFitYvals,'k-')

    ax1.set_title('Free peak in each q slice\n' + infoText)

    ax1.set_ylabel('HWHM (rad / time step)', fontsize=16)
    #ymax = np.nanmax(convertW(fitFWHM,fftSamples))/2*1.1
def plotBarChartPerTerrainPerAlgorithm(data, dataErr=None, outfile="", yAxLabel="", plotTitle="", maxVal=0, legendPos='upper right'):
    assert(len(data) == len(AVAILABLE_WORLDS))
    
    colors = ColorCyle()
    barWidth = 1.0 / (len(data) + 1)
    
    fig, ax = plt.subplots()
    ax.set_ylabel(yAxLabel)
    ax.set_title(plotTitle)
    
    if maxVal > 0:
        ax.set_autoscaley_on(False)
        ax.set_ylim([0,maxVal])
    
    for worldCount, worldName in enumerate(AVAILABLE_WORLDS):
        worldData = data[worldName]
        worldErr = None
        if dataErr != None:
            worldErr = dataErr[worldName]
            
        leftBorders = [i + (worldCount * barWidth) for i in xrange(len(worldData))]
        rects = ax.bar(leftBorders, worldData, yerr=worldErr, width=barWidth, label=WORLD_NAMES[worldName], color=colors.next())
        # add value label on top of bars
        for rect in rects:
            barHeight = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() / 2.0, 1.0 * barHeight, '%.1f'%barHeight,
                    ha='center', va='bottom')
            
    ax.set_xticks([(i + (len(data) * barWidth) / 2) for i in xrange(len(AVAILABLE_ALGORITHMS))])
    ax.set_xticklabels(getAlgorithmNames())
    ax.legend(loc=legendPos)
    
    fig.set_size_inches(9.6,5.4)
    
    if len(outfile) > 0:
        plt.savefig(outfile, dpi=100)
    else:
        plt.show()    
def plotBarChartPerRobotCountPerAlgorithm(data, dataErr=None, outfile="", yAxLabel="", plotTitle="", maxVal=0, legendPos='upper right'):
    assert(len(data) == len(AVAILABLE_ROBOT_COUNTS))
    
    colors = ColorCyle()
    barWidth = 1.0 / (len(data) + 1)
    
    fig, ax = plt.subplots()
    ax.set_ylabel(yAxLabel)
    ax.set_title(plotTitle)
    
    if maxVal > 0:
        ax.set_autoscaley_on(False)
        ax.set_ylim([0,maxVal])
    
    for robotNum, robotCount in enumerate(AVAILABLE_ROBOT_COUNTS):
        robotCountData = data[robotCount]
        robotCountErr = None
        if dataErr != None:
            robotCountErr = dataErr[robotCount]
            
        leftBorders = [i + (robotNum * barWidth) for i in xrange(len(robotCountData))]
        
        labelStr = ""
        if robotCount == 1:
            labelStr = "1 Robot"
        else:
            labelStr = str(robotCount) + " Robots"
        rects = ax.bar(leftBorders, robotCountData, yerr=robotCountErr, width=barWidth, label=labelStr, color=colors.next())
        # add value label on top of bars
        for rect in rects:
            barHeight = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() / 2.0, 1.0 * barHeight, '%.1f'%barHeight,
                    ha='center', va='bottom')
            
    ax.set_xticks([(i + (len(data) * barWidth) / 2) for i in xrange(len(AVAILABLE_ALGORITHMS))])
    ax.set_xticklabels(getAlgorithmNames())
    ax.legend(loc=legendPos)
    
    fig.set_size_inches(9.6,5.4)
        
    if len(outfile) > 0:
        plt.savefig(outfile, dpi=100)
    else:
        plt.show() 
def plot_ranking(rankings,
                 optimum=0,
                 title="",
                 log=False,
                 save="",
                 y_min=0,
                 y_max=0,
                 figsize=(16, 6),
                 legend_ncols=4,
                 colors=None,
                 markers=None,
                 markersize=6,
                 linewidth=3):
    # check if all optimizers have the same number of runs
    # if np.mean([name[1] for name in name_list]) != name_list[0][1]:
    #    raise Exception("All optimizers must have the same numbers of "
    #                    "experiment runs! %s" % name_list)

    fig = plt.figure(dpi=600, figsize=figsize)
    ax = plt.subplot(111)

    if colors is None:
        colors = plot_util.get_plot_colors()
    if markers is None:
        markers = plot_util.get_empty_iterator()

    for i, optimizer in enumerate(rankings):
        ax.plot(range(0, rankings[optimizer].shape[0]),
                rankings[optimizer],
                marker=markers.next(),
                markersize=markersize,
                color=colors.next(),
                linewidth=linewidth,
                label=optimizer.replace("\\", "").replace("learned",
                                                          "d_c").replace(
                                                              "l1", "d_p"))

    ax.legend(
        loc='upper center',  #bbox_to_anchor=(0.5, -0.05),
        fancybox=True,
        shadow=True,
        ncol=legend_ncols,
        labelspacing=0.25,
        fontsize=12)
    ax.set_xlabel("#Function evaluations")
    ax.set_ylabel("Average rank")
    box = ax.get_position()

    #ax.set_position([box.x0, box.y0 + box.height * 0.1,
    #                 box.width, box.height * 0.9])

    if save != "":
        plt.savefig(save,
                    facecolor='w',
                    edgecolor='w',
                    orientation='portrait',
                    papertype=None,
                    format=None,
                    transparent=False,
                    bbox_inches="tight",
                    pad_inches=0.1)
    else:
        plt.show()
    plt.close(fig)
def plot_summed_wins_of_optimizers(trial_list_per_dataset,
                                   name_list_per_dataset,
                                   save="",
                                   cut=sys.maxint,
                                   figsize=(16, 4),
                                   legend_ncols=3,
                                   colors=None,
                                   linewidth=3,
                                   markers=None,
                                   markersize=6):
    # TODO colors should be a function handle which returns an Iterable!

    # This is a hack
    cut = 50
    optimizers, summed_wins_of_optimizer = get_summed_wins_of_optimizers(
        trial_list_per_dataset, name_list_per_dataset)

    # Make a copy of the colors iterator, because we need it more than once!
    if colors is not None:
        if not isinstance(colors, itertools.cycle):
            raise TypeError()
        else:
            color_values = list()
            for i in range(10):
                r, g, b = colors.next()
                color_values.append((r, g, b))

    if markers is not None:
        if not isinstance(markers, itertools.cycle):
            raise TypeError()
        else:
            marker_values = list()
            for i in range(10):
                marker_values.append(markers.next())

    ################################################################################
    # Plot statistics
    for opt1_idx, key in enumerate(optimizers):
        fig, (ax0, ax1) = plt.subplots(nrows=2,
                                       sharex=True,
                                       dpi=600,
                                       figsize=figsize)

        if colors is None:
            colors_ = plot_util.get_plot_colors()
        else:
            colors_ = itertools.cycle(color_values)

        if markers is None:
            markers_ = plot_util.get_empty_iterator()
        else:
            markers_ = itertools.cycle(marker_values)

        y_max = 0.

        for opt2_idx, key2 in enumerate(optimizers):
            if opt1_idx == opt2_idx:
                continue

            y = []
            y1 = []
            for i in range(0, cut + 1):
                y.append(summed_wins_of_optimizer[i][opt1_idx, opt2_idx] /
                         len(trial_list_per_dataset) * 100)
                y1.append(-summed_wins_of_optimizer[i][opt2_idx, opt1_idx] /
                          len(trial_list_per_dataset) * 100)

            y_max_tmp = max(np.max(y), np.max(np.abs(y1)))
            y_max_tmp = np.ceil(y_max_tmp * 10) / 10.
            y_max = max(y_max_tmp, y_max)

            label = "%s vs %s" % (key, key2)
            label = label.replace("learned", "d_c").replace("l1", "d_p")
            color = colors_.next()
            marker = markers_.next()
            ax0.plot(range(0, cut + 1),
                     y,
                     color=color,
                     label=label,
                     linewidth=linewidth,
                     marker=marker,
                     markersize=markersize)
            ax1.plot(range(0, cut + 1),
                     y1,
                     color=color,
                     label=label,
                     linewidth=linewidth,
                     marker=marker,
                     markersize=markersize)

        #handles, labels = ax1.get_legend_handles_labels()
        #fig.legend(handles, labels, loc="upper center", fancybox=True,
        #           ncol=legend_ncols, shadow=True)

        ax0.set_xlim((0, cut))
        ax0.set_ylim((0, y_max))
        ax0.set_ylabel("Significant wins (%)")
        ax1.set_xlim((0, cut))
        ax1.set_ylim((-y_max, 0))
        ax1.set_ylabel("Significant losses (%)")
        yticklabels = ax1.get_yticks().tolist()
        #print yticklabels, [item.get_text() for item in yticklabels]
        ax1.set_yticklabels([-int(item) for item in yticklabels])

        ax1.legend(loc="best", fancybox=True, ncol=legend_ncols, shadow=True)

        plt.tight_layout()
        #plt.subplots_adjust(top=0.85)
        plt.xlabel("#Function evaluations")
        if save != "":
            plt.savefig(save % key,
                        facecolor='w',
                        edgecolor='w',
                        orientation='portrait',
                        papertype=None,
                        format=None,
                        transparent=False,
                        bbox_inches="tight",
                        pad_inches=0.1)
        else:
            plt.show()
        plt.close(fig)
Example #8
0
def plot_summed_wins_of_optimizers(trial_list_per_dataset,
                                   name_list_per_dataset,
                                   save="",  cut=sys.maxint,
                                   figsize=(16, 4), legend_ncols=3,
                                   colors=None, linewidth=3,
                                   markers=None, markersize=6):
    # TODO colors should be a function handle which returns an Iterable!

    # This is a hack
    cut = 50
    optimizers, summed_wins_of_optimizer = get_summed_wins_of_optimizers(
        trial_list_per_dataset, name_list_per_dataset)

    # Make a copy of the colors iterator, because we need it more than once!
    if colors is not None:
        if not isinstance(colors, itertools.cycle):
            raise TypeError()
        else:
            color_values = list()
            for i in range(10):
                r, g, b = colors.next()
                color_values.append((r, g, b))

    if markers is not None:
        if not isinstance(markers, itertools.cycle):
            raise TypeError()
        else:
            marker_values = list()
            for i in range(10):
                marker_values.append(markers.next())

    ################################################################################
    # Plot statistics
    for opt1_idx, key in enumerate(optimizers):
        fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True, dpi=600,
                                       figsize=figsize)

        if colors is None:
            colors_ = plot_util.get_plot_colors()
        else:
            colors_ = itertools.cycle(color_values)

        if markers is None:
            markers_ = plot_util.get_empty_iterator()
        else:
            markers_ = itertools.cycle(marker_values)

        y_max = 0.

        for opt2_idx, key2 in enumerate(optimizers):
            if opt1_idx == opt2_idx:
                continue

            y = []
            y1 = []
            for i in range(0, cut+1):
                y.append(summed_wins_of_optimizer[i][opt1_idx, opt2_idx]
                         / len(trial_list_per_dataset) * 100)
                y1.append(- summed_wins_of_optimizer[i][opt2_idx, opt1_idx]
                          / len(trial_list_per_dataset) * 100)

            y_max_tmp = max(np.max(y), np.max(np.abs(y1)))
            y_max_tmp = np.ceil(y_max_tmp * 10) / 10.
            y_max = max(y_max_tmp, y_max)

            label = "%s vs %s" % (key, key2)
            label = label.replace("learned", "d_c").replace("l1", "d_p")
            color = colors_.next()
            marker = markers_.next()
            ax0.plot(range(0, cut+1), y, color=color, label=label,
                     linewidth=linewidth, marker=marker, markersize=markersize)
            ax1.plot(range(0, cut+1), y1, color=color, label=label,
                     linewidth=linewidth, marker=marker, markersize=markersize)

        #handles, labels = ax1.get_legend_handles_labels()
        #fig.legend(handles, labels, loc="upper center", fancybox=True,
        #           ncol=legend_ncols, shadow=True)

        ax0.set_xlim((0, cut))
        ax0.set_ylim((0, y_max))
        ax0.set_ylabel("Significant wins (%)")
        ax1.set_xlim((0, cut))
        ax1.set_ylim((-y_max, 0))
        ax1.set_ylabel("Significant losses (%)")
        yticklabels = ax1.get_yticks().tolist()
        #print yticklabels, [item.get_text() for item in yticklabels]
        ax1.set_yticklabels([-int(item) for item in yticklabels])

        ax1.legend(loc="best", fancybox=True, ncol=legend_ncols, shadow=True)

        plt.tight_layout()
        #plt.subplots_adjust(top=0.85)
        plt.xlabel("#Function evaluations")
        if save != "":
            plt.savefig(save % key, facecolor='w', edgecolor='w',
                        orientation='portrait', papertype=None, format=None,
                        transparent=False, bbox_inches="tight", pad_inches=0.1)
        else:
            plt.show()
        plt.close(fig)
def plotBarChartPerRobotCountPerAlgorithm(data,
                                          dataErr=None,
                                          outfile="",
                                          yAxLabel="",
                                          plotTitle="",
                                          maxVal=0,
                                          legendPos='upper right'):
    assert (len(data) == len(AVAILABLE_ROBOT_COUNTS))

    colors = ColorCyle()
    barWidth = 1.0 / (len(data) + 1)

    fig, ax = plt.subplots()
    ax.set_ylabel(yAxLabel)
    ax.set_title(plotTitle)

    if maxVal > 0:
        ax.set_autoscaley_on(False)
        ax.set_ylim([0, maxVal])

    for robotNum, robotCount in enumerate(AVAILABLE_ROBOT_COUNTS):
        robotCountData = data[robotCount]
        robotCountErr = None
        if dataErr != None:
            robotCountErr = dataErr[robotCount]

        leftBorders = [
            i + (robotNum * barWidth) for i in xrange(len(robotCountData))
        ]

        labelStr = ""
        if robotCount == 1:
            labelStr = "1 Robot"
        else:
            labelStr = str(robotCount) + " Robots"
        rects = ax.bar(leftBorders,
                       robotCountData,
                       yerr=robotCountErr,
                       width=barWidth,
                       label=labelStr,
                       color=colors.next())
        # add value label on top of bars
        for rect in rects:
            barHeight = rect.get_height()
            ax.text(rect.get_x() + rect.get_width() / 2.0,
                    1.0 * barHeight,
                    '%.1f' % barHeight,
                    ha='center',
                    va='bottom')

    ax.set_xticks([(i + (len(data) * barWidth) / 2)
                   for i in xrange(len(AVAILABLE_ALGORITHMS))])
    ax.set_xticklabels(getAlgorithmNames())
    ax.legend(loc=legendPos)

    fig.set_size_inches(9.6, 5.4)

    if len(outfile) > 0:
        plt.savefig(outfile, dpi=100)
    else:
        plt.show()