netkit.graph.edgecreator
Class EdgeCreatorImp

java.lang.Object
  extended by netkit.graph.edgecreator.EdgeCreatorImp
All Implemented Interfaces:
EdgeCreator
Direct Known Subclasses:
BaseCategoricalEdgeCreator, BaseNumericEdgeCreator, BayesCategoricalEdgeCreator, CosineDistanceEdgeCreator, EuclideanDistanceEdgeCreator, MahalanobisDistanceEdgeCreator

public abstract class EdgeCreatorImp
extends java.lang.Object
implements EdgeCreator


Nested Class Summary
protected  class EdgeCreatorImp.NbrEntry
          Utility class for sub-classes where necessary
 
Field Summary
protected  Attribute attrib
           
protected  int attributeIndex
           
protected  double attributeValue
           
protected  Edge[] edges
           
protected  EdgeType edgetype
           
protected  GraphMetrics gm
           
protected  Graph graph
           
protected  java.util.logging.Logger logger
           
protected  int maxEdges
           
protected  java.lang.String nodeType
           
protected  DataSplit split
           
protected  double trainAssortativity
           
protected  double trueAssortativity
           
 
Constructor Summary
EdgeCreatorImp()
           
 
Method Summary
protected  void addCliqueToAssortMatrix(double[][] matrix, double[] cliqueClassDistrib)
          Utility method whch can be used by any sub-class.
protected  void buildEdges()
          build the edges using the current edge creation model.
 void buildModel(DataSplit split)
          Build a model of edge creation based on the data split.
 boolean canHandleAttributeValue(Attribute attribute)
          Queries the edge creator if it can handle (i.e., create edges for) the given attribute using a specific attribute value.
 Edge[] createEdges()
          Create all the edges on the graph provided in the initialize method (indirectly through the DataSplit object).
 double getAssortativity(boolean useTrueAssort)
          Compute the node-based assortativity of this edge creator.
 double[][] getAssortativityMatrix(boolean useTrueAssort)
           
 int getAttributeIndex()
          Which attribute is this based on.
 double getAttributeValue()
          Which attribute value is this based on.
 Edge[] getEdgesToNearestNeighbors(Node node)
          Get the edges to the K nearest nodes (highest weight using this edge creator), where max-k was provided during initialization.
 EdgeType getEdgeType()
           
 Classification getLabeledNodes(DataSplit split, boolean useTrueAssort)
          Get a classification object which contains all the nodes to be used to calculate assortativity
 int getMaxEdges()
          How many edges should there be at maximum per node?
 void initialize(Graph graph, java.lang.String nodeType, int attributeIndex, double attributeValue, int maxEdges)
          Initialize this creator.
 boolean isByAttribute()
          Is this edge creator by attribute or by instance as a whole
 boolean isByAttributeValue()
          Is this edge creator by attribute value or by attribute as a whole
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface netkit.graph.edgecreator.EdgeCreator
canHandle, getName, getWeight
 

Field Detail

logger

protected java.util.logging.Logger logger

edges

protected Edge[] edges

graph

protected Graph graph

nodeType

protected java.lang.String nodeType

attributeIndex

protected int attributeIndex

maxEdges

protected int maxEdges

attributeValue

protected double attributeValue

edgetype

protected EdgeType edgetype

gm

protected GraphMetrics gm

attrib

protected Attribute attrib

split

protected DataSplit split

trueAssortativity

protected double trueAssortativity

trainAssortativity

protected double trainAssortativity
Constructor Detail

EdgeCreatorImp

public EdgeCreatorImp()
Method Detail

initialize

public void initialize(Graph graph,
                       java.lang.String nodeType,
                       int attributeIndex,
                       double attributeValue,
                       int maxEdges)
Description copied from interface: EdgeCreator
Initialize this creator. This can only be done once

Specified by:
initialize in interface EdgeCreator
Parameters:
graph - The graph over which to create edges
nodeType - Which nodetype is the node to create edges over
attributeIndex - The attribute index over which to generate edges (ignored for creators that cannot handle attributes)
attributeValue - The attribute value over which to generate edges (ignored for creators that cannot handle values; otherwise ignored if value is Double.NaN)
maxEdges - The maximum number of outgoing edges to create from any given node

