Example #1
0
def plotPerfSizeDist(foldername):
    rs = ReadSetupFile()
    dicoCost = {}
 
    for i in range(len(rs.sizeOfTarget)):
        name =  rs.CMAESpath + str(rs.sizeOfTarget[i]) + "/" + foldername + "/Cost/"

        costs = getCostData(name)

        for k, v in costs.items():
            for j in range(len(v)):
                distance = round(rs.getDistanceToTarget(v[j][0],v[j][1]),2)
                if not distance in dicoCost.keys():
                    dicoCost[distance] = {}
                if not rs.sizeOfTarget[i] in dicoCost[distance].keys():
                    dicoCost[distance][rs.sizeOfTarget[i]] = []
                dicoCost[distance][rs.sizeOfTarget[i]].append(v[j][2])

    plotTab = []
    fig = plt.figure(1, figsize=(16,9))
    plt.ylabel("performance")
    plt.xlabel("Target size (mm)")
    for key in sorted(dicoCost.keys()):
        plotTab.append(plt.plot([i for i in sorted(dicoCost[key].keys())], [np.mean(dicoCost[key][i]) for i in sorted(dicoCost[key].keys())], label = str("Distance: " + str(key))))
    plt.legend(loc = 0)
    plt.savefig("ImageBank/perfdist"+foldername+".png", bbox_inches='tight')
    plt.show(block = True)
Example #2
0
def plotPerfSizeDist(foldername):
    rs = ReadSetupFile()
    dicoCost = {}

    for i in range(len(rs.sizeOfTarget)):
        name = rs.CMAESpath + str(
            rs.sizeOfTarget[i]) + "/" + foldername + "/Cost/"

        costs = getCostData(name)

        for k, v in costs.items():
            for j in range(len(v)):
                distance = round(rs.getDistanceToTarget(v[j][0], v[j][1]), 2)
                if not distance in dicoCost.keys():
                    dicoCost[distance] = {}
                if not rs.sizeOfTarget[i] in dicoCost[distance].keys():
                    dicoCost[distance][rs.sizeOfTarget[i]] = []
                dicoCost[distance][rs.sizeOfTarget[i]].append(v[j][2])

    plotTab = []
    fig = plt.figure(1, figsize=(16, 9))
    plt.ylabel("performance")
    plt.xlabel("Target size (mm)")
    for key in sorted(dicoCost.keys()):
        plotTab.append(
            plt.plot([i for i in sorted(dicoCost[key].keys())], [
                np.mean(dicoCost[key][i]) for i in sorted(dicoCost[key].keys())
            ],
                     label=str("Distance: " + str(key))))
    plt.legend(loc=0)
    plt.savefig("ImageBank/perfdist" + foldername + ".png",
                bbox_inches='tight')
    plt.show(block=True)
