public class InstanceSet
extends java.lang.Object
InstanceSet
The instance set class mantains a pool of instances read from the keel formated data file. It provides a set of methods that permit to get each instance, get the whole set of instances, get the number of instances, etc.Instance
,
Attributes
Constructor and Description |
---|
InstanceSet()
It instances a new instance of InstanceSet
|
InstanceSet(boolean nonStaticAttributes)
InstanceSet
This constructor permit define if the attribute's definition need to be
stored as non-static (nonStaticAttributes = true).
|
InstanceSet(InstanceSet is)
Creates a new InstanceSet with the header and Instances from the passed object
It performs a deep (new allocated) copy.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(Attribute at)
Appends the given attribute to the non-static list of the current InstanceSet
|
void |
addInstance(Instance inst)
It adds the passed instance at the end of the present InstanceSet
|
void |
clearInstances()
Remove all instances from this InstanceSet
|
void |
clearNonStaticAttributes()
Clear the non-Static attributes.
|
InstanceAttributes |
getAttributeDefinitions()
getAttributeDefinitions
It does return the definition of the attibutes contained in the dataset.
|
java.lang.String |
getHeader()
It returns the header.
|
java.lang.String |
getInputNominalValue(int whichInst,
int whichAttr)
Returns the value of a nominal input attribute of an instance in the
instanceSet.
|
double |
getInputNumericValue(int whichInst,
int whichAttr)
Returns the value of an integer or a real input attribute of an instance
in the instanceSet.
|
Instance |
getInstance(int whichInstance)
Gets the instance located at the cursor position.
|
Instance[] |
getInstances()
It returns all the instances of the class.
|
java.lang.String |
getNewHeader()
It does return a new header (not necessary the same header as the
input file one).
|
int |
getNumInstances()
It returns the number of instances.
|
java.lang.String |
getOriginalHeaderWithoutInOut()
It does return the original header definiton but
without @input and @output in there
|
java.lang.String |
getOutputNominalValue(int whichInst,
int whichAttr)
Returns the value of a nominal output attribute of an instance in the
instanceSet.
|
double |
getOutputNumericValue(int whichInst,
int whichAttr)
Returns the value of an integer or a real output attribute of an instance
in the instanceSet.
|
void |
parseHeader(InstanceParser parser,
boolean isTrain)
It reads the information in the header of the file.
|
void |
print() |
void |
print(java.io.PrintWriter out)
It prints the dataset to the specified PrintWriter
|
void |
printAsOriginal(java.io.PrintWriter out,
int printInOut)
It prints the dataset to the specified PrintWriter.
|
void |
readSet(java.lang.String fileName,
boolean isTrain)
This method reads all the information in a DB and load it to memory.
|
boolean |
removeAttribute(InstanceSet tSet,
boolean inputAtt,
int whichAtt)
It does remove an attribute.
|
void |
removeInstance(int instNum)
It does remove the instance i from the instanceSet.
|
void |
setAttributesAsNonStatic()
setAttributesAsNonStatic
It stores the static-defined attributes in the class Attributes as
non static in the object attributes.
|
public InstanceSet()
public InstanceSet(boolean nonStaticAttributes)
public InstanceSet(InstanceSet is)
is
- Original InstanceSetpublic void setAttributesAsNonStatic()
public InstanceAttributes getAttributeDefinitions()
public void readSet(java.lang.String fileName, boolean isTrain) throws DatasetException, HeaderFormatException
fileName
- is the database file name.isTrain
- is a flag that indicate if the database is for a train or for a test.DatasetException
- if there is any semantical error in the input file.HeaderFormatException
- if there is any lexical or sintactical error in the
header of the input filepublic void parseHeader(InstanceParser parser, boolean isTrain)
parser
- is the parser of the data setisTrain
- is a boolean indicating if this is a train set (and so
parameters information must be read) or a test set (parameters information
has not to be read).public int getNumInstances()
public Instance getInstance(int whichInstance)
public Instance[] getInstances()
public double getInputNumericValue(int whichInst, int whichAttr) throws java.lang.ArrayIndexOutOfBoundsException
whichInst
- is the position of the instance.whichAttr
- is the position of the input attribute.java.lang.ArrayIndexOutOfBoundsException
- If the index is out of the instance
set size.public double getOutputNumericValue(int whichInst, int whichAttr) throws java.lang.ArrayIndexOutOfBoundsException
whichInst
- is the position of the instance.whichAttr
- is the position of the output attribute.java.lang.ArrayIndexOutOfBoundsException
- If the index is out of the instance
set size.public java.lang.String getInputNominalValue(int whichInst, int whichAttr) throws java.lang.ArrayIndexOutOfBoundsException
whichInst
- is the position of the instance.whichAttr
- is the position of the input attribute.java.lang.ArrayIndexOutOfBoundsException
- If the index is out of the instance
set size.public java.lang.String getOutputNominalValue(int whichInst, int whichAttr) throws java.lang.ArrayIndexOutOfBoundsException
whichInst
- is the position of the instance.whichAttr
- is the position of the output attribute.java.lang.ArrayIndexOutOfBoundsException
- If the index is out of the instance
set size.public void removeInstance(int instNum)
instNum
- is the instance removed from the instanceSet.public boolean removeAttribute(InstanceSet tSet, boolean inputAtt, int whichAtt)
tSet
- is the test set.inputAtt
- is a boolean that is true when the attribute that is
wanted to be removed is an input attribute.whichAtt
- is a integer that indicate the position of the attriubte
to be deleted.public java.lang.String getHeader()
public java.lang.String getNewHeader()
public java.lang.String getOriginalHeaderWithoutInOut()
public void print(java.io.PrintWriter out)
out
- is the PrintWriter where to printpublic void printAsOriginal(java.io.PrintWriter out, int printInOut)
out
- is the PrintWriter where to printprintInOut
- indicates if the @inputs (1), @outputs(2),
both of them (3) or any (0) has to be printedpublic void print()
public void clearInstances()
public void addInstance(Instance inst)
inst
- the instance to be addedpublic void clearNonStaticAttributes()
public void addAttribute(Attribute at)
at
- The Attribute to be Appended