infomat.vectorspace
Class IMatrix

java.lang.Object
  extended by infomat.vectorspace.IMatrix

public class IMatrix
extends java.lang.Object

IMatrix represents the relations between two IObjectSet:s. The IMatrixCell class represents the elements of this IMatrix. This is implemented considering sparse matrices. The IMatrixCells are stored in a DoubleHashMap and are the non zero matrix elements.


Field Summary
private  DoubleHashMap cellMap
           
private  IObjectSet cols
           
private static float maxW
           
private  java.util.HashMap<IObject,java.lang.Float> objectGlobalWeightMap
           
private  IObjectSet rows
           
 
Constructor Summary
IMatrix(IMatrix m)
          Copy constructor.
IMatrix(java.lang.String columnLabel, java.lang.String rowLabel)
           
 
Method Summary
 boolean addCell(IMatrixCell mc)
          Add a IMatrixCell.
 boolean addCell(int ri, int ci, float weight)
          Add the value of a column in a row
 boolean addCell(int ri, int ci, float localCount, float weight)
          Add the value of a column in a row
 boolean addCell(int ri, int ci, float localCount, float localWeight, float weight)
          Add the value of a column in a row
 void addColumnIObject(IObject colObj)
          Adds a Column IObject to the matrix.
 void addDocument(java.lang.String d, int di)
          adds a Document as a Row to the matrix
 void addDocument(java.lang.String d, java.lang.String f, int di)
          adds a Document as a Row to the matrix
 void addRowIObject(IObject rowObj)
          Adds a Row IObject to the matrix.
 void addWord(java.lang.String w, int ws)
          adds a Word as Column to the matrix
 void addWord(java.lang.String w, int ws, float globalWeight)
          adds a Word as a Column IObject to the matrix
 double avgColsInRows()
           
 double avgRowsInCols()
           
 boolean columnIObjectSet(IObjectSet ios)
           
 IObjectGroup constructCorrespondingGroup(IObjectGroup group)
          Returns the corresponding group, i.e.
 java.util.Vector getAllCells()
          Returns the DoubleHashMap containing all non zero elements of the IMatrix.
 IMatrixCell getCell(IObject row, IObject col)
          Returns the IMatrixCell for the IObject "row" in the "row" IObjectSet and the IObject "col" in the "column" IObjectSet
 DoubleHashMap getCellMap()
          Returns the DoubleHashMap containing all non zero elements of the IMatrix.
 java.util.Vector getCellsWith(IObject co)
          Returns a Vector of all the IMatrixCells that contains the given IObject.
 java.util.Vector getCellsWithIObjectRestrictedToGroup(IObject io, IObjectGroup restrictionGroup)
          Returns a Vector of the IMatrixCell:s that contains the given IObject AND any of the IObjects in the restrictionGroup.
 java.util.HashSet getColumnIMatrixCellsForRowObject(IObject rowObject)
           
 IObjectSet getColumnIObjectSet()
          Returns the "column" IObjectSet.
 IObjectGrouping getCurrentColumnGrouping()
          Returns the current IObjectGrouping for the columns.
 IObjectGrouping getCurrentRowGrouping()
          Returns the current IObjectGrouping for the rows.
 java.awt.Dimension getCurrentSize()
          Returns a Dimension with x-size as the number of "columns" and y-size as the number of "rows" of the IMatrix.
 float getGlobalWeight(IObject io)
          Returns 0 if the IObject has not been weighted.
 java.util.HashSet<IObject> getOtherIObjectsForIObject(IObject io)
          Returns all IObject:s the specified IObject share a IMatrixCell with.
 java.util.HashSet getRowIMatrixCellsForColumnObject(IObject colObject)
          Returns a Vector of the IMatrixCells that contains the given IObject.
 IObjectSet getRowIObjectSet()
          Returns the "row" IObjectSet.
 java.awt.Dimension getSize()
          Returns a Dimension with x-size as the number of "columns" and y-size as the number of "rows" of the IMatrix.
 java.util.HashMap<IObject,java.lang.Float> getTotalWeight(boolean row, boolean localWeight)
          Returns the total weight for each object along the specified dimension.
 void invertMatrix()
           
 void purgeMatrixToCurrentGroupings()
          Removes all IObjects that's not in the current IObjectGroupings from the sets and all their IObjectGroupings.
 void removeAllCells()
          Revmove all IMatrixCell from the IMatrix.
 void removeCell(IMatrixCell mc)
          Removes a IMatrixCell from the IMatrix.
 void removeCells(IVector<IMatrixCell> ivec)
           
 void resort()
          Resorts the IObjectSet:s "rows" and "cols" according to their current IObjectGroupings.
 boolean rowIObjectSet(IObjectSet ios)
           
 void saveIMatrix(java.io.File file)
           
 void saveIObjectGroupingFile(IObjectGrouping grouping, java.io.File file)
           
 void setColumnIObjectSet(IObjectSet set)
          Sets the "column" IObjectSet.
 void setGlobalWeight(IObject io, float globalWeight)
           
 void setRowIObjectSet(IObjectSet set)
          Sets the "row" IObjectSet.
 IMatrix subMatrix(IObjectGroup rowGroup, IObjectGroup colGroup)
          Returns a copy of the specified portion of the matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rows

