Beispiel #1
0
def sum_weight(state, letter):
    #    maximum = 0
    weight = cube.path(state)[letter]
    count = 0
    for i in range(len(weight.values())):
        count = weight.values()[i] + count
    return count
Beispiel #2
0
def onnela_clustering(state):
    sum_AB = 0.0
    C_o = 0.0
    letter_sum = 0.0
    partial = 0.0
    for node in state:
        for letterA in state:
            if letterA != node:
                for letterB in state:
                    if letterA != letterB and letterB != node:
                        w1 = cube.path(state)[node][letterA]
                        w1A = w1 * 0.20
                        #                        print 'For i={}, j={}, k={}'.format(node, letterA, letterB)
                        #                        print "({},{}:{})".format(node,letterB,w1A)
                        w2 = cube.path(state)[node][letterB]

                        w2A = w2 * 0.20
                        #                        print "({},{}:{})".format(node,letterB,w2A)

                        w3 = cube.path(state)[letterA][letterB]
                        w3A = w3 * 0.20
                        #                        print "({},{}:{})".format(letterA,letterB,w3A)
                        partial = (w1A * w2A * w3A)**float(1 / 3)
#                        print partial

                    sum_AB = partial + sum_AB
#                    print "({},{},{}):{}".format(node,letterA,letterB,sum_AB)

            letter_sum = sum_AB + letter_sum


#            print ' '
#            print 'End of first iteration for {}, {}. This is the partial sum: {}'.format(node, letterA, letter_sum)
#            print ' '
#            print 'Start New iterations. For i={}, j={}'.format(node, letterA)

        C_node = letter_sum / (23 * 22)
        C_o = C_node + C_o
        #        print 'End of first iteration for node {}. This is the average clustering of node {}: {}'.format(node,node, C_node)
        sum_AB = 0.0
        letter_sum = 0.0
        partial = 0.0

    return C_o
Beispiel #3
0
def barrat_clustering(state):
    graph = cube.network(state)
    sum_AB = 0
    for letter in state:
        k = nx.degree(graph)[letter]
        w_sum = np.sum(cube.path(state)[letter].values())
        partial = 0
        partial_sum = 0
        for letterB in graph.nodes():
            for letterC in graph.nodes():
                if (letter, letterB) in graph.edges() and (
                        letter, letterC) in graph.edges():

                    wA = cube.path(state)[letter][letterB]
                    wB = cube.path(state)[letter][letterC]
                    partial = ((wA + wB) * 0.50) * (w_sum)**-1 + partial
            partial_sum = partial + partial_sum
        sum_AB = ((k)**-1) * ((k - 1)**-1) * partial_sum + sum_AB
    return sum_AB
Beispiel #4
0
def zhang_clustering(state):
    graph = cube.network(state)
    C_z = 0
    for letter in state:
        sum_numerator = 0
        for letterB in graph.nodes():
            partial_sum = 0
            for letterC in graph.nodes():
                if (letter, letterB) in graph.edges() and (
                        letter, letterC) in graph.edges():
                    wA = cube.path(state)[letter][letterB] * 0.20
                    wB = cube.path(state)[letter][letterC] * 0.20
                    wC = cube.path(state)[letterB][letterC] * 0.20
                    wB_array = cube.path(state)[letter].values()
                    prod = wA * wB * wC
                    partial_sum = prod + partial_sum
            sum_numerator = partial_sum + sum_numerator
        A_squared = (np.sum(wB_array))**2.0
        A_squared_not = (np.sum([element**2 for element in wB_array]))
        C_z = sum_numerator * (A_squared - A_squared_not)**-1 + C_z
    return C_z
Beispiel #5
0
def network(string):
    pocketcube = nx.Graph()
        
    
    for letterA in solved_state:
        pocketcube.add_node(letterA)
    edges = pocketcube.edges()
    listahan = cube.path(solved_state)[letterA]
#        for letterB in listahan:
#            pair = (letterA, letterB)
        
    pocketcube.add_weighted_edges_from(edges)
    return pocketcube