| |
- LRAMatrix
class LRAMatrix |
|
A 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.
| |