private IObjectSet rows

cols

private IObjectSet cols

cellMap

private DoubleHashMap cellMap

maxW

private static float maxW

objectGlobalWeightMap

private java.util.HashMap<IObject,java.lang.Float> objectGlobalWeightMap
Constructor Detail

IMatrix

public IMatrix(java.lang.String columnLabel,
               java.lang.String rowLabel)

IMatrix

public IMatrix(IMatrix m)
Copy constructor. Makes new instances of everything, but the IObject:s, which are the same.

Method Detail

subMatrix

public IMatrix subMatrix(IObjectGroup rowGroup,
                         IObjectGroup colGroup)
Returns a copy of the specified portion of the matrix. The IMatrixCell:s are copied, but the IObject:s are the same. The global weights of the IObject:s are not kept.


addWord

public void addWord(java.lang.String w,
                    int ws)
adds a Word as Column to the matrix

Parameters:
w - The Word as a string
ws - A unique identifier of the word

addWord

public void addWord(java.lang.String w,
                    int ws,
                    float globalWeight)
adds a Word as a Column IObject to the matrix

Parameters:
w - The Word as a string
ws - A unique identifier of the word
globalWeight - The global weight of the word

addColumnIObject

public void addColumnIObject(IObject colObj)
Adds a Column IObject to the matrix. OBS. If you add the same object again it will be added, which may lead to confusion.


addDocument

public void addDocument(java.lang.String d,
                        int di)
adds a Document as a Row to the matrix

Parameters:
d - The source of the document
di - A unique identifier of the document

addDocument

public void addDocument(java.lang.String d,
                        java.lang.String f,
                        int di)
adds a Document as a Row to the matrix

Parameters:
d - The source of the document
f - The location of the document
di - A unique identifier of the document
See Also:
IObject

addRowIObject

public void addRowIObject(IObject rowObj)
Adds a Row IObject to the matrix. OBS. If you add the same object again it will be added, which may lead to confusion.


addCell

public boolean addCell(IMatrixCell mc)
Add a IMatrixCell.

Parameters:
mc - the Matrix cell
Returns:
true if the corresponding IObjects exist in the IObjectSet:s, false otherwise.

addCell

public boolean addCell(int ri,
                       int ci,
                       float weight)
Add the value of a column in a row

Parameters:
ri - The unique identifier of the row
ci - The unique identifier of the column
weight - The value of the column in the row
Returns:
true if row and column exists, false otherwise

addCell

public boolean addCell(int ri,
                       int ci,
                       float localCount,
                       float weight)
Add the value of a column in a row

Parameters:
ri - The unique identifier of the row
ci - The unique identifier of the column
weight - The value of the column in the row
Returns:
true if row and column exists, false otherwise

addCell

public boolean addCell(int ri,
                       int ci,
                       float localCount,
                       float localWeight,
                       float weight)
Add the value of a column in a row

Parameters:
ri - The unique identifier of the row
ci - The unique identifier of the column
weight - The value of the column in the row
Returns:
true if row and column exists, false otherwise

constructCorrespondingGroup

public IObjectGroup constructCorrespondingGroup(IObjectGroup group)
Returns the corresponding group, i.e. a group along the other dimension that contains all IObjects that are associated with the IObject:s of the given group.


getCellsWith

public java.util.Vector getCellsWith(IObject co)
Returns a Vector of all the IMatrixCells that contains the given IObject. Each IMatrixCell is returned in one position only.


rowIObjectSet

