SSDE.h

This file contains the code for the Spectral Graph Embedding Method via Sampled Spectral Distance Embedding (SSDE).  Given a graph this program returns the embedding of the nodes into Cartesian space where the Euclidean distances between nodes approximates the path distance in the original graph.

Authors

Eli Bocek-Rivele, Ali Civril, and Jonathan Purnell.

Summary
SSDE.hThis file contains the code for the Spectral Graph Embedding Method via Sampled Spectral Distance Embedding (SSDE).
Enumerations
Type of Sampling nodes
NodeThis class holds the information for a node in the graph.
Node Name File
Graph File
Coordinates File
Functions
NodeDefault constructor (puts space for 5 neighbors)
NodeConstructor that allocates memory for info on node’s neighbors.
insertAdds neighbor and edge weight.
resizeAllocates more memory for neighbor info.
dotProductCalculate dot product of two vectors.
magCalculate magnitude of vector.
normalizeNormalizes vector in-place
multConsReturns vector resulting from multiplying input vector by input constant.
minusSSDEReturns the difference between two vectors.
multGammaReturns vector who’s elements average to zero.
makeOrthoMakes first input vector orthogonal to second input vector.
multLMultiplies C*INV*R
multGammaLGammaSimplifies the sequence of multiplying input vector by Gamma, by L and then by Gamma again.
readNodesLoads the list of nodes names.
readFileLoads the graph data.
writeFileWrites the coordinates of the embedded nodes.
BFSBreadth First Search.
allBFSBased on sampling method, samples nodes from the graph and determines the distances from the sampled nodes to all other nodes in the graph.
randomSampleCRSamples nodes from the graph randomly.
houseReturns the householder vector and the associated beta, given the size and the vector x.
bidiagonalizeBidiagonalizes a given matrix A by overwriting it, also returns Ue and Ve which are the elements in the expression Ue^T*A*Ve = B (A is overwritten as B) A is supposed to be an m*n matrix where m >= n, Ub is m*m, Vb is n*n
givenscomputes cos(theta) c and sin(theta) c given a and b.
SVDstepApplies Givens rotations to the matrix on B bounded by upper and lower indices (call this Bbar).
sampleCalculates all the necessary matrices involved in sampling (also performs the SVD algorithm).
powerIterationPerforms power iterations to find the largest eigenvectors of our distance matrix.
normalizeCoordsNormalizes the coordinates of the embedded graph.
writeGraphFunction for finding the Strongly Connected Components in the graph.
TarjanFunction to perform the Tarjan algorithm.

Enumerations

Type of Sampling nodes

RANDOM_SAMPLINGnode sampling is done randomly
GREEDY_SAMPLINGnode sampling is done by choosing the farthest node

Node

This class holds the information for a node in the graph.

Node Name File

  • First line of the file has the number of nodes
  • Subsequent lines correspond to each node and contain the name of the node and the number of neighboring node

Graph File

  • First line of the file has the number of nodes
  • Subsequent lines correspond to each edge and contains the names of the two nodes followed by the edge weight
  • Note that this graph must be an undirected connected graph.  The code doesn’t not check for this, and if the graph is not connected the code will produce erroneous results.

Coordinates File

  • First line of the file has the number of nodes
  • Subsequent lines correspond to each node and contains the coordinates of the embedded node
Summary
Functions
NodeDefault constructor (puts space for 5 neighbors)
NodeConstructor that allocates memory for info on node’s neighbors.
insertAdds neighbor and edge weight.
resizeAllocates more memory for neighbor info.
dotProductCalculate dot product of two vectors.
magCalculate magnitude of vector.
normalizeNormalizes vector in-place
multConsReturns vector resulting from multiplying input vector by input constant.
minusSSDEReturns the difference between two vectors.
multGammaReturns vector who’s elements average to zero.
makeOrthoMakes first input vector orthogonal to second input vector.
multLMultiplies C*INV*R
multGammaLGammaSimplifies the sequence of multiplying input vector by Gamma, by L and then by Gamma again.
readNodesLoads the list of nodes names.
readFileLoads the graph data.
writeFileWrites the coordinates of the embedded nodes.
BFSBreadth First Search.
allBFSBased on sampling method, samples nodes from the graph and determines the distances from the sampled nodes to all other nodes in the graph.
randomSampleCRSamples nodes from the graph randomly.
houseReturns the householder vector and the associated beta, given the size and the vector x.
bidiagonalizeBidiagonalizes a given matrix A by overwriting it, also returns Ue and Ve which are the elements in the expression Ue^T*A*Ve = B (A is overwritten as B) A is supposed to be an m*n matrix where m >= n, Ub is m*m, Vb is n*n
givenscomputes cos(theta) c and sin(theta) c given a and b.
SVDstepApplies Givens rotations to the matrix on B bounded by upper and lower indices (call this Bbar).
sampleCalculates all the necessary matrices involved in sampling (also performs the SVD algorithm).
powerIterationPerforms power iterations to find the largest eigenvectors of our distance matrix.
normalizeCoordsNormalizes the coordinates of the embedded graph.
writeGraphFunction for finding the Strongly Connected Components in the graph.
TarjanFunction to perform the Tarjan algorithm.

Functions

Node

Node(string name)

Default constructor (puts space for 5 neighbors)

Parameters

namestring with the name of this node

