Example #1
0
def gradPolyFunctionalTest_random(repeats, edgeNumber, eps, h, delta,
                                  nearby_option):

    n = 1
    if not nearby_option:
        while n <= repeats:

            P = rP.getRandomPolygon(edgeNumber)

            cD_test = cV.getConeVol(P)
            point_test = [random.random() * 10, random.random() * 10]

            # could be improved by making delta smaller if check is false ... orby setting point_test in the near of an vertex...

            check = hMethodPolyFunctionalCheck(cD_test, point_test, eps, h)

            if not check:
                print(
                    ' gradPolyFunctionalTest failed with polytop , point_test , value : '
                )
                print(P)
                print(point_test)
                print(cV.polyFunctional(cD_test, point_test))

            n = n + 1
    else:
        while n <= repeats:

            P = rP.getRandomPolygon(edgeNumber)

            cD_test = cV.getConeVol(P)
            point_test = [random.random(), random.random()]
            norm = M.norm(point_test)
            point_test = M.scaleVek(delta / norm, point_test)
            print(' here is the translation')
            print(point_test)
            point_test = M.addVek(point_test, P[0])
            # could be improved by making delta smaller if check is false ... orby setting point_test in the near of an vertex...

            check = hMethodPolyFunctionalCheck(cD_test, point_test, eps, h)

            if not check:
                print(
                    ' gradPolyFunctionalTest failed with polytop , point_test , value : '
                )
                print(P)
                print(point_test)
                print(cV.polyFunctional(cD_test, point_test))

            n = n + 1
Example #2
0
def compareSupportFunctions(repeats, eps):
    P = rP.getRandomPolygon(3)
    Q = rP.getRandomPolygon(4)
    cD_P = cV.getConeVol(P)

    for i in range(len(P)):
        u = [cD_P[i - 1][0], cD_P[i - 1][1]]
        alpha = rP.supportFunctionCartesianCentered(Q, u)
        beta = rP.supportFunctionCartesianCentered2(Q, u)
        alternative = trySupport(Q, u)

        print(alternative)
        print(alpha)
        print(beta)
Example #3
0
def supportTest(repeats):
    tooSmall = 0
    tooSmall2 = 0
    tooSmall3 = 3
    tooBig = 0
    easyFail = 0
    n = 0
    while (n < repeats):
        containsPoint_eps = 0

        P = rP.getRandomPolygon(3)
        Q = rP.getRandomPolygon(4)
        cD_P = cV.getConeVol(P)

        for i in range(len(P)):
            print(len(P))
            u = [cD_P[i - 1][0], cD_P[i - 1][1]]
            alpha = rP.supportFunctionCartesianCentered(Q, u)
            beta = rP.supportFunctionCartesianCentered2(Q, u)
            gamma = 1  #trySupport( Q , u , 0.0000001)

            if math.fabs(
                    M.scal(u, P[i - 1]) -
                    rP.supportFunctionCartesianCentered2(P, u)) > 1:
                easyFail += 1

            if not (containsPoint(Q, M.scaleVek(alpha - math.exp(-15), u))):
                tooBig += 1

            if (containsPoint(Q, M.scaleVek(alpha + 0.01, u))):
                #plotPoly( P , 'r' )
                #plotPoly( Q , 'y')

                tooSmall += 1

            if (containsPoint(Q, M.scaleVek(beta + 0.01, u))):
                #plotPoly( P , 'r' )
                #plotPoly( Q , 'y')

                tooSmall2 += 1

            if (containsPoint(Q, M.scaleVek(gamma + 0.01, u))):
                #plotPoly( P , 'r' )
                #plotPoly( Q , 'y')

                tooSmall3 += 1
        n += 1

    print([easyFail, tooBig, tooSmall, tooSmall2, tooSmall3])
