Beispiel #1
0
def __compareVectToNonVectorOneChange__(G, p_in1, p_out1, c_in1, c_out1):
    A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
    p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
    order = list(range(4))
    rd.shuffle(order)
    for t1 in order:
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = hmNV.__getNormNonVect__(
            p_out, c_in, c_out, p_in)
        ## make copy here just in case of modification
        oldVerOrig = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        slowRes = slowMethod(G, p_in, p_out, c_in, c_out, t1)
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = hmNV.__getNormNonVect__(
            p_out, c_in, c_out, p_in)
        reallySlow = hitsReallySimple(G, p_in, p_out, c_in, c_out, t1)

        C2 = C + Ct
        oldVer = hm.__hitsmk2GroupOrder__(A, At, C, Ct, oldVer, s1, C2, t1)
        assert (abs(oldVer[:, t1] - slowRes[:, t1]).max() < 10**(-8))
        assert (abs(oldVer[:, t1] - reallySlow[:, t1]).max() < 10**(-8))
def __compareVectToNonVectorOneChange__(G, p_in1, p_out1, c_in1, c_out1):
    A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
    p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
    for t1 in range(len(p_in1)):
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = hmNV.__getNormNonVect__(
            p_out, c_in, c_out, p_in)
        ## make copy here just in case of modification
        oldVerOrig = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        slowRes = slowMethod(G, p_in, p_out, c_in, c_out, t1)
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = hmNV.__getNormNonVect__(
            p_out, c_in, c_out, p_in)
        reallySlow = hitsReallySimple(G, p_in, p_out, c_in, c_out, t1)

        x, max1 = hm.__hitsmk2OneAtATimeGroup__(As, Ats, t1, C, Ct, oldVer, s1,
                                                s2)
        assert (abs(oldVer - slowRes).max() < 10**(-8))
        assert (abs(oldVer - reallySlow).max() < 10**(-8))
def __compareVectToNonVectorAllChanges__(G, p_in1, p_out1, c_in1, c_out1):
    A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
    p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
    for rep in range(10):
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = hmNV.__getNormNonVect__(
            p_out, c_in, c_out, p_in)
        oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        order = list(range(len(p_in1)))
        rd.shuffle(order)
        maxDiff = -100
        for t1 in order:
            ## make copy here just in case of modification
            #            oldVerOrig = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
            #            oldVerOrig1 = oldVer.copy()
            reallySlow = hitsReallySimple(G, p_in.copy(), p_out.copy(),
                                          c_in.copy(), c_out.copy(), t1)
            p_in, p_out, c_in, c_out = slowMethod(G, p_in, p_out, c_in, c_out,
                                                  t1, False)
            x, max1 = hm.__hitsmk2OneAtATimeGroup__(As, Ats, t1, C, Ct, oldVer,
                                                    s1, s2)
            if max1 > maxDiff:
                maxDiff = max1
            slowRes = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
            assert (abs(oldVer - slowRes).max() < 10**(-8))
            assert (abs(oldVer - reallySlow).max() < 10**(-8))
        p_in2 = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out2 = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in2 = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out2 = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out2, c_in2, c_out2, p_in2 = hmNV.__getNormNonVect__(
            p_out2, c_in2, c_out2, p_in2)
        original = np.concatenate([p_out2, c_in2, c_out2, p_in2], axis=1)
        actualMaxDiff = abs(original - oldVer).max()
        p_outM = abs(p_out2 - p_out).max()
        c_outM = abs(c_out2 - c_out).max()
        p_inM = abs(p_in2 - p_in).max()
        c_inM = abs(c_in2 - c_in).max()
        slowMax = max([p_outM, c_outM, p_inM, c_inM])
        assert (abs(actualMaxDiff - maxDiff) < 10**(-10))
        assert (abs(actualMaxDiff - slowMax) < 10**(-10))
        assert (abs(maxDiff - slowMax) < 10**(-10))
Beispiel #4
0
def __compareVectToNonVectorOneChange__(G, p_in1, p_out1, c_in1, c_out1):
    func1 = hmV.__getNormNonVect__
    func2 = hm.__hitsmk2OneAtATime__
    for t1 in range(len(p_in1)):
        p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
        p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
        c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
        c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
        p_out, c_in, c_out, p_in = func1(p_out, c_in, c_out, p_in)
        # make copy here just in case of modification
        oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        slowRes = slowMethod(G, p_in, p_out, c_in, c_out, t1)
        A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
        As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
        func2(As, Ats, t1, C, Ct, oldVer, s1, s2, totals)
        assert (abs(oldVer - slowRes).max() < 10**(-8))
        assert (abs(oldVer.sum(axis=0) - totals).max() < 10**(-10))
