Package com.yahoo.labs.samoa.instances
Class InstanceImpl
- java.lang.Object
-
- com.yahoo.labs.samoa.instances.InstanceImpl
-
- All Implemented Interfaces:
Instance
,MultiLabelInstance
,Serializable
- Direct Known Subclasses:
DenseInstance
,MultilabelInstance
,SparseInstance
public class InstanceImpl extends Object implements MultiLabelInstance
The Class InstanceImpl.- Author:
- abifet
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected InstanceData
instanceData
The instance data.protected InstancesHeader
instanceHeader
The instance information.protected double
weight
The weight.
-
Constructor Summary
Constructors Constructor Description InstanceImpl(double weight, double[] res)
Instantiates a new instance.InstanceImpl(double weight, double[] attributeValues, int[] indexValues, int numberAttributes)
Instantiates a new instance.InstanceImpl(double weight, InstanceData instanceData)
Instantiates a new instance.InstanceImpl(int numAttributes)
Instantiates a new instance.InstanceImpl(InstanceImpl inst)
Instantiates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes)
Adds the sparse values.Attribute
attribute(int instAttIndex)
Attribute.Attribute
classAttribute()
Class attribute.int
classIndex()
Class index.boolean
classIsMissing()
Class is missing.double
classValue()
Class value.double
classValue(int instAttIndex)
Gets the value of an output attribute.Instance
copy()
Copy.Instances
dataset()
Dataset.void
deleteAttributeAt(int i)
Delete attribute at.int
index(int i)
Index.int
indexOfAttribute(Attribute attribute)
Index of an Attribute.Attribute
inputAttribute(int attributeIndex)
Gets an input attribute given its index.void
insertAttributeAt(int i)
Insert attribute at.boolean
isMissing(int instAttIndex)
Checks if is missing.boolean
isMissing(Attribute attribute)
Checks if an attribute is missing.boolean
isMissingSparse(int p)
Checks if is missing sparse.int
numAttributes()
Num attributes.int
numberOutputTargets()
Gets the number of output attributes.int
numClasses()
Num classes.int
numInputAttributes()
Gets the number of input attributes.int
numOutputAttributes()
Gets the number of output attributes.int
numValues()
Num values.Attribute
outputAttribute(int outputIndex)
Gets an output attribute given its index.void
setClassValue(double d)
Sets the class value.void
setClassValue(int indexClass, double valueAttribute)
Sets the value of an output attribute.void
setDataset(Instances dataset)
Sets the dataset.void
setMissing(int instAttIndex)
Sets an attribute as missingvoid
setMissing(Attribute attribute)
Sets an attribute as missingvoid
setValue(int numAttribute, double d)
Sets the value.void
setValue(Attribute attribute, double value)
Sets the value of an attribute.void
setWeight(double weight)
Sets the weight.String
stringValue(int i)
String value.double[]
toDoubleArray()
To double array.String
toString()
Text representation of a InstanceImpl.double
value(int instAttIndex)
Value.double
value(Attribute attribute)
Value.double
valueInputAttribute(int attributeIndex)
Gets the value of an input attribute.double
valueOutputAttribute(int attributeIndex)
Gets the value of an output attribute.double
valueSparse(int i)
Value sparse.double
weight()
Weight.
-
-
-
Field Detail
-
weight
protected double weight
The weight.
-
instanceData
protected InstanceData instanceData
The instance data.
-
instanceHeader
protected InstancesHeader instanceHeader
The instance information.
-
-
Constructor Detail
-
InstanceImpl
public InstanceImpl(InstanceImpl inst)
Instantiates a new instance.- Parameters:
inst
- the inst
-
InstanceImpl
public InstanceImpl(double weight, double[] res)
Instantiates a new instance.- Parameters:
weight
- the weightres
- the res
-
InstanceImpl
public InstanceImpl(double weight, double[] attributeValues, int[] indexValues, int numberAttributes)
Instantiates a new instance.- Parameters:
weight
- the weightattributeValues
- the attribute valuesindexValues
- the index valuesnumberAttributes
- the number attributes
-
InstanceImpl
public InstanceImpl(double weight, InstanceData instanceData)
Instantiates a new instance.- Parameters:
weight
- the weightinstanceData
- the instance data
-
InstanceImpl
public InstanceImpl(int numAttributes)
Instantiates a new instance.- Parameters:
numAttributes
- the num attributes
-
-
Method Detail
-
weight
public double weight()
Weight.
-
setWeight
public void setWeight(double weight)
Sets the weight.
-
attribute
public Attribute attribute(int instAttIndex)
Attribute.
-
indexOfAttribute
public int indexOfAttribute(Attribute attribute)
Description copied from interface:Instance
Index of an Attribute.- Specified by:
indexOfAttribute
in interfaceInstance
- Parameters:
attribute
- the attribute to be found.- Returns:
- the index of an attribute
-
deleteAttributeAt
public void deleteAttributeAt(int i)
Delete attribute at.- Specified by:
deleteAttributeAt
in interfaceInstance
- Parameters:
i
- the i
-
insertAttributeAt
public void insertAttributeAt(int i)
Insert attribute at.- Specified by:
insertAttributeAt
in interfaceInstance
- Parameters:
i
- the i
-
numAttributes
public int numAttributes()
Num attributes.- Specified by:
numAttributes
in interfaceInstance
- Returns:
- the int
-
value
public double value(int instAttIndex)
Value.
-
isMissing
public boolean isMissing(int instAttIndex)
Checks if is missing.
-
numValues
public int numValues()
Num values.
-
index
public int index(int i)
Index.
-
valueSparse
public double valueSparse(int i)
Value sparse.- Specified by:
valueSparse
in interfaceInstance
- Parameters:
i
- the i- Returns:
- the double
-
isMissingSparse
public boolean isMissingSparse(int p)
Checks if is missing sparse.- Specified by:
isMissingSparse
in interfaceInstance
- Parameters:
p
- the p- Returns:
- true, if is missing sparse
-
value
public double value(Attribute attribute)
Value.
-
stringValue
public String stringValue(int i)
String value.- Specified by:
stringValue
in interfaceInstance
- Parameters:
i
- the i- Returns:
- the string
-
toDoubleArray
public double[] toDoubleArray()
To double array.- Specified by:
toDoubleArray
in interfaceInstance
- Returns:
- the double[]
-
setValue
public void setValue(int numAttribute, double d)
Sets the value.
-
classValue
public double classValue()
Class value.- Specified by:
classValue
in interfaceInstance
- Returns:
- the double
-
classIndex
public int classIndex()
Class index.- Specified by:
classIndex
in interfaceInstance
- Returns:
- the int
-
numClasses
public int numClasses()
Num classes.- Specified by:
numClasses
in interfaceInstance
- Returns:
- the int
-
classIsMissing
public boolean classIsMissing()
Class is missing.- Specified by:
classIsMissing
in interfaceInstance
- Returns:
- true, if successful
-
classAttribute
public Attribute classAttribute()
Class attribute.- Specified by:
classAttribute
in interfaceInstance
- Returns:
- the attribute
-
setClassValue
public void setClassValue(double d)
Sets the class value.- Specified by:
setClassValue
in interfaceInstance
- Parameters:
d
- the new class value
-
dataset
public Instances dataset()
Dataset.
-
setDataset
public void setDataset(Instances dataset)
Sets the dataset.- Specified by:
setDataset
in interfaceInstance
- Parameters:
dataset
- the new dataset
-
addSparseValues
public void addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes)
Adds the sparse values.- Specified by:
addSparseValues
in interfaceInstance
- Parameters:
indexValues
- the index valuesattributeValues
- the attribute valuesnumberAttributes
- the number attributes
-
toString
public String toString()
Text representation of a InstanceImpl.
-
numInputAttributes
public int numInputAttributes()
Description copied from interface:Instance
Gets the number of input attributes.- Specified by:
numInputAttributes
in interfaceInstance
- Returns:
- the number of input attributes
-
numOutputAttributes
public int numOutputAttributes()
Description copied from interface:Instance
Gets the number of output attributes.- Specified by:
numOutputAttributes
in interfaceInstance
- Returns:
- the number of output attributes
-
numberOutputTargets
public int numberOutputTargets()
Description copied from interface:Instance
Gets the number of output attributes.- Specified by:
numberOutputTargets
in interfaceInstance
- Returns:
- the number of output attributes
-
classValue
public double classValue(int instAttIndex)
Description copied from interface:Instance
Gets the value of an output attribute.- Specified by:
classValue
in interfaceInstance
- Parameters:
instAttIndex
- the index- Returns:
- the value
-
setClassValue
public void setClassValue(int indexClass, double valueAttribute)
Description copied from interface:Instance
Sets the value of an output attribute.- Specified by:
setClassValue
in interfaceInstance
- Parameters:
indexClass
- the output attribute indexvalueAttribute
- the value of the attribute
-
outputAttribute
public Attribute outputAttribute(int outputIndex)
Description copied from interface:Instance
Gets an output attribute given its index.- Specified by:
outputAttribute
in interfaceInstance
- Parameters:
outputIndex
- the index- Returns:
- the attribute
-
inputAttribute
public Attribute inputAttribute(int attributeIndex)
Description copied from interface:Instance
Gets an input attribute given its index.- Specified by:
inputAttribute
in interfaceInstance
- Parameters:
attributeIndex
- the index- Returns:
- the attribute
-
valueInputAttribute
public double valueInputAttribute(int attributeIndex)
Description copied from interface:Instance
Gets the value of an input attribute.- Specified by:
valueInputAttribute
in interfaceInstance
- Parameters:
attributeIndex
- the index- Returns:
- the value
-
valueOutputAttribute
public double valueOutputAttribute(int attributeIndex)
Description copied from interface:Instance
Gets the value of an output attribute.- Specified by:
valueOutputAttribute
in interfaceInstance
- Parameters:
attributeIndex
- the index- Returns:
- the value
-
setMissing
public void setMissing(int instAttIndex)
Description copied from interface:Instance
Sets an attribute as missing- Specified by:
setMissing
in interfaceInstance
- Parameters:
instAttIndex
- , the attribute's index
-
setMissing
public void setMissing(Attribute attribute)
Description copied from interface:Instance
Sets an attribute as missing- Specified by:
setMissing
in interfaceInstance
- Parameters:
attribute
- , the Attribute
-
isMissing
public boolean isMissing(Attribute attribute)
Description copied from interface:Instance
Checks if an attribute is missing.
-
-