Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PGL
提交
d38731db
P
PGL
项目概览
PaddlePaddle
/
PGL
通知
76
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
11
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PGL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
11
Issue
11
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d38731db
编写于
12月 27, 2019
作者:
S
suweiyue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
graph_kernel: add doc
上级
4c3b9949
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
5 deletion
+25
-5
pgl/graph_kernel.pyx
pgl/graph_kernel.pyx
+25
-5
未找到文件。
pgl/graph_kernel.pyx
浏览文件 @
d38731db
...
...
@@ -253,10 +253,22 @@ def sample_subset_with_eid(list nids, list eids, long long maxdegree, shuffle=Fa
@
cython
.
boundscheck
(
False
)
@
cython
.
wraparound
(
False
)
def
skip_gram_gen_pair
(
vector
[
long
long
]
walk
,
long
win_size
=
5
):
def
skip_gram_gen_pair
(
vector
[
long
long
]
walk_path
,
long
win_size
=
5
):
"""Return node paris generated by skip-gram algorithm.
This function will auto remove the pair which src node is the same
as dst node.
Args:
walk_path: List of nodes as a walk path.
win_size: the windows size used in skip-gram.
Return:
A tuple of (src node list, dst node list).
"""
cdef
vector
[
long
long
]
src
cdef
vector
[
long
long
]
dst
cdef
long
long
l
=
len
(
walk
)
cdef
long
long
l
=
len
(
walk
_path
)
cdef
long
long
real_win_size
,
left
,
right
,
i
cdef
np
.
ndarray
[
np
.
int64_t
,
ndim
=
1
]
rnd
=
np
.
random
.
randint
(
1
,
win_size
+
1
,
dtype
=
np
.
int64
,
size
=
l
)
...
...
@@ -270,15 +282,23 @@ def skip_gram_gen_pair(vector[long long] walk, long win_size=5):
if
right
>=
l
:
right
=
l
-
1
for
j
in
xrange
(
left
,
right
+
1
):
if
walk
[
i
]
==
walk
[
j
]:
if
walk
_path
[
i
]
==
walk_path
[
j
]:
continue
src
.
push_back
(
walk
[
i
])
dst
.
push_back
(
walk
[
j
])
src
.
push_back
(
walk
_path
[
i
])
dst
.
push_back
(
walk
_path
[
j
])
return
src
,
dst
@
cython
.
boundscheck
(
False
)
@
cython
.
wraparound
(
False
)
def
alias_sample_build_table
(
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
probs
):
"""Return the alias table and event table for alias sampling.
Args:
porobs: A list of float numbers as the probability.
Return:
A tuple of (alias table, event table).
"""
cdef
long
long
l
=
len
(
probs
)
cdef
np
.
ndarray
[
np
.
float64_t
,
ndim
=
1
]
alias
=
probs
*
l
cdef
np
.
ndarray
[
np
.
int64_t
,
ndim
=
1
]
events
=
np
.
zeros
(
l
,
dtype
=
np
.
int64
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录