Beispiel #5
0
def __compareVectToNonVectorAllChanges__(G, p_in1, p_out1, c_in1, c_out1):
    p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    p_out, c_in, c_out, p_in = hmV.__getNormNonVect__(p_out, c_in, c_out, p_in)
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    order = list(range(4))
    rd.shuffle(order)
    A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
    As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
    slwM = slowMethod
    func1 = hm.__hitsmk2Order__
    C2 = C + Ct
    for t1 in order:
        # make copy here just in case of modification
        oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        p_in, p_out, c_in, c_out = slwM(G, p_in, p_out, c_in, c_out, t1, False)
        oldVer = func1(A, At, C, Ct, oldVer, s1, C2, t1)
        slowRes = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        assert (abs(oldVer[:, t1] - slowRes[:, t1]).max() < 10**(-8))
        takeNorm = hmV.__getNormNonVect__
        p_out, c_in, c_out, p_in = takeNorm(p_out, c_in, c_out, p_in)
    ## This test is a little redundant but there you go
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    p_in2 = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out2 = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in2 = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out2 = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    gtNormNoVec = hmV.__getNormNonVect__
    p_out2, c_in2, c_out2, p_in2 = gtNormNoVec(p_out2, c_in2, c_out2, p_in2)

    original = np.concatenate([p_out2, c_in2, c_out2, p_in2], axis=1)
    actualMaxDiff = abs(original - oldVer).max()

    p_outM = abs(p_out2 - p_out).max()
    c_outM = abs(c_out2 - c_out).max()
    p_inM = abs(p_in2 - p_in).max()
    c_inM = abs(c_in2 - c_in).max()
    slowMax = max([p_outM, c_outM, p_inM, c_inM])

    assert (abs(actualMaxDiff - slowMax) < 10**(-10))
Beispiel #6
0
def __compareVectToNonVectorAllChanges__(G, p_in1, p_out1, c_in1, c_out1):
    p_in = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    p_out, c_in, c_out, p_in = hmV.__getNormNonVect__(p_out, c_in, c_out, p_in)
    oldVer = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
    order = list(range(len(p_in1)))
    rd.shuffle(order)
    A, At, C, Ct, n, s1, s2 = hm.__setup__(G)
    As, Ats, totals = hm.__setupOneAtATime__(A, At, oldVer)
    maxDiff = -100
    slwM = slowMethod
    func1 = hm.__hitsmk2OneAtATime__
    for t1 in order:
        # make copy here just in case of modification
        p_in, p_out, c_in, c_out = slwM(G, p_in, p_out, c_in, c_out, t1, False)
        max1 = func1(As, Ats, t1, C, Ct, oldVer, s1, s2, totals)
        if max1 > maxDiff:
            maxDiff = max1
        slowRes = np.concatenate([p_out, c_in, c_out, p_in], axis=1)
        assert (abs(oldVer - slowRes).max() < 10**(-8))
        assert (abs(oldVer.sum(axis=0) - totals).max() < 10**(-10))
    p_in2 = np.array(deepcopy(p_in1)).reshape([len(G), 1])
    p_out2 = np.array(deepcopy(p_out1)).reshape([len(G), 1])
    c_in2 = np.array(deepcopy(c_in1)).reshape([len(G), 1])
    c_out2 = np.array(deepcopy(c_out1)).reshape([len(G), 1])
    gtNormNoVec = hmV.__getNormNonVect__
    p_out2, c_in2, c_out2, p_in2 = gtNormNoVec(p_out2, c_in2, c_out2, p_in2)
    original = np.concatenate([p_out2, c_in2, c_out2, p_in2], axis=1)
    actualMaxDiff = abs(original - oldVer).max()
    p_outM = abs(p_out2 - p_out).max()
    c_outM = abs(c_out2 - c_out).max()
    p_inM = abs(p_in2 - p_in).max()
    c_inM = abs(c_in2 - c_in).max()
    slowMax = max([p_outM, c_outM, p_inM, c_inM])
    assert (abs(actualMaxDiff - maxDiff) < 10**(-10))
    assert (abs(actualMaxDiff - slowMax) < 10**(-10))
    assert (abs(maxDiff - slowMax) < 10**(-10))