Class Instance
- java.lang.Object
-
- cc.mallet.types.Instance
-
- All Implemented Interfaces:
AlphabetCarrying,java.io.Serializable,java.lang.Cloneable
public class Instance extends java.lang.Object implements java.io.Serializable, AlphabetCarrying, java.lang.Cloneable
A machine learning "example" to be used in training, testing or performance of various machine learning algorithms.An instance contains four generic fields of predefined name: "data", "target", "name", and "source". "Data" holds the data represented `by the instance, "target" is often a label associated with the instance, "name" is a short identifying name for the instance (such as a filename), and "source" is human-readable sourceinformation, (such as the original text).
Each field has no predefined type, and may change type as the instance is processed. For example, the data field may start off being a string that represents a file name and then be processed by a
Pipeinto a CharSequence representing the contents of the file, and eventually to a feature vector holding indices into anAlphabetholding words found in the file. It is up to each pipe which fields in the Instance it modifies; the most common case is that the pipe modifies the data field.Generally speaking, there are two modes of operation for Instances. (1) An instance gets created and passed through a Pipe, and the resulting data/target/name/source fields are used. This is generally done for training instances. (2) An instance gets created with raw values in its slots, then different users of the instance call newPipedCopy() with their respective different pipes. This might be done for test instances at "performance" time.
Rather than store an
Alphabetin the Instance, we obtain it through the Pipe instance variable, because the Pipe also indicates where the data came from and how to interpret the Alphabet.Instances can be made immutable if locked. Although unlocked Instances are mutable, typically the only code that changes the values in the four slots is inside Pipes.
Note that constructing an instance with a pipe argument means "Construct the instance and then run it through the pipe".
InstanceListuses this method when adding instances through a pipeInputIterator.- Author:
- Andrew McCallum mccallum@cs.umass.edu
- See Also:
Pipe,Alphabet,InstanceList, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Instance(java.lang.Object data, java.lang.Object target, java.lang.Object name, java.lang.Object source)In certain unusual circumstances, you might want to create an Instance without sending it through a pipe.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanalphabetsMatch(AlphabetCarrying object)voidclearSource()java.lang.Objectclone()AlphabetgetAlphabet()Alphabet[]getAlphabets()java.lang.ObjectgetData()AlphabetgetDataAlphabet()LabelinggetLabeling()java.lang.ObjectgetName()doublegetNumericProperty(java.lang.String key)PropertyListgetProperties()Deprecated.java.lang.ObjectgetProperty(java.lang.String key)java.lang.ObjectgetSource()java.lang.ObjectgetTarget()AlphabetgetTargetAlphabet()booleanhasProperty(java.lang.String key)booleanisLocked()voidlock()voidsetData(java.lang.Object d)voidsetLabeling(Labeling l)voidsetName(java.lang.Object n)voidsetNumericProperty(java.lang.String key, double value)voidsetProperty(java.lang.String key, java.lang.Object value)voidsetPropertyList(PropertyList p)Deprecated.voidsetSource(java.lang.Object s)voidsetTarget(java.lang.Object t)InstanceshallowCopy()voidunLock()
-
-
-
Method Detail
-
getData
public java.lang.Object getData()
-
getTarget
public java.lang.Object getTarget()
-
getName
public java.lang.Object getName()
-
getSource
public java.lang.Object getSource()
-
getDataAlphabet
public Alphabet getDataAlphabet()
-
getTargetAlphabet
public Alphabet getTargetAlphabet()
-
getAlphabet
public Alphabet getAlphabet()
- Specified by:
getAlphabetin interfaceAlphabetCarrying
-
getAlphabets
public Alphabet[] getAlphabets()
- Specified by:
getAlphabetsin interfaceAlphabetCarrying
-
alphabetsMatch
public boolean alphabetsMatch(AlphabetCarrying object)
-
isLocked
public boolean isLocked()
-
lock
public void lock()
-
unLock
public void unLock()
-
getLabeling
public Labeling getLabeling()
-
setData
public void setData(java.lang.Object d)
-
setTarget
public void setTarget(java.lang.Object t)
-
setLabeling
public void setLabeling(Labeling l)
-
setName
public void setName(java.lang.Object n)
-
setSource
public void setSource(java.lang.Object s)
-
clearSource
public void clearSource()
-
shallowCopy
public Instance shallowCopy()
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
setProperty
public void setProperty(java.lang.String key, java.lang.Object value)
-
setNumericProperty
public void setNumericProperty(java.lang.String key, double value)
-
getProperties
@Deprecated public PropertyList getProperties()
Deprecated.
-
setPropertyList
@Deprecated public void setPropertyList(PropertyList p)
Deprecated.
-
getProperty
public java.lang.Object getProperty(java.lang.String key)
-
getNumericProperty
public double getNumericProperty(java.lang.String key)
-
hasProperty
public boolean hasProperty(java.lang.String key)
-
-