コード例 #1
0
ファイル: test_cholesky.py プロジェクト: ethiery/heat-solver
def compareCompleteVSIncomplete():
    size = 100
    nbOfPoints = 50
    nbValuesForAverage = 4
    x, yComplete, yIncomplete = [], [], []

    for i in numpy.linspace(0, size*(size-1), nbOfPoints):
        # Computes matrix density
        x.append((size*size-i)/(size*size))
        # Computes average execution times on 3 calls on different matrix
        completeTime, incompleteTime = 0, 0
        for j in range(nbValuesForAverage):    
            M = matgen.symmetricSparsePositiveDefinite(size, i)
            wrapped1 = wrapper(cholesky.completeCholesky, M)
            completeTime += timeit.timeit(wrapped1, number=1)
            wrapped2 = wrapper(cholesky.incompleteCholesky, M)
            incompleteTime += timeit.timeit(wrapped2, number=1)
        yComplete.append(completeTime/nbValuesForAverage)
        yIncomplete.append(incompleteTime/nbValuesForAverage)

    p1 = plt.plot(x, yComplete, 'b', marker='o')
    p2 = plt.plot(x, yIncomplete, 'g', marker='o')
    plt.title("Average execution time for the Cholesky factorization in function of matrix density\n")
    plt.legend(["New custom Complete factorization", "Custom incomplete factorization"], loc=4)
    plt.ylabel("Execution time (s)")
    plt.xlabel("density of the initial 100*100 matrix")
    plt.show()
コード例 #2
0
ファイル: test_cholesky.py プロジェクト: ethiery/heat-solver
def testIncompleteCholeskyPrecision():
    size = 100
    nbOfPoints = 100 
    x, y = [], []
    for i in numpy.linspace(0, size*(size-1), nbOfPoints):
        x.append(i/(size*size))
        M = matgen.symmetricSparsePositiveDefinite(size, i)
        complete = cholesky.completeCholesky(M)
        incomplete = cholesky.incompleteCholesky(M)
        y.append(numpy.linalg.norm(complete-incomplete)/numpy.linalg.norm(complete))
    plt.plot(x, y, marker='o')
    plt.title("Relative error made by Cholesky incomplete factorization, in function of matrix density\n")
    plt.ylabel("relative error on the norm of the matrix obtained")
    plt.xlabel("density of the initial 100*100 matrix")
    plt.show()