buildModel

public void buildModel(DataSplit split)
Description copied from interface: EdgeCreator
Build a model of edge creation based on the data split. Must be called before calling any analytic methods.

Specified by:
buildModel in interface EdgeCreator

getEdgeType

public final EdgeType getEdgeType()
Specified by:
getEdgeType in interface EdgeCreator

getAttributeIndex

public final int getAttributeIndex()
Description copied from interface: EdgeCreator
Which attribute is this based on.

Specified by:
getAttributeIndex in interface EdgeCreator

getMaxEdges

public final int getMaxEdges()
Description copied from interface: EdgeCreator
How many edges should there be at maximum per node?

Specified by:
getMaxEdges in interface EdgeCreator

isByAttribute

public boolean isByAttribute()
Description copied from interface: EdgeCreator
Is this edge creator by attribute or by instance as a whole

Specified by:
isByAttribute in interface EdgeCreator

isByAttributeValue

public boolean isByAttributeValue()
Description copied from interface: EdgeCreator
Is this edge creator by attribute value or by attribute as a whole

Specified by:
isByAttributeValue in interface EdgeCreator

canHandleAttributeValue

public boolean canHandleAttributeValue(Attribute attribute)
Description copied from interface: EdgeCreator
Queries the edge creator if it can handle (i.e., create edges for) the given attribute using a specific attribute value.

Specified by:
canHandleAttributeValue in interface EdgeCreator
Returns:
true if this edge creator can create edges based on the given Attribute if given a specific attribute value

getAttributeValue

public final double getAttributeValue()
Description copied from interface: EdgeCreator
Which attribute value is this based on.

Specified by:
getAttributeValue in interface EdgeCreator

addCliqueToAssortMatrix

protected final void addCliqueToAssortMatrix(double[][] matrix,
                                             double[] cliqueClassDistrib)
Utility method whch can be used by any sub-class. Adds

Parameters:
matrix - An assortativity matrix
cliqueClassDistrib - The number of nodes for each class in the incoming clique

getLabeledNodes

public final Classification getLabeledNodes(DataSplit split,
                                            boolean useTrueAssort)
Get a classification object which contains all the nodes to be used to calculate assortativity

Parameters:
split - The data train/test split to use
useTrueAssort - If true, use all objects, otherwise use only nods from training set (given in DataSplit object during initialize)
Throws:
java.lang.IllegalArgumentException - if creator has not yet been initialized

getEdgesToNearestNeighbors

public Edge[] getEdgesToNearestNeighbors(Node node)
Get the edges to the K nearest nodes (highest weight using this edge creator), where max-k was provided during initialization. This goes through all nodes in the graph, so sub-classes should override to provide a more optimized version. This list should include all nearest neighbors, not only those in the 'training set'. It will look for a cutoff in weights less than k, but if the first k weights are all the same then it will look forward to the first cutoff. This may mean that all nodes are neighbors if all weights are the same.

Parameters:
node - The node
Returns:

getAssortativityMatrix

public double[][] getAssortativityMatrix(boolean useTrueAssort)

getAssortativity

public final double getAssortativity(boolean useTrueAssort)
Description copied from interface: EdgeCreator
Compute the node-based assortativity of this edge creator. This is calculated by computing the assortativity of the nodes, using only the edges that this edge creator would create (creating no more then maxEdges outgoing edges per node if possible -- this is provided in the initialize method).

Specified by:
getAssortativity in interface EdgeCreator
Parameters:
useTrueAssort - Should we compute assortativity based on the whole truth or just the training set

createEdges

public final Edge[] createEdges()
Description copied from interface: EdgeCreator
Create all the edges on the graph provided in the initialize method (indirectly through the DataSplit object). It will create no more than maxEdges outgoing edges (if possible), as provided in the initialize method.

Specified by:
createEdges in interface EdgeCreator

buildEdges

protected void buildEdges()
build the edges using the current edge creation model. If you want to use the default buildAssortativityMatrix method and if you override this method, then you must add edges such that they are grouped by source node (i.e., all edges with the same source node appear sequentially in the edges array). This assumption is leverage by the default getAssortativityMatrix method for efficiency.