Class InMemoryGraphLookupTable

    • 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 graph
      org.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 idx
      org.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 rate
      void 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
      • 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()
      • 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 index
        second - 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 vertex
        second - 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)
      • getInnerNodeVector

        public org.nd4j.linalg.api.ndarray.INDArray getInnerNodeVector​(int innerNode)
      • setVertexVectors

        public void setVertexVectors​(org.nd4j.linalg.api.ndarray.INDArray vertexVectors)