Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can think aggregators as a tree, that the leafs leaves (which are the graph vertices) are sending messages to the root (the master aggregator), and then the root is combining all these messages to a value. In the end, this combined values is are distributed back to the leafsleaves. Aggregators are useful for statistics (think of an histogram of vertex degrees) or for global controllingmanagement.

Registering aggregators

To start using aggregators, you must register declare them in your GraphJob.

e.g.

No Format
HamaConfiguration conf = new HamaConfiguration(new Configuration());
GraphJob graphJob = new GraphJob(conf, MyClass.class);

// To add an average aggregator
graphJob.setAggregatorClass(AverageAggregator.class);

// To add a sum aggregator
graphJob.setAggregatorClass(SumAggregator.class);

There are lots of multiple different aggregators and you can also make your own. Look for already implemented You can look for already implemented aggregators in org.apache.hama.graph package.

Start working with aggregators

In order to aggregate values from your vertices, use:

No Format

this.aggregate(index,value);

This method is called from inside each vertex. Though it's not mandatory all vertices to make use of this method.

The index parameter of this method is a number that is equivalent to the order of the registered aggregator. (The first registered aggregator has index 0, second has index 1 etc.)

Get results

Inside your vertex, you can get the results of each aggregator by using the method:

No Format

this.getAggregatedValue(index);

Write your own aggregators

To write your own aggregator, you have to extend AbstractAggregator class and implement the methods of #aggregate(M value) and #getValue(). For more, please see the default implementation of aggregators in org.apache.hama.graph package.