Suppose we are interested in the Uroosa’s aggregated percentage in Hotel Kitchen SinkWe can use REDUCE as following:
Copy
match path = all (a:person {_id:'uroosa'})-[owns]->{0,} (b:business {_id:'hotel kitchen sink'})return path, reduce(total_ownership = 1 , own in owns | total_ownership * own.percentage) as ownershipnextreturn sum(ownership);
Note that we first mutiply Ownership percentages along each path and then the sum up the percentages for the 2 paths.
Geometric Mean is a measure of central tendency that calculates an average of the data using multiplication instead of addition. For a set of n numbers, the geometric mean is the nth root of the product of those numbers. For example, the geometric mean of the numbers 2, 3, and 14 equals (2 * 3 * 14)1/3 = (84)1/3 = 4.37952. Geometric Mean is particularly useful when the data is skewed and a simple average does not work.Suppose we are interested in the Geometric Mean Income of all the people who live in the same city as Fatima:
Copy
match path = ALL (a {_id:'fatima'})-[:lives_in]->(b)<-[:lives_in]-(c)return COLLECT_LIST(c) as residentsnextreturn reduce (geo_mean_product = 1, resident in residents | resident.income * geo_mean_product) ^ (1.0 / LENGTH(residents)) as income_geometric_mean;
Note that we first use the COLLECT_LIST to get all the people who live in the same city as Fatima in a LIST. Next we use the REDUCE to calculate the Geometric Mean.An alternate way to calculate Geometric Mean would be:
Copy
match path = ALL (a {_id:'fatima'})-[:lives_in]->(b)<-[:lives_in]-(c)return exp(AVG(ln(c.income))) as income_geometric_mean;