示例#1
0
def plot(js):

    fig, ax = plt.subplots(2,2,num='Korali Results', figsize=(8,8))
    solver = js['Generations'][0]['Solver']['Type']
    numdim = len(js['Variables'])
    names  = [ js['Variables'][i]['Name'] for i in range(numdim) ]
    
    fval = []
    objVec = []
    dfval = []
    gen = []
    width = []
    means = []

    for s in js['Generations']:
     objVec.append(s['Solver']['Internal']['Current Best Variables'])
     fval.append(s['Solver']['Internal']['Current Best Value'])
     dfval.append(abs(s['Solver']['Internal']['Current Best Value'] - s['Solver']['Internal']['Best Ever Value']))
     gen.append(s['Internal']['Current Generation'])
     width.append(s['Solver']['Internal']['Max Distances'])
     means.append(s['Solver']['Internal']['Current Mean'])

    plt.suptitle('DEA Diagnostics', fontweight='bold', fontsize=12 )
    colors = hlsColors(numdim)
    
    # Upper Left Plot
    ax[0,0].grid(True)
    ax[0,0].set_yscale('log')
    drawMulticoloredLine(ax[0,0], gen, fval, 0.0, 'r', 'b', '$| F |$')
    ax[0,0].plot(gen, dfval, 'x', color = '#34495e', label = '$| F - F_{best} |$')
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0,0].legend(bbox_to_anchor=(0,1.00,1,0.2), loc="lower left", mode="expand", ncol = 3, handlelength=1, fontsize = 8)

    # Upper Right Plot
    ax[0,1].set_title('Objective Variables')
    ax[0,1].grid(True)
    for i in range(numdim):
        ax[0,1].plot(gen, objVec, color = colors[i], label=names[i])
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0,1].legend(bbox_to_anchor=(1.04,0.5), loc="center left", borderaxespad=0, handlelength=1)

    # Lower Right Plot
    ax[1,0].set_title('Width Population')
    ax[1,0].grid(True)
    for i in range(numdim):
        ax[1,0].plot(gen, width, color = colors[i])

    # Lower Left Plot
    ax[1,1].set_title('Mean Population')
    ax[1,1].grid(True)
    for i in range(numdim):
        ax[1,1].plot(gen, means, color = colors[i], label=names[i])
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[1,1].legend(bbox_to_anchor=(1.04,0.5), loc="center left", borderaxespad=0, handlelength=1)

    plt.show()
示例#2
0
def plot(genList, args):
    fig, ax = plt.subplots(2, 2, num='Korali Results', figsize=(8, 8))
    firstKey = next(iter(genList))
    numdim = len(genList[firstKey]['Variables'])
    numgens = len(genList)

    lastGen = 0
    for i in genList:
        if genList[i]['Current Generation'] > lastGen:
            lastGen = genList[i]['Current Generation']

    cond = [0.0] * numgens
    absfval = [0.0] * numgens
    dfval = [0.0] * numgens
    genIds = [0.0] * numgens
    sigma = [0.0] * numgens
    psL2 = [0.0] * numgens
    axis = [None] * numdim
    objVec = [None] * numdim
    ssdev = [None] * numdim

    for i in range(numdim):
        axis[i] = [None] * numgens
        objVec[i] = [None] * numgens
        ssdev[i] = [None] * numgens

    curPos = 0
    for gen in genList:
        genIds[curPos] = genList[gen]['Current Generation']
        cond[curPos] = genList[gen]['Solver'][
            'Maximum Covariance Eigenvalue'] / genList[gen]['Solver'][
                'Minimum Covariance Eigenvalue']
        absfval[curPos] = abs(genList[gen]['Solver']['Current Best Value'])
        dfval[curPos] = abs(genList[gen]['Solver']['Current Best Value'] -
                            genList[gen]['Solver']['Best Ever Value'])
        sigma[curPos] = genList[gen]['Solver']['Sigma']
        psL2[curPos] = genList[gen]['Solver'][
            'Conjugate Evolution Path L2 Norm']

        for i in range(numdim):
            axis[i][curPos] = genList[gen]['Solver']['Axis Lengths'][i]
            objVec[i][curPos] = genList[gen]['Solver'][
                'Current Best Variables'][i]
            ssdev[i][curPos] = genList[gen]['Solver']["Sigma"] * np.sqrt(
                genList[gen]['Solver']['Covariance Matrix'][i * numdim + i])

        curPos = curPos + 1

    plt.suptitle('CMAES Diagnostics', fontweight='bold', fontsize=12)

    names = [genList[firstKey]['Variables'][i]['Name'] for i in range(numdim)]

    # Upper Left Plot
    ax[0, 0].grid(True)
    ax[0, 0].set_yscale('log')
    #drawMulticoloredLine(ax[0,0], genIds, absfval, 0.0, 'r', 'b', '$| F |$')
    ax[0, 0].plot(genIds, absfval, color='r', label='$| F |$')
    ax[0, 0].plot(genIds,
                  dfval,
                  'x',
                  color='#34495e',
                  label='$| F - F_{best} |$')
    ax[0, 0].plot(genIds, cond, color='#98D8D8', label='$\kappa(\mathbf{C})$')
    ax[0, 0].plot(genIds, sigma, color='#F8D030', label='$\sigma$')
    ax[0, 0].plot(genIds, psL2, color='k', label='$|| \mathbf{p}_{\sigma} ||$')

    ax[0, 0].legend(bbox_to_anchor=(0, 1.00, 1, 0.2),
                    loc="lower left",
                    mode="expand",
                    ncol=3,
                    handlelength=1,
                    fontsize=8)

    colors = hlsColors(numdim)

    # Upper Right Plot
    ax[0, 1].set_title('Objective Variables')
    ax[0, 1].grid(True)
    for i in range(numdim):
        ax[0, 1].plot(genIds, objVec[i], color=colors[i], label=names[i])
    ax[0, 1].legend(bbox_to_anchor=(1.04, 0.5),
                    loc="center left",
                    borderaxespad=0,
                    handlelength=1)

    # Lower Right Plot
    ax[1, 0].set_title('Square Root of Eigenvalues of $\mathbf{C}$')
    ax[1, 0].grid(True)
    ax[1, 0].set_yscale('log')
    for i in range(numdim):
        ax[1, 0].plot(genIds, axis[i], color=colors[i])

    # Lower Left Plot
    ax[1, 1].set_title('$\sigma \sqrt{diag(\mathbf{C})}$')
    ax[1, 1].grid(True)
    ax[1, 1].set_yscale('log')
    for i in range(numdim):
        ax[1, 1].plot(genIds, ssdev[i], color=colors[i], label=names[i])
