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 matrixes. The IMatrixCells are stored in a DoubleHashMap and are the non-zero matrix elements.


Field Summary
private  DoubleHashMap cellMap
           
private  java.util.HashMap<IObject,java.lang.Float> colIObjectGlobalWeightMap
           
private  IObjectSet cols
           
private  java.util.HashMap<IObject,java.lang.Float> rowIObjectGlobalWeightMap
           
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 addRowIObject(IObject rowObj)
          Adds a Row 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)
           
 float getColumnIObjectGlobalWeight(IObject io)
          Returns 0 if the IObject has not been weighted.
 IObjectSet getColumnIObjectSet()
          Returns the "column" IObjectSet.
 IVector<IMatrixCell> getIVectorOfElements()
          Returns an IVector with all cells and their weights.
 java.lang.String getNumberOfRowsColumnsCellsString()
           
 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.
 float getRowIObjectGlobalWeight(IObject io)
          Returns 0 if the IObject has not been weighted.
 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 purgeMatrixToGroups(IObjectGroup rowGroup, IObjectGroup columnGroup)
          Removes all IObjects that's not in the specified row and colum group.
 void removeAllCells()
          Revmove all IMatrixCell from the IMatrix.
 void removeCell(IMatrixCell mc)
          Removes a IMatrixCell from the IMatrix.
 void removeCells(IVector<IMatrixCell> ivec)
           
 void removeColumnIObjectGlobalWeight(IObject io)
           
 void removeRowIObjectGlobalWeight(IObject io)
           
 boolean rowIObjectSet(IObjectSet ios)
           
 void saveIMatrix(java.io.File file)
           
 void saveIObjectGroupingFile(IObjectGrouping grouping, java.io.File file)
           
 void setColumnIObjectGlobalWeight(IObject io, float globalWeight)
           
 void setColumnIObjectSet(IObjectSet set)
          Sets the "column" IObjectSet.
 void setRowIObjectGlobalWeight(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

rowIObjectGlobalWeightMap

private java.util.HashMap<IObject,java.lang.Float> rowIObjectGlobalWeightMap

colIObjectGlobalWeightMap

private java.util.HashMap<IObject,java.lang.Float> colIObjectGlobalWeightMap
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.


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.


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.


getNumberOfRowsColumnsCellsString

public java.lang.String getNumberOfRowsColumnsCellsString()

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

purgeMatrixToGroups

public void purgeMatrixToGroups(IObjectGroup rowGroup,
                                IObjectGroup columnGroup)
Removes all IObjects that's not in the specified row and colum group. 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!


getIVectorOfElements

public IVector<IMatrixCell> getIVectorOfElements()
Returns an IVector with all cells and their weights.


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.


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()

setRowIObjectGlobalWeight

public void setRowIObjectGlobalWeight(IObject io,
                                      float globalWeight)

setColumnIObjectGlobalWeight

public void setColumnIObjectGlobalWeight(IObject io,
                                         float globalWeight)

removeRowIObjectGlobalWeight

public void removeRowIObjectGlobalWeight(IObject io)

removeColumnIObjectGlobalWeight

public void removeColumnIObjectGlobalWeight(IObject io)

getRowIObjectGlobalWeight

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


getColumnIObjectGlobalWeight

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