概述
Struc2Vec游走是一种有偏的随机游走(Biased Random Walk)。这是Struc2Vec框架的关键组成部分之一,其中游走是在构建的带权多层图中而不是在原图中进行的。详情请参考Struc2Vec算法。
示例图集
创建示例图集:
// 在空图集中逐行运行以下语句
insert().into(@default).nodes([{_id:"A"},{_id:"B"},{_id:"C"},{_id:"D"},{_id:"E"},{_id:"F"},{_id:"G"},{_id:"H"},{_id:"I"},{_id:"J"}])
insert().into(@default).edges([{_from:"A", _to:"B"}, {_from:"A", _to:"C"}, {_from:"D", _to:"C"}, {_from:"D", _to:"F"}, {_from:"E", _to:"C"}, {_from:"E", _to:"F"}, {_from:"F", _to:"G"}, {_from:"G", _to:"J"}, {_from:"H", _to:"G"}, {_from:"H", _to:"I"}])
创建HDC图集
将当前图集全部加载到HDC服务器hdc-server-1
上,并命名为 hdc_struc2vec_walk
:
CALL hdc.graph.create("hdc-server-1", "hdc_struc2vec_walk", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static",
query: "query",
default: false
})
hdc.graph.create("hdc_struc2vec_walk", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static",
query: "query",
default: false
}).to("hdc-server-1")
参数
算法名:random_walk_struc2vec
参数名 |
类型 |
规范 |
默认值 |
可选 |
描述 |
---|---|---|---|---|---|
ids |
[]_id |
/ | / | 是 | 通过_id 指定随机游走的起点;若未设置则计算所有点 |
uuids |
[]_uuid |
/ | / | 是 | 通过_uuid 指定随机游走的起点;若未设置则计算所有点 |
walk_length |
Integer | ≥1 | 1 |
是 | 每次游走的深度,即访问的节点数量 |
walk_num |
Integer | ≥1 | 1 |
是 | 从每个指定节点开始的游走次数 |
k |
Integer | [1, 10] | / | 否 | 构建的多层加权图中的层数,层数不能超过原始图的直径 |
stay_probability |
Float | (0,1] | / | 否 | 留在当前层游走的概率 |
return_id_uuid |
String | uuid , id , both |
uuid |
是 | 在结果中使用_uuid 、_id 或同时使用两者来表示点 |
limit |
Integer | ≥-1 | -1 |
是 | 限制返回的结果数;-1 返回所有结果 |
文件回写
CALL algo.random_walk_struc2vec.write("hdc_struc2vec_walk", {
params: {
return_id_uuid: "id",
walk_length: 5,
walk_num: 1,
k: 4,
stay_probability: 0.8
},
return_params: {
file: {
filename: "walks"
}
}
})
algo(random_walk_struc2vec).params({
project: "hdc_struc2vec_walk",
return_id_uuid: "id",
walk_length: 5,
walk_num: 1,
k: 4,
stay_probability: 0.8
}).write({
file:{
filename: 'walks'
}})
结果:
_ids
J,G,F,E,C,
D,F,E,F,E,
F,G,F,
H,I,H,F,
B,A,B,A,B,
A,C,E,D,
E,F,G,H,G,
C,D,F,G,
I,H,G,F,E,
G,D,F,
完整返回
CALL algo.random_walk_struc2vec("hdc_struc2vec_walk", {
params: {
return_id_uuid: "id",
ids: ['J'],
walk_length: 6,
walk_num: 3,
k: 4,
stay_probability: 0.8
},
return_params: {}
}) YIELD walks
RETURN walks
exec{
algo(random_walk_struc2vec).params({
return_id_uuid: "id",
ids: ['J'],
walk_length: 6,
walk_num: 3,
k: 4,
stay_probability: 0.8
}) as walks
return walks
} on hdc_struc2vec_walk
结果:
_ids |
---|
["J","G","F","C","B"] |
["J","F","H","F","J"] |
["J","G","J","H","F"] |
流式返回
CALL algo.random_walk_struc2vec("hdc_struc2vec_walk", {
params: {
return_id_uuid: "id",
ids: ['J'],
walk_length: 6,
walk_num: 3,
k: 5,
stay_probability: 0.7
},
return_params: {
stream: {}
}
}) YIELD walks
RETURN walks
exec{
algo(random_walk_struc2vec).params({
return_id_uuid: "id",
ids: ['J'],
walk_length: 6,
walk_num: 3,
k: 5,
stay_probability: 0.7
}).stream() as walks
return walks
} on hdc_struc2vec_walk
结果:
_ids |
---|
["J","G","I","F"] |
["J","E","J"] |
["J","H","F","A"] |