Example #3
0
def plotCostColorMap(what, foldername = "None", targetSize = "All"):
    '''
    Cette fonction permet d'afficher le profil de cout des trajectoires
    
    Entrees:  -what: choix des donnees a afficher
    '''
    rs = ReadSetupFile()
    fig = plt.figure(1, figsize=(16,9))

    if what == "CMAES" and targetSize == "All":
        for i in range(len(rs.sizeOfTarget)):
            ax = plt.subplot2grid((2,2), (i/2,i%2))
            name =  rs.CMAESpath + str(rs.sizeOfTarget[i]) + "/" + foldername + "/Cost/"
            costs = getCostData(name)

            x0 = []
            y0 = []
            cost = []

            for k, v in costs.items():
                for j in range(len(v)):
                    x0.append(v[j][0])
                    y0.append(v[j][1])
                    cost.append(v[j][2])

            xi = np.linspace(-0.4,0.4,100)
            yi = np.linspace(0.12,0.58,100)
            zi = griddata(x0, y0, cost, xi, yi)

            t1 = ax.scatter(x0, y0, c=cost, marker=u'o', s=5, cmap=cm.get_cmap('RdYlBu'))
            ax.scatter(rs.XTarget, rs.YTarget, c ='g', marker='v', s=200)
            CS = ax.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
            fig.colorbar(t1, shrink=0.5, aspect=5)
            t1 = ax.scatter(x0, y0, c='b', marker=u'o', s=20)
            ax.set_xlabel("X (m)")
            ax.set_ylabel("Y (m)")
            ax.set_title(str("Cost map for target " + str(rs.sizeOfTarget[i])))

    else:
        if what == "CMAES":
            name = rs.CMAESpath + targetSize + "/" + foldername + "/Cost/"
        elif what == "Brent":
            name = BrentTrajectoriesFolder
        else:
            name = rs.NNpath + foldername + "/Cost/"

        costs = getCostData(name)
   
        x0 = []
        y0 = []
        cost = []

        for k, v in costs.items():
            for j in range(len(v)):
                x0.append(v[j][0])
                y0.append(v[j][1])
                cost.append(v[j][2])

        xi = np.linspace(-0.4,0.4,100)
        yi = np.linspace(0.12,0.58,100)
        zi = griddata(x0, y0, cost, xi, yi)
    
        t1 = plt.scatter(x0, y0, c=cost, marker=u'o', s=5, cmap=cm.get_cmap('RdYlBu'))
        plt.scatter(rs.XTarget, rs.YTarget, c ='g', marker='v', s=200)
        CS = plt.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
        fig.colorbar(t1, shrink=0.5, aspect=5)
        t1 = plt.scatter(x0, y0, c='b', marker=u'o', s=20)
        plt.xlabel("X (m)")
        plt.ylabel("Y (m)")
        plt.title("Cost map for " + what)

    plt.savefig("ImageBank/"+what+'_costmap'+foldername+'.png', bbox_inches='tight')
    plt.show(block = True)
Example #4
0
def plotCostColorMap(what, foldername="None", targetSize="All"):
    '''
    Cette fonction permet d'afficher le profil de cout des trajectoires
    
    Entrees:  -what: choix des donnees a afficher
    '''
    rs = ReadSetupFile()
    fig = plt.figure(1, figsize=(16, 9))

    if what == "CMAES" and targetSize == "All":
        for i in range(len(rs.sizeOfTarget)):
            ax = plt.subplot2grid((2, 2), (i / 2, i % 2))
            name = rs.CMAESpath + str(
                rs.sizeOfTarget[i]) + "/" + foldername + "/Cost/"
            costs = getCostData(name)

            x0 = []
            y0 = []
            cost = []

            for k, v in costs.items():
                for j in range(len(v)):
                    x0.append(v[j][0])
                    y0.append(v[j][1])
                    cost.append(v[j][2])

            xi = np.linspace(-0.4, 0.4, 100)
            yi = np.linspace(0.12, 0.58, 100)
            zi = griddata(x0, y0, cost, xi, yi)

            t1 = ax.scatter(x0,
                            y0,
                            c=cost,
                            marker=u'o',
                            s=5,
                            cmap=cm.get_cmap('RdYlBu'))
            ax.scatter(rs.XTarget, rs.YTarget, c='g', marker='v', s=200)
            CS = ax.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
            fig.colorbar(t1, shrink=0.5, aspect=5)
            t1 = ax.scatter(x0, y0, c='b', marker=u'o', s=20)
            ax.set_xlabel("X (m)")
            ax.set_ylabel("Y (m)")
            ax.set_title(str("Cost map for target " + str(rs.sizeOfTarget[i])))

    else:
        if what == "CMAES":
            name = rs.CMAESpath + targetSize + "/" + foldername + "/Cost/"
        elif what == "Brent":
            name = BrentTrajectoriesFolder
        else:
            name = rs.RBFNpath + foldername + "/Cost/"

        costs = getCostData(name)

        x0 = []
        y0 = []
        cost = []

        for k, v in costs.items():
            for j in range(len(v)):
                x0.append(v[j][0])
                y0.append(v[j][1])
                cost.append(v[j][2])

        xi = np.linspace(-0.4, 0.4, 100)
        yi = np.linspace(0.12, 0.58, 100)
        zi = griddata(x0, y0, cost, xi, yi)

        t1 = plt.scatter(x0,
                         y0,
                         c=cost,
                         marker=u'o',
                         s=5,
                         cmap=cm.get_cmap('RdYlBu'))
        plt.scatter(rs.XTarget, rs.YTarget, c='g', marker='v', s=200)
        CS = plt.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
        fig.colorbar(t1, shrink=0.5, aspect=5)
        t1 = plt.scatter(x0, y0, c='b', marker=u'o', s=20)
        plt.xlabel("X (m)")
        plt.ylabel("Y (m)")
        plt.title("Cost map for " + what)

    plt.savefig("ImageBank/" + what + '_costmap' + foldername + '.png',
                bbox_inches='tight')
    plt.show(block=True)
