netkit.classifiers.aggregators
Class SharedNodeInfo

java.lang.Object
  extended by netkit.classifiers.aggregators.SharedNodeInfo

public final class SharedNodeInfo
extends java.lang.Object

The SharedNodeInfo class is used to cache aggregation statistics for a given node such that multiple aggregators can use the same statistics without having to calculate them more than once.

Currently, it is assumed that aggregators for a specific node is called in a succession before aggregation for a different node in the graph is done. Therefore, I only cache things as long is we are aggregating on the same node. This saves a lot of memory.

Author:
Sofus A. Macskassy (sofmac@gmail.com)

Method Summary
 double[] countNeighbors(Node n, Estimate prior)
          Count, for all relevant neighbors, how many of the neighboring attributes took on each of the possible values (weighted by the edge weight).
static int getAttributeIndex(java.lang.String nodeType, Attribute attrib)
           
static java.lang.String getDestinationNodeType(java.lang.String edgeType)
          Helper function to get the node type at the other end of the given edgeType
 HistogramDiscrete getHistogram(Node n)
          Get the histogram of observed values (of the neighbors of the source node) of the discrete attribute that is being aggregated over.
static SharedNodeInfo getInfo(java.lang.String nodeType, int attribIdx, EdgeType edgeType)
          Get a SharedNodeInfo instance for a given node type, attribute and edge type.
 double getMax(Node n)
          Get the maximum observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.
 double getMean(Node n)
          Get the mean observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.
 double getMin(Node n)
          Get the minium observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.
 double getSum(Node n, Estimate prior)
          Get the (weighted) sum of all relevant neighbors.
static void initialize(Graph g)
          Assume that we will be doing aggregation over this particular graph until further notice
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initialize

public static void initialize(Graph g)
Assume that we will be doing aggregation over this particular graph until further notice

Parameters:
g - The graph being aggregated over

getAttributeIndex

public static int getAttributeIndex(java.lang.String nodeType,
                                    Attribute attrib)

getInfo

public static SharedNodeInfo getInfo(java.lang.String nodeType,
                                     int attribIdx,
                                     EdgeType edgeType)
Get a SharedNodeInfo instance for a given node type, attribute and edge type.

Parameters:
nodeType - The node type of the neighbor nodes that will be aggregated over (for example, if I want to create an aggregate result on node X of type XType and I want to aggregate over attribute A on X's neighbors that are of type YType, then nodeType is 'YType')
attribIdx - What is the attribute index of the attribute to be aggregated over.
edgeType - What is the edge that is used to get from the source node (XType) to the destination node (YType). This is used to get the neighbors of a given source node when computing the aggregation statistics.
Returns:
A SharedNodeInfo instance that works for a given nodetype, attribute index and edgetype.

getDestinationNodeType

public static java.lang.String getDestinationNodeType(java.lang.String edgeType)
Helper function to get the node type at the other end of the given edgeType

Parameters:
edgeType - The edgetype whose destination node type is requested
Returns:
the node type at the other end of the given edgeType

countNeighbors

public double[] countNeighbors(Node n,
                               Estimate prior)
Count, for all relevant neighbors, how many of the neighboring attributes took on each of the possible values (weighted by the edge weight). If the prior is not null, then use the estimated values (for categorical attributes) such that is the neighbor attribute is 'red' with a likelihood of 60 percent (0.6), then count 0.6 towards 'red'.

Parameters:
n - The source node from which to find neighboring nodes
prior - The prior estimations of the values of the attribute to be aggregated on (works only for categorical attributes)
Returns:
A double array that has the count, for each possible value of the attribute, across all relevant neighbors
See Also:
getNeighborEdges(netkit.graph.Node)

getSum

public double getSum(Node n,
                     Estimate prior)
Get the (weighted) sum of all relevant neighbors. Counts all neighbors and sums up the score. This is useful to get a ratio rather than absolute count

Parameters:
n - The source node for the aggregation
prior - The estimated priors of the attribute to be aggregated on
Returns:
Get the (weighted) sum of all relevant neighbors.
See Also:
countNeighbors(netkit.graph.Node, netkit.classifiers.Estimate)

getMin

public double getMin(Node n)
Get the minium observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.

Parameters:
n - The source node to aggregate from
Returns:
The minimum observed value of the attribute over relevant neighbors

getMax

public double getMax(Node n)
Get the maximum observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.

Parameters:
n - The source node to aggregate from
Returns:
The maximum observed value of the attribute over relevant neighbors

getMean

public double getMean(Node n)
Get the mean observed value (of the neighbors of the source node) of the discrete or continuous attribute that is being aggregated over.

Parameters:
n - The source node to aggregate from
Returns:
The mean observed value of the attribute over relevant neighbors

getHistogram

public HistogramDiscrete getHistogram(Node n)
Get the histogram of observed values (of the neighbors of the source node) of the discrete attribute that is being aggregated over.

Parameters:
n - The source node to aggregate from
Returns:
The histogram of observed value of the attribute over relevant neighbors