- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很难在 gremlin 中找出以下场景的查询。这是有向图(可能是循环的)。
我想获得前 N 个有利节点,从节点“Jane”开始,这里的优先级定义为:
favor(Jane->Lisa) = edge(Jane,Lisa) / total weight from outwards edges of Lisa
favor(Jane->Thomas) = favor(Jane->Thomas) + favor(Jane->Lisa) * favor(Lisa->Thomas)
favor(Jane->Jerryd) = favor(Jane->Thomas) * favor(Thomas->Jerryd) + favor(Jane->Lisa) * favor(Lisa->Jerryd)
favor(Jane->Jerryd) = [favor(Jane->Thomas) + favor(Jane->Lisa) * favor(Lisa->Thomas)] * favor(Thomas->Jerryd) + favor(Jane->Lisa) * favor(Lisa->Jerryd)
and so .. on
这是我的意思手工计算的相同图表,
g
.addV('person').as('1').property(single, 'name', 'jane')
.addV('person').as('2').property(single, 'name', 'thomas')
.addV('person').as('3').property(single, 'name', 'lisa')
.addV('person').as('4').property(single, 'name', 'wyd')
.addV('person').as('5').property(single, 'name', 'jerryd')
.addE('favor').from('1').to('2').property('weight', 10)
.addE('favor').from('1').to('3').property('weight', 20)
.addE('favor').from('3').to('2').property('weight', 90)
.addE('favor').from('2').to('4').property('weight', 50)
.addE('favor').from('2').to('5').property('weight', 90)
.addE('favor').from('3').to('5').property('weight', 100)
我正在寻找的是:
[Lisa, computedFavor]
[Thomas, computedFavor]
[Jerryd, computedFavor]
[Wyd, computedFavor]
我正在努力配合循环图来调整重量。到目前为止,这是我能够查询的地方:
https://gremlify.com/f2r0zy03oxc/2
g.V().has('name','jane'). // our starting node
repeat(
union(
outE() // get only outwards edges
).
otherV().simplePath()). // produce simple path
emit().
times(10). // max depth of 10
path(). // attain path
by(valueMap())
解决来自 stephen mallette 的评论:
favor(Jane->Jerryd) =
favor(Jane->Thomas) * favor(Thomas->Jerryd)
+ favor(Jane->Lisa) * favor(Lisa->Jerryd)
// note we can expand on favor(Jane->Thomas) in above expression
//
// favor(Jane->Thomas) is favor(Jane->Thomas)@directEdge +
// favor(Jane->Lisa) * favor(Lisa->Thomas)
//
计算示例
Jane to Lisa => 20/(10+20) => 2/3
Lisa to Jerryd => 100/(100+90) => 10/19
Jane to Lisa to Jerryd => 2/3*(10/19)
Jane to Thomas (directly) => 10/(10+20) => 1/3
Jane to Lisa to Thomas => 2/3 * 90/(100+90) => 2/3 * 9/19
Jane to Thomas => 1/3 + (2/3 * 9/19)
Thomas to Jerryd => 90/(90+50) => 9/14
Jane to Thomas to Jerryd => [1/3 + (2/3 * 9/19)] * (9/14)
Jane to Jerryd:
= Jane to Lisa to Jerryd + Jane to Thomas to Jerryd
= 2/3 * (10/19) + [1/3 + (2/3 * 9/19)] * (9/14)
这是一些psedocode:
def get_favors(graph, label="jane", starting_favor=1):
start = graph.findNode(label)
queue = [(start, starting_favor)]
favors = {}
seen = set()
while queue:
node, curr_favor = queue.popleft()
# get total weight (out edges) from this node
total_favor = 0
for (edgeW, outNode) in node.out_edges:
total_favor = total_favor + edgeW
for (edgeW, outNode) in node.out_edges:
# if there are no favors for this node
# take current favor and provide proportional favor
if outNode not in favors:
favors[outNode] = curr_favor * (edgeW / total_favor)
# it already has some favor, so we add to it
# we add proportional favor
else:
favors[outNode] += curr_favor * (edgeW / total_favor)
# if we have seen this edge, and node ignore
# otherwise, transverse
if (edgeW, outNode) not in seen:
seen.add((edgeW, outNode))
queue.append((outNode, favors[outNode]))
# sort favor by value and return top X
return favors
最佳答案
这是我认为正确应用您的公式的 Gremlin 查询。我将首先粘贴完整的最终查询,然后就所涉及的步骤说几句。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> until(has('name','jerryd')).
.....11> sack().
.....12> sum()
==>0.768170426065163
查询从 Jane 开始并继续遍历,直到检查了所有到 Jerry D 的路径。在每个遍历器的过程中,都会维护一个
sack
,其中包含相乘在一起的每个关系的计算权重值。第 6 行的计算找到所有可能来自先前顶点的边权重值,第 7 行的
math
步骤用于将当前边的权重除以该总和。在最后,每个计算结果在第 12 行加在一起。如果删除最后的
sum
步骤,您可以看到中间结果。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> until(has('name','jerryd')).
.....11> sack()
==>0.2142857142857143
==>0.3508771929824561
==>0.2030075187969925
要查看所采用的路线,可以将
path
步骤添加到查询中。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> until(has('name','jerryd')).
.....11> local(
.....12> union(
.....13> path().
.....14> by('name').
.....15> by('weight'),
.....16> sack()).fold())
==>[[jane,10,thomas,90,jerryd],0.2142857142857143]
==>[[jane,20,lisa,100,jerryd],0.3508771929824561]
==>[[jane,20,lisa,90,thomas,90,jerryd],0.2030075187969925]
这种方法还考虑了根据您的公式添加任何直接连接,因为我们可以看到我们是否使用 Thomas 作为目标。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> until(has('name','thomas')).
.....11> local(
.....12> union(
.....13> path().
.....14> by('name').
.....15> by('weight'),
.....16> sack()).fold())
==>[[jane,10,thomas],0.3333333333333333]
==>[[jane,20,lisa,90,thomas],0.3157894736842105]
这些额外的步骤不是必需的,但包含
path
在调试这样的查询时很有用。此外,这不是必需的,但也许只是为了一般利益,我会补充说,您也可以从这里获得最终答案,但我包含的第一个查询就是您真正需要的。
g.withSack(1).V().
has('name','jane').
repeat(outE().
sack(mult).
by(project('w','f').
by('weight').
by(outV().outE().values('weight').sum()).
math('w / f')).
inV().
simplePath()).
until(has('name','thomas')).
local(
union(
path().
by('name').
by('weight'),
sack()).fold().tail(local)).
sum()
==>0.6491228070175439
如果有任何不清楚或我误解了公式,请告诉我。
unfold
只是为了让结果更容易阅读。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> emit().
.....11> local(
.....12> union(
.....13> path().
.....14> by('name').
.....15> by('weight').unfold(),
.....16> sack()).fold()).
.....17> group().
.....18> by(tail(local,2).limit(local,1)).
.....19> by(tail(local).sum()).
.....20> unfold()
==>jerryd=0.768170426065163
==>wyd=0.23182957393483708
==>lisa=0.6666666666666666
==>thomas=0.6491228070175439
第 17 行的最后
group
步骤使用
path
结果来计算找到的每个唯一名称的总支持度。要查看路径,您可以在删除
group
步骤的情况下运行查询。
gremlin> g.withSack(1).V().
......1> has('name','jane').
......2> repeat(outE().
......3> sack(mult).
......4> by(project('w','f').
......5> by('weight').
......6> by(outV().outE().values('weight').sum()).
......7> math('w / f')).
......8> inV().
......9> simplePath()).
.....10> emit().
.....11> local(
.....12> union(
.....13> path().
.....14> by('name').
.....15> by('weight').unfold(),
.....16> sack()).fold())
==>[jane,10,thomas,0.3333333333333333]
==>[jane,20,lisa,0.6666666666666666]
==>[jane,10,thomas,50,wyd,0.11904761904761904]
==>[jane,10,thomas,90,jerryd,0.2142857142857143]
==>[jane,20,lisa,90,thomas,0.3157894736842105]
==>[jane,20,lisa,100,jerryd,0.3508771929824561]
==>[jane,20,lisa,90,thomas,50,wyd,0.11278195488721804]
==>[jane,20,lisa,90,thomas,90,jerryd,0.2030075187969925]
关于gremlin - 海王星 - 如何获得到所有具有比例权重的节点的距离 gremlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63972067/
我有几个系统,其中包含用户表以及某种形式的业力/权重/声誉。有时是用户发布的帖子数量,有时是用户在网站上的所有事件中收到的赞成/反对票数。 USER { id int name str
我需要能够使用填充的相对大小 - 根据设备的分辨率和 dpi 变大或变小。 例如,如果我的 View 宽度为 100 像素,我希望左侧填充 10 像素,右侧填充 10 像素。但是,如果它在更高密度的屏
我目前正在使用由大约 10 个字段组成的 Solr 索引数据。当我执行搜索时,我希望某些字段的权重更高。谁能帮我指出正确的方向? 例如,在所有字段中搜索“超人”等术语时,应在“Description”
我正在使用 igraph 模拟网络随时间的变化在 r并且我正在寻找一种有效且可扩展的方式来对此进行编码以用于业务。 网络变化的主要驱动因素是: 新增节点 新领带 新节点权重 在第一阶段,在 100 个
我一直在寻找一种使用OpenVINO框架上的C++ API获取网络每一层权重/参数和偏差张量的方法。我在文档中找不到任何内容,在示例中也找不到任何示例。我如何提取这些张量? 谢谢, 塞萨尔 编辑: 分
我的问题与 PHP Memcache 扩展的 addServer 函数中的“weight”参数有关。 在过去的几个月里,我一直在为所有服务器使用“weight = 1”。我现在正在尝试应用以下配置以最
我应该使用哪种数据结构来保持元素按给定权重排序?我需要在集合中添加元素,其中每个元素都会生成特定的权重,但该权重不包含(也不计算)在元素本身内部;它是由元素之外的其他人计算的。而且,权重不需要存储(但
我正在尝试在 keras/tensorflow 中使用具有多个类的焦点损失,这导致使用我猜的分类焦点损失。我找到了一些实现here和 there或there 。 据我了解,焦点损失中的参数a主要用于二
我有一个像这样的 Pandas 数据框: df = pd.DataFrame({'id': [121, 34324, 111, 12, 45, 232], 'weight'
我有一个带有输出神经元的神经网络,我想在软最大化之前使用经过训练的权重进行线性缩放。 我有 10 个输出,我想要 10 个权重,在输出被软最大化之前乘以每个输出。因此每个输出的权重为 1。 但我不断收
我有这样的布局: 我希望它看起来像: TextView - 宽度的 40%,带 ImageView 的布局
这让我彻底疯了。我想在 android 中使用有点复杂的布局。我正在尝试使用权重而不是固定事物的大小。也许我应该放弃…… 这是我想做的: 我想要 3 个 ScrollView (里面有 TextVie
我正在尝试开发类似于网格但使用 LinearLayout。我想在单行中有 3 张图像和图像后的确切底部文本。 我尝试过的: LinearLayout layout = new LinearLayout
我想在同一行添加一个 EditText 和一个 Button,我想将 80% 的行给 editText,20% 给 Button。 这是我的代码:
我有一个 mysql 表,其中存储一列(称为 tickets),并且 tickets 值可以是任意数字。 我想要做的是有一个mysql查询,从列中选择所有行,按降序对它们进行排序,然后使用PHP对查询
我搜索了一段时间,但结果让我很困惑,因为我对 MySQL 还很陌生。 我有一个包含这 4 列的表:AUTO_INCREMENT ID、NAME、TYPE、CHANCE 所以行看起来像这样: 1, NO
我不完全是 JS 专业人士,虽然不漂亮或高效,但这是有效的。 实际上,我在表单中有重复的字段组,并允许用户根据需要将数据从第一个字段复制到所有 5 个字段。 如何使这段代码更高效? function
我正在使用xgboost库来训练二元分类器。我想通过向权重添加噪声(例如集合中树的叶节点的值)来防止训练算法的数据泄漏。为此,我需要检索每棵树的权重并修改它们。 我可以通过在 Booster 对象上使
我正在尝试让 LinearLayout 中的 View 填充宽度。我尝试使用 LayoutParams 设置它,但它给了我一个错误: 我的代码: EditText et = new EditText(
我想改变 ScrollView 的权重,但找不到实现它的方法。 这是我的 XML: **other layout.. 从代码中只能设置scrollView的高度或者宽度,weigh
我是一名优秀的程序员,十分优秀!