Example #4
0
def quadraticMinSearcherTestWithoutGamma( repeats , f ):
    eps = 0.01
    notUnique = 0
    singDiffMatrix = 0
    fails = 0
    while repeats > 0:
        repeats -= 1
        P = rP.getRandomPolygon( 5 )
        cD = cV.getConeVol( P )

        result = quadraticMinSearcher( cD , [ f , eps ] )[0]
        if M.dist( result , P[0]) > 0.1:
            value = M.dist(cV.getConeVolIterator( cD ,  result ) , result)
            if  value < eps:
                print( 'not unique solution' )
                print( P )
                print(result)
                notUnique += 1
                break
            else:
                if f( result , cD ) < 0.01:
                    print(" singular diff matrix ")
                    print(P)
                    print(result)
                    print( f( result , cD ) )
                    singDiffMatrix += 1
                else:
                    print('quadratic searcher failed by')
                    print(P)
                    print(result)
                    fails += 1
    return [notUnique , singDiffMatrix , fails]
Example #5
0
def quadraticMinSearcherTest( repeats , f ):
    eps = 0.00001
    fails = 0
    while repeats > 0:
        print( repeats )
        repeats -= 1
        P = rP.getRandomPolygon( 5 )
        cD = cV.getConeVol( P )

        result = quadraticMinSearcher( cD , [ f , eps ] )[0]
        if M.dist( cV.gamma( cD , result) , P[0]) > 0.1:
            if cV.sigma( result , cD ) < eps:
                print( 'not unique solution' )
                print( P )
                print(result)
                print( cV.gamma( cD , result ) )
                fails += 1
                break
            else:
                print('quadratic searcher failed by by')
                print( cV.sigma( result , cD ) )
                print(P)
                print(result)
                print(cV.gamma(cD, result))
                fails += 1
    return fails
Example #6
0
def makeTest(n):
    rounds = 0
    wrongs = []
    counting = [0, 0, 0, 0]
    while rounds < test_repeats:
        P = rP.getRandomPolygon(n)
        convexTest = isConvex(P)
        convexRunTest = isConvexRun(P)
        if not (convexTest) and convexRunTest:
            print('okay')
            #plotPoly(P, 'b')
            counting[1] += 1
        if convexTest and convexRunTest:
            print('nice')
            #plotPoly(P, 'g')
            counting[0] += 1
        if convexTest and not (convexRunTest):
            print('strange')
            #plotPoly(P, 'y')
            counting[2] += 1
        if not (convexTest) and not (convexRunTest):
            print('this is bad')
            wrongs.append(P)
            plotPoly(P, 'r')
            counting[3] += 1
        rounds = rounds + 1
    return counting
Example #7
0
def getRandomRoundedPolygon(number, digits):
    K = []
    while len(K) == 0 or not isConvexRun(K) or not isConvex(K):

        K = rP.getRandomPolygon(number)

        rP.roundVertices(K, digits)

    return K
Example #8
0
def makeEdgeNumberTest(repeats, edgeNumber):
    fail_less = 0
    fail_more = 0
    for i in range(repeats):
        P = rP.getRandomPolygon(edgeNumber)
        if len(P) < edgeNumber:
            print('not enough edges')
            fail_less = fail_less + 1
        if len(P) > edgeNumber:
            print('too many edges')
            fail_more = fail_more + 1
Example #9
0
def normalsTest(repeats, verticesNumber, test_eps):
    for i in range(repeats):
        P = rP.getRandomPolygon(verticesNumber)
        coneVol = cV.getConeVol(P)
        diff = math.fabs(getSumOuterNormal(P) - verticesNumber)
        if diff > test_eps:
            #print( P )
            #print( diff )
            normalNormsPrint(coneVol)
            print(' normalsTest failed at')
            print(len(coneVol))
            print(len(P))
            pT.plotPoly(P, 'r')
            break
Example #10
0
def polyFunctionalTest(repeats, edgeNumber, eps):
    turns = 0
    while turns < repeats:
        P = rP.getRandomPolygon(edgeNumber)
        cD = cV.getConeVol(P)
        vertex = P[0]
        value_vertex = cV.polyFunctional(cD, vertex)
        grad_vertex = cV.gradPolyFunctional(cD, vertex)

        # getConeVol, polyFunctional oder gradPolyFunctional könnte falsch sein...

        if (value_vertex >= eps):
            print(' Fehler bei polyFunctionalTest , value zu hoch')
            print(P)
            print(value_vertex)

        if (M.norm(grad_vertex) >= eps):
            print(' Fehler bei polyFunctionalTest , grad zu hoch')
            print(P)
            print(grad_vertex)
        turns += 1