示例#3
0
def plot(js):
    fig, ax = plt.subplots(2, 2, num='Korali Results', figsize=(8, 8))
    solver = js['Generations'][0]['Solver']['Type']
    numdim = len(js['Variables'])
    names = [js['Variables'][i]['Name'] for i in range(numdim)]

    axis = []
    cond = []
    fval = []
    dfval = []
    gen = []
    ssdev = []
    sigma = []
    psL2 = []
    objVec = []

    for s in js['Generations']:
        cond.append(s['Solver']['Internal']['Maximum Covariance Eigenvalue'] /
                    s['Solver']['Internal']['Minimum Covariance Eigenvalue'])
        fval.append(s['Solver']['Internal']['Current Best Value'])
        dfval.append(
            abs(s['Solver']['Internal']['Current Best Value'] -
                s['Solver']['Internal']['Best Ever Value']))
        gen.append(s['Internal']['Current Generation'])
        sigma.append(s['Solver']['Internal']['Sigma'])
        psL2.append(
            s['Solver']['Internal']['Conjugate Evolution Path L2 Norm'])
        axis.append(s['Solver']['Internal']['Axis Lengths'])
        objVec.append(s['Solver']['Internal']['Current Best Variables'])

    ssdev = [[] for i in range(numdim)]
    for i in range(numdim):
        for s in js['Generations']:
            ssdev[i].append(
                js['Generations'][-1]['Solver']["Internal"]["Sigma"] *
                np.sqrt(s['Solver']["Internal"]['Covariance Matrix'][i * numdim
                                                                     + i]))

    plt.suptitle('CMAES Diagnostics', fontweight='bold', fontsize=12)

    # Upper Left Plot
    ax[0, 0].grid(True)
    ax[0, 0].set_yscale('log')
    drawMulticoloredLine(ax[0, 0], gen, fval, 0.0, 'r', 'b', '$| F |$')
    ax[0, 0].plot(gen, dfval, 'x', color='#34495e', label='$| F - F_{best} |$')
    ax[0, 0].plot(gen, cond, color='#98D8D8', label='$\kappa(\mathbf{C})$')
    ax[0, 0].plot(gen, sigma, color='#F8D030', label='$\sigma$')
    ax[0, 0].plot(gen, psL2, color='k', label='$|| \mathbf{p}_{\sigma} ||$')

    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0, 0].legend(bbox_to_anchor=(0, 1.00, 1, 0.2),
                    loc="lower left",
                    mode="expand",
                    ncol=3,
                    handlelength=1,
                    fontsize=8)

    colors = hlsColors(numdim)

    # Upper Right Plot
    #if (plot_mean):
    #    ax[0,1].set_title('Mean of Objective Variables')
    #    objVec = mu
    #else:
    ax[0, 1].set_title('Objective Variables')
    ax[0, 1].grid(True)
    for i in range(numdim):
        ax[0, 1].plot(gen, objVec, color=colors[i], label=names[i])

    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0, 1].legend(bbox_to_anchor=(1.04, 0.5),
                    loc="center left",
                    borderaxespad=0,
                    handlelength=1)

    # Lower Right Plot
    ax[1, 0].set_title('Square Root of Eigenvalues of $\mathbf{C}$')
    ax[1, 0].grid(True)
    ax[1, 0].set_yscale('log')
    for i in range(numdim):
        ax[1, 0].plot(gen, axis, color=colors[i])

    # Lower Left Plot
    ax[1, 1].set_title('$\sigma \sqrt{diag(\mathbf{C})}$')
    ax[1, 1].grid(True)
    ax[1, 1].set_yscale('log')
    for i in range(numdim):
        ax[1, 1].plot(gen, ssdev[i], color=colors[i], label=names[i])

    plt.show()
