matrix
index
/home/max/LRApy/matrix.py

Project: LRApy
Author: Max Jakob (max.jakob@web.de)
Module: matrix
Module Description: This module provides a matrix data structure, entropy
and SVD calculations, and a cosinus similarity function.
 
Version: 1.1
Last change: 2007-02-15
 
Copyright 2007 by Max Jakob.
This code is released under the GNU GPL. See the accompanying LICENSE file.
 
Embedded documentation can be translated with the Python pydoc module.

 
Modules
       
math
numpy

 
Classes
       
LRAMatrix

 
class LRAMatrix
    LRAMatrix instance represents a matrix inside which the
relational similarity between word pairs can be computed.
<matrix> is a two-dimensional numpy-array.
<rows> is a mapping from word pairs to their row number in <matrix>,
so that the word pairs and their vectors can be found easily.
 
  Methods defined here:
__init__(self)
__str__(self)
Returns an unsorted string of the self.matrix, in which the
rows are labeled with the actual word pairs.
applyEntropy(self)
Apply log and entropy transformations to the matrix.
applySVD(self, k)
Apply Singular Valus Decomposition (SVD) to the matrix, and project
to <k> columns. Sigma is a one-dimensional array of non-zero diagonal
elements of sigma in descending order. It is converted in a kxk array
to be able to multiply the matrices.
We drop vt (V transposed), because it can be shown that is not important 
for the cosinus similarity.
getRowNumber(self, wordPairTuple)
Returns the row number of the word pair of <wordPairTuple>.
getRowVector(self, wordPairTuple)
Returns the row vector of the word pair of <wordPairTuple>.
setWordPairVector(self, wordPairTuple, vector)
Appends <vector> to the matrix and adds a mapping of
<wordPairTuple> to the right row number to the self.rows
dictionary. The length of the two word pairs is also checked,
for string formatting porpuses.

 
Functions
       
cosinus(vector1, vector2)
Returns the cosinus similarity for two one-dimensional vectors of
the same length as a float.
getEmptyVector(vectorLen)
Returns an empty one-dimensional numpy.array with length <vectorLen>.
mergeVectors(vector1, vector2)
Merges two vectors of the same dimension.