Example #11
0
def testerDetOfDiff(repeats, range_test, eps):
    complete_fail = 0
    approx_fail = 0
    analytic_fail = 0
    for i in range(repeats):
        P = rP.getRandomPolygon(5)  #random.random() * 5 + 3 )
        cD = cV.getConeVol(P)
        point = [
            random.random() * 2 * range_test - range_test,
            random.random() * 2 * range_test - range_test
        ]
        if not checkDetOfDiff(point, cD, eps):
            if not checkDetOfDiffApprox(point, cD, eps):
                complete_fail += 1
            else:
                analytic_fail += 1
        else:
            if not checkDetOfDiffApprox(point, cD, eps):
                approx_fail += 1

    print([repeats, complete_fail, analytic_fail, approx_fail])
Example #12
0
def getWorstNormDirection(repeats, eps_direction):
    success = 0
    fails = 0
    value_max = 0
    worstPoly = []
    for n in range(repeats):
        K = rP.getRandomPolygon(4)
        value = getWorsteNormalsDirection(K)
        if value < eps_directionTest:
            success += 1
        else:
            if value > value_max:
                value_max = value
                worstPoly = K
            minVertDist = getMinVertexDist(K)
            if minVertDist > 1:
                print(minVertDist)

    print([success, fails])
    plotPoly(worstPoly, 'r')
    print(value_max)
import polygonReconstruct as pR
import randomPolygon3Centered as rP
import coneVol2 as cV
import math
import random
import matrix as M

repeats = 0
noFail = 0
fail_soft = 0
fail_medium = 0
fail_hard = 0

while repeats < 50:
    eps_test = 0.00001
    P_test = rP.getRandomPolygon(math.floor(10 * random.random() + 3))
    cD_test = cV.getConeVol(P_test)

    result = pR.polygonReconstructCentered(cD_test, 0.0001, 0.5, 0.9, 0.5, 0.5,
                                           eps_test)

    sigma_result = cV.sigma(result, cD_test)

    if (sigma_result < eps_test):
        noFail += 1
    else:
        if (sigma_result < eps_test * 100):
            fail_soft += 1
        else:
            if (sigma_result < eps_test * 100 * 100):
                fail_medium += 1
Example #14
0
#plotPoly( test , 'b')

#support_test = [ [ 0 , 1] , [ 0.5 * math.pi , 1 ] , [ 1.5 * math.pi , 1 ] ]

#u = [ 1 , 1 ]

#print( rP.supportFunction( support_test , u ) - 0.5 )

repeats = 0

n = 0
good_triangles = 0
bad_triangles = 0
while (n < repeats):
    P = rP.getRandomPolygon(3)

    if isConvex(P) and isConvexRun(P):
        good_triangles += 1
    else:
        bad_triangles += 1

    n += 1
#print( [ good_triangles , bad_triangles ])


def testIsContainedSquare(repeats):
    square = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    fail_1 = 0
    fail_2 = 0
Example #15
0
            divisor = mE.getMachEps()
        u = M.scaleVek( 1.0 / divisor , u_tilde )

        height= M.scal(u,vertices[i-1])
        if height < 0:
            print('height is negativ at ')
            print(i)
        facetVolume= M.norm(v)
        coneVolume= 0.5 * height * facetVolume

        result.append([u[0],u[1],coneVolume])
    return result


cD_test = [[0, 1, 1], [1, 0, 1], [ 0 , -1, 1],[-1,0,1] ]
polygon_hardcoreTest = rP.getRandomPolygon( 5 )
cD_hardcoreTest = getConeVol( polygon_hardcoreTest )
p=[1,0.5]

def getGrid(n):
    result=[]
    l=0
    k=0
    while(l<=n**2):
        while(k<=n**2):
            if(k+l>0):
                result.append([k*1/n,l*1/n])
            k=k+1
        k=0
        l=l+1
    return result