Class InMemoryGraphLookupTable
- java.lang.Object
-
- org.deeplearning4j.graph.models.embeddings.InMemoryGraphLookupTable
-
- All Implemented Interfaces:
GraphVectorLookupTable
public class InMemoryGraphLookupTable extends Object implements GraphVectorLookupTable
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
expTable
protected double
learningRate
protected static double
MAX_EXP
protected int
nVertices
protected org.nd4j.linalg.api.ndarray.INDArray
outWeights
protected BinaryTree
tree
protected int
vectorSize
protected org.nd4j.linalg.api.ndarray.INDArray
vertexVectors
-
Constructor Summary
Constructors Constructor Description InMemoryGraphLookupTable(int nVertices, int vectorSize, BinaryTree tree, double learningRate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
calculateProb(int first, int second)
Calculate the probability of the second vertex given the first vertex i.e., P(v_second | v_first)double
calculateScore(int first, int second)
Calculate score.org.nd4j.linalg.api.ndarray.INDArray
getInnerNodeVector(int innerNode)
int
getNumVertices()
Returns the number of vertices in the graphorg.nd4j.linalg.api.ndarray.INDArray
getOutWeights()
BinaryTree
getTree()
org.nd4j.linalg.api.ndarray.INDArray
getVector(int idx)
Get the vector for the vertex with index idxorg.nd4j.linalg.api.ndarray.INDArray
getVertexVectors()
void
iterate(int first, int second)
Conduct learning given a pair of vertices (in and out)void
resetWeights()
Reset (randomize) the weights.void
setLearningRate(double learningRate)
Set the learning ratevoid
setVertexVectors(org.nd4j.linalg.api.ndarray.INDArray vertexVectors)
org.nd4j.linalg.api.ndarray.INDArray[][]
vectorsAndGradients(int first, int second)
Returns vertex vector and vector gradients, plus inner node vectors and inner node gradients
Specifically, out[0] are vectors, out[1] are gradients for the corresponding vectors
out[0][0] is vector for first vertex; out[0][1] is gradient for this vertex vector
out[0][i] (i>0) is the inner node vector along path to second vertex; out[1][i] is gradient for inner node vertex
This design is used primarily to aid in testing (numerical gradient checks)int
vectorSize()
The size of the vector representations
-
-
-
Field Detail
-
nVertices
protected int nVertices
-
vectorSize
protected int vectorSize
-
tree
protected BinaryTree tree
-
vertexVectors
protected org.nd4j.linalg.api.ndarray.INDArray vertexVectors
-
outWeights
protected org.nd4j.linalg.api.ndarray.INDArray outWeights
-
learningRate
protected double learningRate
-
expTable
protected double[] expTable
-
MAX_EXP
protected static double MAX_EXP
-
-
Constructor Detail
-
InMemoryGraphLookupTable
public InMemoryGraphLookupTable(int nVertices, int vectorSize, BinaryTree tree, double learningRate)
-
-
Method Detail
-
getVertexVectors
public org.nd4j.linalg.api.ndarray.INDArray getVertexVectors()
-
getOutWeights
public org.nd4j.linalg.api.ndarray.INDArray getOutWeights()
-
vectorSize
public int vectorSize()
Description copied from interface:GraphVectorLookupTable
The size of the vector representations- Specified by:
vectorSize
in interfaceGraphVectorLookupTable
-
resetWeights
public void resetWeights()
Description copied from interface:GraphVectorLookupTable
Reset (randomize) the weights.- Specified by:
resetWeights
in interfaceGraphVectorLookupTable
-
iterate
public void iterate(int first, int second)
Description copied from interface:GraphVectorLookupTable
Conduct learning given a pair of vertices (in and out)- Specified by:
iterate
in interfaceGraphVectorLookupTable
-
vectorsAndGradients
public org.nd4j.linalg.api.ndarray.INDArray[][] vectorsAndGradients(int first, int second)
Returns vertex vector and vector gradients, plus inner node vectors and inner node gradients
Specifically, out[0] are vectors, out[1] are gradients for the corresponding vectors
out[0][0] is vector for first vertex; out[0][1] is gradient for this vertex vector
out[0][i] (i>0) is the inner node vector along path to second vertex; out[1][i] is gradient for inner node vertex
This design is used primarily to aid in testing (numerical gradient checks)- Parameters:
first
- first (input) vertex indexsecond
- second (output) vertex index
-
calculateProb
public double calculateProb(int first, int second)
Calculate the probability of the second vertex given the first vertex i.e., P(v_second | v_first)- Parameters:
first
- index of the first vertexsecond
- index of the second vertex- Returns:
- probability, P(v_second | v_first)
-
calculateScore
public double calculateScore(int first, int second)
Calculate score. -log P(v_second | v_first)
-
getTree
public BinaryTree getTree()
-
getInnerNodeVector
public org.nd4j.linalg.api.ndarray.INDArray getInnerNodeVector(int innerNode)
-
getVector
public org.nd4j.linalg.api.ndarray.INDArray getVector(int idx)
Description copied from interface:GraphVectorLookupTable
Get the vector for the vertex with index idx- Specified by:
getVector
in interfaceGraphVectorLookupTable
-
setLearningRate
public void setLearningRate(double learningRate)
Description copied from interface:GraphVectorLookupTable
Set the learning rate- Specified by:
setLearningRate
in interfaceGraphVectorLookupTable
-
getNumVertices
public int getNumVertices()
Description copied from interface:GraphVectorLookupTable
Returns the number of vertices in the graph- Specified by:
getNumVertices
in interfaceGraphVectorLookupTable
-
setVertexVectors
public void setVertexVectors(org.nd4j.linalg.api.ndarray.INDArray vertexVectors)
-
-