Example #5
0
def plotCostColorMapFor12(what, rs, foldername = "None", targetSize = "All"):
    '''
    Cette fonction permet d'afficher le profil de cout des muscles 1 et 2 des trajectoires
    
    Entrees:  -what: choix des donnees a afficher
    '''
    fig = plt.figure(1, figsize=(16,9))

    if what == "OPTI" and targetSize == "All":
        for i in range(len(rs.target_size)):
            ax = plt.subplot2grid((2,2), (i/2,i%2))
            name =  rs.OPTIpath + str(rs.target_size[i]) + "/" + foldername + "/CostU12/"
            costs = getCostData(name)

            x0 = []
            y0 = []
            cost = []

            for _, v in costs.items():
                for j in range(len(v)):
                    x0.append(v[j][0])
                    y0.append(v[j][1])
                    cost.append(v[j][2])

            xi = np.linspace(-0.4,0.4,100)
            yi = np.linspace(0.12,0.58,100)
            zi = griddata(x0, y0, cost, xi, yi)

            t1 = ax.scatter(x0, y0, c=cost, marker=u'o', s=5, cmap=cm.get_cmap('RdYlBu'))
            ax.scatter(rs.XTarget, rs.YTarget, c ='g', marker='v', s=200)
            ax.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
            fig.colorbar(t1, shrink=0.5, aspect=5)
            t1 = ax.scatter(x0, y0, c='b', marker=u'o', s=20)
            ax.set_xlabel("X (m)")
            ax.set_ylabel("Y (m)")
            ax.set_title(str("Cost map U 1 and 2 for target " + str(rs.target_size[i])))
        imageFolder = rs.OPTIpath + "/ImageBank/"

    else:
        if what == "OPTI":
            name = rs.OPTIpath + targetSize + "/" + foldername + "/CostU12/"
            imageFolder = rs.OPTIpath + "/ImageBank/"
        elif what == "Brent":
            name = BrentTrajectoriesFolder
            imageFolder = "ImageBank/"
        else:
            name = rs.path + foldername + "/CostU12/"
            imageFolder = rs.path + "/ImageBank/"

        costs = getCostData(name)
   
        x0 = []
        y0 = []
        cost = []

        for _, v in costs.items():
            for j in range(len(v)):
                x0.append(v[j][0])
                y0.append(v[j][1])
                cost.append(v[j][2])

        xi = np.linspace(-0.4,0.4,100)
        yi = np.linspace(0.12,0.58,100)
        zi = griddata(x0, y0, cost, xi, yi)
    
        t1 = plt.scatter(x0, y0, c=cost, marker=u'o', s=5, cmap=cm.get_cmap('RdYlBu'))
        plt.scatter(rs.XTarget, rs.YTarget, c ='g', marker='v', s=200)
        plt.contourf(xi, yi, zi, 15, cmap=cm.get_cmap('RdYlBu'))
        fig.colorbar(t1, shrink=0.5, aspect=5)
        t1 = plt.scatter(x0, y0, c='b', marker=u'o', s=20)
        plt.xlabel("X (m)")
        plt.ylabel("Y (m)")
        plt.title("Cost map U 1 and 2 for " + what)

    checkIfFolderExists(imageFolder)  
    plt.savefig(imageFolder+'costmapU.svg', bbox_inches='tight')
    plt.show(block = True)