Node

Node(string name,
int num_neighbors)

Constructor that allocates memory for info on node’s neighbors.

Parameters

namestring with the name of this node
num_neighborsinteger number of neighbors to this node

insert

void insert(int neighbor,
double dist)

Adds neighbor and edge weight.

Parameters

neighborindex of neighboring node
distedge weight (i.e. distance) between this node and the neighbor

resize

void resize(int newSize)

Allocates more memory for neighbor info.

Parameters

newSizenew number of neighbors

dotProduct

Calculate dot product of two vectors.

mag

Calculate magnitude of vector.

normalize

Normalizes vector in-place

multCons

Returns vector resulting from multiplying input vector by input constant.

minusSSDE

Returns the difference between two vectors.

multGamma

Returns vector who’s elements average to zero.

makeOrtho

Makes first input vector orthogonal to second input vector.

multL

Multiplies C*INV*R

multGammaLGamma

Simplifies the sequence of multiplying input vector by Gamma, by L and then by Gamma again.

readNodes

void readNodes(char *fileName)

Loads the list of nodes names.  The format of this file is outlined in Node Name File.  A hash table is create so that the node names can be translated to their index in nodes[] in constant time.

readFile

void readFile(char *fileName)

Loads the graph data.  Format of this file follows Graph File.

writeFile

void writeFile(char *fileName)

Writes the coordinates of the embedded nodes.  Format of the file follows Coordinates File.

BFS

Breadth First Search.  Calculates the distance from given node to all other nodes in the graph.

allBFS

void allBFS(int samplingMethod)

Based on sampling method, samples nodes from the graph and determines the distances from the sampled nodes to all other nodes in the graph.  The C and PHI matrices are then computed.

Parameter

samplingMethodindicates the sampling method

randomSampleCR

Samples nodes from the graph randomly.

house

void house(double *v,
double *x,
int size,
double *beta)

Returns the householder vector and the associated beta, given the size and the vector x.

bidiagonalize

void bidiagonalize(double **A,
double **Ub,
double **Vb,
int m,
int n)

Bidiagonalizes a given matrix A by overwriting it, also returns Ue and Ve which are the elements in the expression Ue^T*A*Ve = B (A is overwritten as B) A is supposed to be an m*n matrix where m >= n, Ub is m*m, Vb is n*n

givens

void givens(double a,
double b,
double *c,
double *s)

computes cos(theta) c and sin(theta) c given a and b.  [c s]^T[a] = [r].  [-s c]^T[b] = [0].

SVDstep

void SVDstep(double **B,
double **Ue,
double **Ve,
int lower,
int upper)

Applies Givens rotations to the matrix on B bounded by upper and lower indices (call this Bbar).  Overwrites Bbar with Ue^T*B*Ve, also calculates Ue and Ve in this formula Ue and Ve are treated as a whole (not only the parts remaining between upper and lower indices) They are first initialized to I, and accumulated accordingly.

sample

void sample()

Calculates all the necessary matrices involved in sampling (also performs the SVD algorithm).

powerIteration

void powerIteration()

Performs power iterations to find the largest eigenvectors of our distance matrix.

normalizeCoords

void normalizeCoords()

Normalizes the coordinates of the embedded graph.

writeGraph

void writeGraph(std::deque<int> &S)

Function for finding the Strongly Connected Components in the graph.  The largest SCC is written to coauthors_scc.

Tarjan

void Tarjan(int v,
int &index,
std::deque<int> &S,
ofstream &scc_file)

Function to perform the Tarjan algorithm.

Node(string name)
Default constructor (puts space for 5 neighbors)
void insert(int neighbor,
double dist)
Adds neighbor and edge weight.
void resize(int newSize)
Allocates more memory for neighbor info.
void readNodes(char *fileName)
Loads the list of nodes names.
void readFile(char *fileName)
Loads the graph data.
void writeFile(char *fileName)
Writes the coordinates of the embedded nodes.
void allBFS(int samplingMethod)
Based on sampling method, samples nodes from the graph and determines the distances from the sampled nodes to all other nodes in the graph.
void house(double *v,
double *x,
int size,
double *beta)
Returns the householder vector and the associated beta, given the size and the vector x.
void bidiagonalize(double **A,
double **Ub,
double **Vb,
int m,
int n)
Bidiagonalizes a given matrix A by overwriting it, also returns Ue and Ve which are the elements in the expression Ue^T*A*Ve = B (A is overwritten as B) A is supposed to be an m*n matrix where m >= n, Ub is m*m, Vb is n*n
void givens(double a,
double b,
double *c,
double *s)
computes cos(theta) c and sin(theta) c given a and b.
void SVDstep(double **B,
double **Ue,
double **Ve,
int lower,
int upper)
Applies Givens rotations to the matrix on B bounded by upper and lower indices (call this Bbar).
void sample()
Calculates all the necessary matrices involved in sampling (also performs the SVD algorithm).
void powerIteration()
Performs power iterations to find the largest eigenvectors of our distance matrix.
void normalizeCoords()
Normalizes the coordinates of the embedded graph.
void writeGraph(std::deque<int> &S)
Function for finding the Strongly Connected Components in the graph.
void Tarjan(int v,
int &index,
std::deque<int> &S,
ofstream &scc_file)
Function to perform the Tarjan algorithm.
Close