Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph embedding中transitionCountMatrix的计算问题 #69

Open
vcicii opened this issue Jun 16, 2022 · 0 comments
Open

graph embedding中transitionCountMatrix的计算问题 #69

vcicii opened this issue Jun 16, 2022 · 0 comments

Comments

@vcicii
Copy link

vcicii commented Jun 16, 2022

源代码:

def generateTransitionMatrix(samples):
    pairSamples = samples.flatMap(lambda x: generate_pair(x))
    pairCountMap = pairSamples.countByValue()
    pairTotalCount = 0
    transitionCountMatrix = defaultdict(dict)
    itemCountMap = defaultdict(int)
    for key, cnt in pairCountMap.items():
        key1, key2 = key

        # 此处是否应该改为 += cnt
        transitionCountMatrix[key1][key2] = cnt
        itemCountMap[key1] += cnt
        pairTotalCount += cnt
        ......

修改:

    for key, cnt in pairCountMap.items():
        key1, key2 = key

        if key1 not in transitionCountMatrix or key2 not in transitionCountMatrix[key1]:
            transitionCountMatrix[key1][key2] = cnt
        else:
            transitionCountMatrix[key1][key2] += cnt

        itemCountMap[key1] += cnt
        pairTotalCount += cnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant