Using the graph of the gods example and adding the following 'amount' property:
rand = new Random()
g.withSack {rand.nextFloat()}.E().property('amount',sack())
The traversal below is based on https://neo4j.com/docs/graph-algorithms/current/algorithms/similarity-pearson/ with the goal of calculating the (Ai - mean(A)) and (Bi - mean(B)) terms:
g.V().match(
__.as('v1').outE().valueMap().select('amount').fold().as('e1'),
__.as('v1').V().as('v2'),
__.as('v2').outE().valueMap().select('amount').fold().as('e2'),
__.as('v1').outE().inV().dedup().fold().as('v1n'),
__.as('v2').outE().inV().dedup().fold().as('v2n')
).
where('v1',neq('v2').and(without('v1n'))).
where('v2',without('v1n')).
project('v1','v2','a1','a2','a1m','a2m').
by(select('v1')).
by(select('v2')).
by(select('e1')).
by(select('e2')).
by(select('e1').unfold().mean()).
by(select('e2').unfold().mean()).
where(select('a1').unfold().count().is(gt(0))).
where(select('a2').unfold().count().is(gt(0)))
Output of traversal:
==>[a1:[v1:v[4096],v2:v[4248],a1:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a2:[0.7349615,0.80212617,0.6879539],a1m:0.5197273015975952,a2m:0.7416805227597555]]
==>[a1:[v1:v[4096],v2:v[4264],a1:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a2:[0.37226892,0.8902944,0.4158439,0.9709829],a1m:0.5197273015975952,a2m:0.6623475253582001]]
==>[a1:[v1:v[8192],v2:v[4096],a1:[0.32524675],a2:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a1m:0.32524675130844116,a2m:0.5197273015975952]]
==>[a1:[v1:v[8192],v2:v[4184],a1:[0.32524675],a2:[0.53761715,0.9604127,0.87463444,0.7719325],a1m:0.32524675130844116,a2m:0.786149188876152]]
==>[a1:[v1:v[8192],v2:v[4248],a1:[0.32524675],a2:[0.7349615,0.80212617,0.6879539],a1m:0.32524675130844116,a2m:0.7416805227597555]]
==>[a1:[v1:v[8192],v2:v[4264],a1:[0.32524675],a2:[0.37226892,0.8902944,0.4158439,0.9709829],a1m:0.32524675130844116,a2m:0.6623475253582001]]
==>[a1:[v1:v[4184],v2:v[4096],a1:[0.53761715,0.9604127,0.87463444,0.7719325],a2:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a1m:0.786149188876152,a2m:0.5197273015975952]]
==>[a1:[v1:v[4184],v2:v[8192],a1:[0.53761715,0.9604127,0.87463444,0.7719325],a2:[0.32524675],a1m:0.786149188876152,a2m:0.32524675130844116]]
==>[a1:[v1:v[4248],v2:v[4096],a1:[0.7349615,0.80212617,0.6879539],a2:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a1m:0.7416805227597555,a2m:0.5197273015975952]]
==>[a1:[v1:v[4248],v2:v[8192],a1:[0.7349615,0.80212617,0.6879539],a2:[0.32524675],a1m:0.7416805227597555,a2m:0.32524675130844116]]
==>[a1:[v1:v[4264],v2:v[4096],a1:[0.37226892,0.8902944,0.4158439,0.9709829],a2:[0.30577987,0.8416171,0.5247855,0.57484317,0.35161084],a1m:0.6623475253582001,a2m:0.5197273015975952]]
How would someone calculate 'a1 - a1m' and 'a2 - a2m' from this point in the traversal? The issue here is subtracting a single value from every element in a list and then returning the list of differences, any help with an example would be great.