예제 #1
0
파일: model.py 프로젝트: will-iam/Variant
def greeksEstimate(data, resource):
    '''
    delta = débit de la communication.
    lambda = latence pour ouvrir une communication.
    '''

    TsData = []
    for k, v in data.items():
        if not k.endswith(':' + str(resource) + ':1:4'):
            continue

        for p in v:

            coord = p['point']
            if coord[0] * coord[1] * coord[2] != resource:
                print(
                    "greeksEstimate: erreur dans la récupération des données.")
                sys.exit(1)

            if coord[0] == 1 and coord[1] == 1:
                continue

            #if coord[0] != coord[1]:
            #  continue

            #caseSize = int(np.sqrt(p['nPhysicalCells'] * coord[0] * coord[1]))
            #if caseSize > 700:
            #    continue
            extractedKey = parser.extractKey(k)
            p['Nx'] = extractedKey['Nx']
            p['Ny'] = extractedKey['Ny']

            TsData.append(p)

    # Estimation des paramètres du modèle
    TsList = []
    coupleList = []
    interfaceSizeDict = {}
    neighbourhoodDict = {}
    for p in TsData:
        ts = np.log(p['maxIterationSum'] - p['maxComputeSum'])
        #ts = p['loopTime'] - p['computeTime']

        coord = p['point']
        nx = float(coord[0])
        ny = float(coord[1])
        Nx = p['Nx']
        Ny = p['Ny']

        h = parser.fn(nx) * ny + parser.fn(ny) * nx
        i = h * (Nx + Ny)

        coupleList.append([1.0, np.log(h), np.log(i)])
        TsList.append(ts)

        if h not in interfaceSizeDict.keys():
            interfaceSizeDict[h] = {}
        if i not in interfaceSizeDict[h].keys():
            interfaceSizeDict[h][i] = []
        interfaceSizeDict[h][i].append(ts)

        if i not in neighbourhoodDict.keys():
            neighbourhoodDict[i] = {}
        if h not in neighbourhoodDict[i].keys():
            neighbourhoodDict[i][h] = []
        neighbourhoodDict[i][h].append(ts)

    Ts = np.array(TsList)
    F = np.array(coupleList)
    B = np.dot(pinv(F), Ts)

    print(len(Ts), " simulations. Valeur de B:", B)
    TsEstimate = np.dot(F, B)
    err = np.sqrt(np.sum(np.dot((Ts - TsEstimate),
                                (Ts - TsEstimate)))) / len(Ts)
    print("Erreur entre le modèle bruité non calibré et le modèle calibré: ",
          err)

    # i =  h * caseSize, j =  h * np.log(caseSize) : err = 0.00505024734782
    # i =  h * np.log(caseSize) : err = 0.005053122627
    # i =  h * np.sqrt(caseSize) : err = 0.00505726721335
    # i =  h * caseSize         : err = 0.00505726721335

    # Best = [-2.11062418  1.41218773 -1.39434254]
    '''
    # Estimation du bruit sur les temps de synchronisation ?


    Pf = np.dot(np.dot(F, inv(F.T.dot(F))), F.T)

    index = 0
    varYDict = {}
    for c in coupleList:
        varY = Pf[index][index]
        h = c[0]
        i = c[1]/h
        varYDict[i] = {}
        varYDict[i][h] = varY
        index += 1
    # Estimation de l'erreur entre le modèle non calibré bruité et le modèle calibré



    X = []
    Y = []
    err = []
    for i in sorted(neighbourhoodDict):
        for h,v in sorted(neighbourhoodDict[i].items()):
            for y in neighbourhoodDict[i][h]:
                x = h*(lambdaValue + deltaValue*i)
                Y.append(y)
                X.append(x)
                err.append(np.abs(x-y))

    sigma = np.std(err)
    print "err var:", np.var(err),", err std:", sigma
    Pf = Pf * sigma * sigma
    '''

    ### fig ###
    fig = plt.figure(0, figsize=(9, 6))
    boxDist = {}
    # Trace la courbe en fonction de i
    ax = fig.add_subplot(111)
    #ax = fig.add_subplot(211)
    xMin = np.min(neighbourhoodDict.keys())
    xMax = np.max(neighbourhoodDict.keys())
    #ax.set_xscale('log')
    #ax.set_yscale('log')
    x = np.linspace(xMin, xMax, 60)
    for h in sorted(interfaceSizeDict):
        #if h != 224 and h != 48 and h != 8 and h != 2:
        #    continue

        #if h < 8:
        #    continue

        for k, vL in interfaceSizeDict[h].items():
            if k not in boxDist.keys():
                boxDist[k] = []

            for v in vL:
                boxDist[k].append(v)

        ax.plot(sorted(interfaceSizeDict[h].keys()),
                [np.mean(t) for k, t in sorted(interfaceSizeDict[h].items())],
                "o--",
                label="total neighbour: " + str(h))

        #for i, tsList in interfaceSizeDict[h].items():
        #    ii = [i for p in tsList]
        #    ax.plot(ii, tsList, "+")

        # Estimate
        y = [B[0] + B[1] * np.log(h) + B[2] * np.log(i) for i in x]
        ax.plot(x, y, "-", label="total neighbour: " + str(h))

        #Best = [-2.11062418,  1.41218773, -1.39434254]
        #y = [np.exp(Best[0]) * np.power(h, Best[1] + Best[2]) * np.power(i / h, Best[2]) for i in x]
        #ax.plot(x, y, "-", label="total neighbour: " + str(h))

    ax.boxplot(boxDist.values(), positions=boxDist.keys())

    plt.xlabel('max interface size')
    plt.legend()
    plt.title('synchronized time model')
    plt.ylabel('Time')
    '''
(1, 1, 64, 123) - (0)

(1, 2, 32, 111) - (2.0)
(1, 4, 16, 123) - (6.0)
(1, 8, 8, 111) - (14.0)
(1, 16, 4, 123) - (30.0)
(1, 32, 2, 111) - (62.0)
(1, 64, 1, 138) - (126.0)

(2, 2, 16, 123) - (8.0)
(2, 4, 8, 111) - (20.0)
(2, 8, 4, 123) - (44.0)
(2, 16, 2, 111) - (92.0)
(2, 32, 1, 105) - (188.0)

(4, 4, 4, 123) - (48.0)
(4, 8, 2, 111) - (104.0)
(4, 16, 1, 105) - (216.0)

(8, 8, 1, 105) - (224.0)
    '''
    '''
    # Trace la courbe en fonction de h
    bx = fig.add_subplot(212)
#    bx = fig.add_subplot(111)
    x = np.linspace(0, 256, 10)
    for i in sorted(neighbourhoodDict):
        bx.plot(sorted(neighbourhoodDict[i].keys()), [np.mean(t) for k, t in sorted(neighbourhoodDict[i].items())], "o-", label="interfacesize: " + str(i))
        # Estimate
        #y = [lambdaValue + deltaValue * np.log(h) + thetaValue * np.log(i) for h in x]
#        bx.plot(x, y, "--")


    plt.xlabel('total neighbour number')
    #plt.legend(loc='upper left')
    plt.title('synchronized time model')
    plt.ylabel('Time')
    '''
    '''
    for i in varYDict.keys():
        errbarp = {}
        errbarm = {}
        for h, v in varYDict[i].items():
            print i, h, v
            x = h
            yp = h*(lambdaValue + deltaValue*i) + v * sigma * sigma
            ym = h*(lambdaValue + deltaValue*i) - v * sigma * sigma
            errbarp[x] = yp
            errbarm[x] = ym

        bx.plot(errbarp.keys(), errbarp.values(), "+")
        bx.plot(errbarm.keys(), errbarm.values(), "x")



    positionList = []
    valueList = []
    for s in sorted(neighbourhoodDict):
        for k in neighbourhoodDict[s].keys():
            positionList.append(k)
        for k in neighbourhoodDict[s].values():
            valueList.append(k)
    bx.boxplot(valueList, positions=positionList)

    plt.legend(loc='upper left')
    plt.title('synchronized time model')

    # Trace la courbe en fonction de predict
    cx = fig.add_subplot(111)
    cx.plot(X,Y,"+")
    cx.plot(X,X,"--")
    '''

    plt.show()

    return B
예제 #2
0
sizeDataDict = []
for p in range(0, int(np.log2(maxAvailableNode)) + 1):
    filterDict = {'nSizeX': caseSize[0], 'nSizeY': caseSize[1], 'R': 64 * 2**p}
    print filterDict
    data = parser.getData(filterDict)
    if len(data):
        sizeDataDict.append(data)

if len(sizeDataDict) == 0:
    print("No data found.")
    sys.exit(1)

loopTimeDict = dict()
for data in sizeDataDict:
    for key, value in data.items():
        keyDict = parser.extractKey(key)

        Nt = keyDict['Nt']
        R = keyDict['R']

        if keyDict['Ny'] != caseSize[0] or keyDict['Nx'] != caseSize[1]:
            print("Error in collected data")
            sys.exit(1)

        for run in value:
            nSDD = run['point'][0] * run['point'][1]

            # On several nodes, select only pure SDD, which is the best result.
            if R > 64 and nSDD < R:
                continue