示例#4
0
def plot(genList, args):
    firstKey = next(iter(genList))
    fig, ax = plt.subplots(2, 2, num='Korali Results', figsize=(8, 8))

    numdim = len(genList[firstKey]['Variables'])
    numgens = len(genList)

    lastGen = 0
    for i in genList:
        if genList[i]['Current Generation'] > lastGen:
            lastGen = genList[i]['Current Generation']

    cond = [0.0] * numgens
    fval = [0.0] * numgens
    dfval = [0.0] * numgens
    genIds = [0.0] * numgens
    width = [None] * numdim
    means = [None] * numdim
    objVec = [None] * numdim

    for i in range(numdim):
        objVec[i] = [0.0] * numgens
        width[i] = [0.0] * numgens
        means[i] = [0.0] * numgens

    curPos = 0
    for gen in genList:
        genIds[curPos] = genList[gen]['Current Generation']
        fval[curPos] = genList[gen]['Solver']['Current Best Value']
        dfval[curPos] = abs(genList[gen]['Solver']['Current Best Value'] -
                            genList[gen]['Solver']['Best Ever Value'])

        for i in range(numdim):
            means[i][curPos] = genList[gen]['Solver']['Current Mean'][i]
            width[i][curPos] = genList[gen]['Solver']['Max Distances'][i]
            objVec[i][curPos] = genList[gen]['Solver'][
                'Current Best Variables'][i]
        curPos = curPos + 1

    plt.suptitle('DEA Diagnostics', fontweight='bold', fontsize=12)

    names = [genList[firstKey]['Variables'][i]['Name'] for i in range(numdim)]
    colors = hlsColors(numdim)

    # Upper Left Plot
    ax[0, 0].grid(True)
    ax[0, 0].set_yscale('log')
    drawMulticoloredLine(ax[0, 0], genIds, fval, 0.0, 'r', 'b', '$| F |$')
    ax[0, 0].plot(genIds,
                  dfval,
                  'x',
                  color='#34495e',
                  label='$| F - F_{best} |$')
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0, 0].legend(bbox_to_anchor=(0, 1.00, 1, 0.2),
                    loc="lower left",
                    mode="expand",
                    ncol=3,
                    handlelength=1,
                    fontsize=8)

    # Upper Right Plot
    ax[0, 1].set_title('Objective Variables')
    ax[0, 1].grid(True)
    for i in range(numdim):
        ax[0, 1].plot(genIds, objVec[i], color=colors[i], label=names[i])
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[0, 1].legend(bbox_to_anchor=(1.04, 0.5),
                    loc="center left",
                    borderaxespad=0,
                    handlelength=1)

    # Lower Right Plot
    ax[1, 0].set_title('Width Population')
    ax[1, 0].grid(True)
    for i in range(numdim):
        ax[1, 0].plot(genIds, width[i], color=colors[i])

    # Lower Left Plot
    ax[1, 1].set_title('Mean Population')
    ax[1, 1].grid(True)
    for i in range(numdim):
        ax[1, 1].plot(genIds, means[i], color=colors[i], label=names[i])
    #if ( (idx == 2) or (updateLegend == False) ):
    ax[1, 1].legend(bbox_to_anchor=(1.04, 0.5),
                    loc="center left",
                    borderaxespad=0,
                    handlelength=1)