public class SOMLibClassInformation
extends java.lang.Object
InputData
input vectors.
The file format consists of a header
and the content as follows:
InputData.numVectors()
). See also an example file from the Iris data set.
Alternatively, the file format can be more simple, and not contain any file header. Then, there is only a list of
lines with two tabulator-seperated Strings
in the form of labelName className
.
The number of classes, and the indices of those classes, are computer automatically.
Finally, the simplest form of the file is to have lines with just the class label; then, this class is assigned to
the input datum with the index of the line number.
The number of classes, and the indices of those classes, are computer automatically.
Modifier and Type | Class and Description |
---|---|
static interface |
SOMLibClassInformation.ClassColorChangeListener |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
classInformationFileName
The file name to read from.
|
private int[] |
classMemberCount
The number of inputs in each class.
|
private java.lang.String[] |
classNames
The names of the classes.
|
private java.util.ArrayList<java.lang.String> |
classNamesTemp |
private java.util.ArrayList<SOMLibClassInformation.ClassColorChangeListener> |
colorChangeListeners |
private int[] |
dataClasses
A mapping input index => class index, for fast lookup.
|
private java.util.HashMap<java.lang.String,java.lang.Integer> |
dataHash
Mapping class name => class index, for fast lookup.
|
private java.util.HashMap<java.lang.String,java.lang.String> |
dataHashTemp |
private java.lang.String[] |
dataNames |
private java.util.ArrayList<java.lang.String> |
dataNamesTemp |
private static java.util.logging.Logger |
logger |
private int |
numClasses
The number of classes.
|
protected int |
numData
The number of input vectors.
|
private java.util.ArrayList<java.awt.Color> |
paintList |
Constructor and Description |
---|
SOMLibClassInformation()
Constructor intended to be used e.g.
|
SOMLibClassInformation(java.util.Map<java.lang.String,java.lang.String> classAssignment) |
SOMLibClassInformation(java.lang.String classInformationFileName)
Creates a new class information object by trying to read the given file in both the versions with a file header (
readSOMLibClassInformationFile() ) and the tab-separated file (readTabSepClassInformationFile()
). |
SOMLibClassInformation(java.lang.String[] classNames,
java.lang.String[][] dataName)
Constructor intended to be used when generating data.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassColorChangeListener(SOMLibClassInformation.ClassColorChangeListener l) |
void |
addItem(java.lang.String label,
java.lang.String classname) |
java.lang.String[] |
classNames()
Returns all the distinct class names.
|
int[] |
computeClassDistribution(java.lang.String[] labelNames)
computes the percentages of class membership for the given label names
|
boolean |
containsInput(java.lang.String vectorName) |
java.awt.Color |
getClassColor(int index)
Get the colour for the given class index.
|
java.awt.Color[] |
getClassColors()
Get all class colours.
|
java.util.ArrayList<java.util.Map.Entry<java.lang.String,java.lang.Integer>> |
getClassDistribution() |
int |
getClassIndex(java.lang.String vectorLabel)
Gets the class index for a given input vector label.
|
int |
getClassIndexForInput(java.lang.String vectorName) |
java.lang.String |
getClassName(int index)
Gets the class label name for a given input vector index.
|
java.lang.String |
getClassName(java.lang.String vectorName)
Gets the class name of the given vector name.
|
java.lang.String[] |
getClassNames()
Returns the names of the classes.
|
java.lang.String[] |
getDataNames() |
java.lang.String[] |
getDataNamesInClass(java.lang.String className) |
java.util.ArrayList<java.lang.String> |
getDataNamesInClassAsList(java.lang.String className) |
java.lang.String[][] |
getDataNamesPerClass()
Returns an array of data names for each class.
|
int |
getNumberOfClassMembers(int classIndex)
Gets the number of input vectors in the given class.
|
int |
getNumberOfClassMembers(java.lang.String className) |
java.util.ArrayList<java.awt.Color> |
getPaintList()
Get the class colours as list.
|
double |
getPercentageOfClassMembers(int classIndex) |
boolean |
hasClassAssignmentForName(java.lang.String vectorName) |
private void |
initPaintList()
Initialise a standard paint list
|
boolean |
loadClassColours(java.io.File file)
Load colours from an external (non-classinfo) file.
|
static void |
main(java.lang.String[] args)
Method for stand-alone execution to convert a file to the SOMLibClassInformation format.
|
int |
numClasses()
Gets the number of classes, as read from $NUM_CLASSES, or computed.
|
int |
numVectors() |
static SOMLibClassInformation |
parse(java.lang.String contents)
Parses the given contents, which must adhere to the SOMLib format, to a
SOMLibClassInformation object.The difference to the main constructor SOMLibClassInformation(String) is that the constructor reads from
a file, while this method already has the contents in the given parameter. |
void |
processItems(boolean sortClassNames)
process any items that were added by the
addItem(String, String) method. |
private void |
readSimple() |
protected void |
readSOMLibClassInformationFile()
Reads a class information file containing a header and class indices.
|
private void |
readSOMLibClassInformationFile(java.io.BufferedReader br) |
private void |
readTabSepClassInformationFile()
Reads a class information file containing no header, and tab-separated String entries for the input vector and
class labels.
|
private void |
readTabSepClassInformationFile(java.io.BufferedReader br) |
void |
removeClassColorChangeListener(SOMLibClassInformation.ClassColorChangeListener l) |
void |
removeNotPresentElements(SOMLibSparseInputData inputData) |
void |
setClassColor(int index,
java.awt.Color color)
Get the colour for the given class index.
|
private void |
throwClassInfoReadingError(java.lang.String classInformationFileName,
java.io.IOException e) |
private static final java.util.logging.Logger logger
protected java.lang.String classInformationFileName
private int numClasses
private java.lang.String[] classNames
private int[] classMemberCount
protected int numData
private java.lang.String[] dataNames
private int[] dataClasses
private java.util.HashMap<java.lang.String,java.lang.Integer> dataHash
private java.util.ArrayList<java.lang.String> classNamesTemp
private java.util.ArrayList<java.lang.String> dataNamesTemp
private java.util.HashMap<java.lang.String,java.lang.String> dataHashTemp
private java.util.ArrayList<java.awt.Color> paintList
private java.util.ArrayList<SOMLibClassInformation.ClassColorChangeListener> colorChangeListeners
public SOMLibClassInformation()
SOMPAKInputData
public SOMLibClassInformation(java.util.Map<java.lang.String,java.lang.String> classAssignment)
public SOMLibClassInformation(java.lang.String[] classNames, java.lang.String[][] dataName)
public SOMLibClassInformation(java.lang.String classInformationFileName) throws SOMToolboxException
readSOMLibClassInformationFile()
) and the tab-separated file (readTabSepClassInformationFile()
).classInformationFileName
- The file to read fromSOMToolboxException
- if there is any error in the file formatpublic java.lang.String[] getClassNames()
public java.lang.String[][] getDataNamesPerClass()
public java.lang.String[] getDataNames()
private void throwClassInfoReadingError(java.lang.String classInformationFileName, java.io.IOException e) throws SOMLibFileFormatException
SOMLibFileFormatException
private void readTabSepClassInformationFile() throws SOMToolboxException, java.io.IOException
SOMToolboxException
- if there is any error in the file formatjava.io.IOException
private void readTabSepClassInformationFile(java.io.BufferedReader br) throws java.io.IOException, SOMLibFileFormatException
java.io.IOException
SOMLibFileFormatException
private void readSimple() throws SOMToolboxException, java.io.IOException
SOMToolboxException
java.io.IOException
public void processItems(boolean sortClassNames)
addItem(String, String)
method. This method should be called
prior to accessing the other getter methods of this classsortClassNames
- indicates whether the class names should be sortedpublic void addItem(java.lang.String label, java.lang.String classname)
protected void readSOMLibClassInformationFile() throws java.io.IOException, SOMToolboxException
java.io.IOException
SOMToolboxException
private void readSOMLibClassInformationFile(java.io.BufferedReader br) throws java.io.IOException, SOMLibFileFormatException, ClassInfoHeaderNotFoundException
java.io.IOException
SOMLibFileFormatException
ClassInfoHeaderNotFoundException
public int numClasses()
public int numVectors()
public java.lang.String[] classNames()
public int getClassIndex(java.lang.String vectorLabel)
vectorLabel
- the name of the vectorpublic java.lang.String getClassName(int index)
index
- index of the input vector.public java.lang.String getClassName(java.lang.String vectorName) throws SOMLibFileFormatException
vectorName
- the label/name of the input vector.SOMLibFileFormatException
- If there is no class information available for the given vector name/labelpublic boolean containsInput(java.lang.String vectorName)
public int getClassIndexForInput(java.lang.String vectorName) throws SOMLibFileFormatException
SOMLibFileFormatException
public boolean hasClassAssignmentForName(java.lang.String vectorName)
public int getNumberOfClassMembers(int classIndex)
classIndex
- the index of the class.public int getNumberOfClassMembers(java.lang.String className)
public java.util.ArrayList<java.util.Map.Entry<java.lang.String,java.lang.Integer>> getClassDistribution()
public double getPercentageOfClassMembers(int classIndex)
public java.lang.String[] getDataNamesInClass(java.lang.String className)
public java.util.ArrayList<java.lang.String> getDataNamesInClassAsList(java.lang.String className)
public int[] computeClassDistribution(java.lang.String[] labelNames)
private void initPaintList()
public java.util.ArrayList<java.awt.Color> getPaintList()
public java.awt.Color[] getClassColors()
public java.awt.Color getClassColor(int index)
public void setClassColor(int index, java.awt.Color color)
public void addClassColorChangeListener(SOMLibClassInformation.ClassColorChangeListener l)
public void removeClassColorChangeListener(SOMLibClassInformation.ClassColorChangeListener l)
public boolean loadClassColours(java.io.File file)
public void removeNotPresentElements(SOMLibSparseInputData inputData)
public static void main(java.lang.String[] args) throws SOMToolboxException, java.io.IOException
SOMToolboxException
java.io.IOException
public static SOMLibClassInformation parse(java.lang.String contents) throws SOMToolboxException
SOMLibClassInformation
object.SOMLibClassInformation(String)
is that the constructor reads from
a file, while this method already has the contents in the given parameter.SOMToolboxException