public boolean rowIObjectSet(IObjectSet ios)

columnIObjectSet

public boolean columnIObjectSet(IObjectSet ios)

getTotalWeight

public java.util.HashMap<IObject,java.lang.Float> getTotalWeight(boolean row,
                                                                 boolean localWeight)
Returns the total weight for each object along the specified dimension.

Parameters:
row - - true: weight for row objects, false: weight for column objects
localWeight - - true: the localWeght, false: the weight

purgeMatrixToCurrentGroupings

public void purgeMatrixToCurrentGroupings()
Removes all IObjects that's not in the current IObjectGroupings from the sets and all their IObjectGroupings. Also removes all corresponding IMatrixCells.


invertMatrix

public void invertMatrix()

getRowIObjectSet

public IObjectSet getRowIObjectSet()
Returns the "row" IObjectSet.


getColumnIObjectSet

public IObjectSet getColumnIObjectSet()
Returns the "column" IObjectSet.


setRowIObjectSet

public void setRowIObjectSet(IObjectSet set)
Sets the "row" IObjectSet. WARNING. This is usually not a good idea!


setColumnIObjectSet

public void setColumnIObjectSet(IObjectSet set)
Sets the "column" IObjectSet. WARNING. This is usually not a good idea!


getCurrentRowGrouping

public IObjectGrouping getCurrentRowGrouping()
Returns the current IObjectGrouping for the rows.


getCurrentColumnGrouping

public IObjectGrouping getCurrentColumnGrouping()
Returns the current IObjectGrouping for the columns.


getCellMap

public DoubleHashMap getCellMap()
Returns the DoubleHashMap containing all non zero elements of the IMatrix.


getAllCells

public java.util.Vector getAllCells()
Returns the DoubleHashMap containing all non zero elements of the IMatrix.


getCell

public IMatrixCell getCell(IObject row,
                           IObject col)
Returns the IMatrixCell for the IObject "row" in the "row" IObjectSet and the IObject "col" in the "column" IObjectSet


removeCell

public void removeCell(IMatrixCell mc)
Removes a IMatrixCell from the IMatrix. Does not remove the corresponding IObjects from the IObjectSet:s.

Parameters:
mc - An IMatrixCell

removeCells

public void removeCells(IVector<IMatrixCell> ivec)

removeAllCells

public void removeAllCells()
Revmove all IMatrixCell from the IMatrix. Does not remove the corresponding IObjects from the IObjectSet:s.


getSize

public java.awt.Dimension getSize()
Returns a Dimension with x-size as the number of "columns" and y-size as the number of "rows" of the IMatrix.


getCurrentSize

public java.awt.Dimension getCurrentSize()
Returns a Dimension with x-size as the number of "columns" and y-size as the number of "rows" of the IMatrix. This is the size of the matrix seen through the current row and column groupings.


resort

public void resort()
Resorts the IObjectSet:s "rows" and "cols" according to their current IObjectGroupings.


getCellsWithIObjectRestrictedToGroup

public java.util.Vector getCellsWithIObjectRestrictedToGroup(IObject io,
                                                             IObjectGroup restrictionGroup)
Returns a Vector of the IMatrixCell:s that contains the given IObject AND any of the IObjects in the restrictionGroup.


getRowIMatrixCellsForColumnObject

public java.util.HashSet getRowIMatrixCellsForColumnObject(IObject colObject)
Returns a Vector of the IMatrixCells that contains the given IObject. OBS. This does not work properly if the same IObjectSet is used for both rows and columns. Thus to construct a word-word-matrix, for instance, you should have each word as two different IObject:s.


getColumnIMatrixCellsForRowObject

public java.util.HashSet getColumnIMatrixCellsForRowObject(IObject rowObject)

getOtherIObjectsForIObject

public java.util.HashSet<IObject> getOtherIObjectsForIObject(IObject io)
Returns all IObject:s the specified IObject share a IMatrixCell with.


saveIMatrix

public void saveIMatrix(java.io.File file)

saveIObjectGroupingFile

public void saveIObjectGroupingFile(IObjectGrouping grouping,
                                    java.io.File file)

avgColsInRows

public double avgColsInRows()

avgRowsInCols

public double avgRowsInCols()

setGlobalWeight

public void setGlobalWeight(IObject io,
                            float globalWeight)

getGlobalWeight

public float getGlobalWeight(IObject io)
Returns 0 if the IObject has not been weighted.