📄 instance.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Wed Sep 04 10:31:50 CDT 2002 --><TITLE>: Class Instance</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../weka/core/FastVector.FastVectorEnumeration.html"><B>PREV CLASS</B></A> <A HREF="../../weka/core/Instances.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="Instance.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">weka.core</FONT><BR>Class Instance</H2><PRE>java.lang.Object | +--<B>weka.core.Instance</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../weka/core/Copyable.html">Copyable</A>, java.io.Serializable</DD></DL><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../weka/core/SparseInstance.html">SparseInstance</A></DD></DL><HR><DL><DT>public class <B>Instance</B><DT>extends java.lang.Object<DT>implements <A HREF="../../weka/core/Copyable.html">Copyable</A>, java.io.Serializable</DL><P>Class for handling an instance. All values (numeric, nominal, or string) are internally stored as floating-point numbers. If an attribute is nominal (or a string), the stored value is the index of the corresponding nominal (or string) value in the attribute's definition. We have chosen this approach in favor of a more elegant object-oriented approach because it is much faster. <p> Typical usage (code from the main() method of this class): <p> <code> ... <br> // Create empty instance with three attribute values <br> Instance inst = new Instance(3); <br><br> // Set instance's values for the attributes "length", "weight", and "position"<br> inst.setValue(length, 5.3); <br> inst.setValue(weight, 300); <br> inst.setValue(position, "first"); <br><br> // Set instance's dataset to be the dataset "race" <br> inst.setDataset(race); <br><br> // Print the instance <br> System.out.println("The instance: " + inst); <br> ... <br> </code><p> All methods that change an instance are safe, ie. a change of an instance does not affect any other instances. All methods that change an instance's attribute values clone the attribute value vector before it is changed. If your application heavily modifies instance values, it may be faster to create a new instance from scratch.<P><DL><DT><B>See Also: </B><DD><A HREF="../../serialized-form.html#weka.core.Instance">Serialized Form</A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected double[]</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#m_AttValues">m_AttValues</A></B></CODE><BR> The instance's attribute values.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="../../weka/core/Instances.html">Instances</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#m_Dataset">m_Dataset</A></B></CODE><BR> The dataset the instance has access to.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected double</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#m_Weight">m_Weight</A></B></CODE><BR> The instance's weight.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected static double</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#MISSING_VALUE">MISSING_VALUE</A></B></CODE><BR> Constant representing a missing value.</TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected </CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#Instance()">Instance</A></B>()</CODE><BR> Private constructor for subclasses.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> </CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#Instance(double, double[])">Instance</A></B>(double weight, double[] attValues)</CODE><BR> Constructor that inititalizes instance variable with given values.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> </CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#Instance(weka.core.Instance)">Instance</A></B>(<A HREF="../../weka/core/Instance.html">Instance</A> instance)</CODE><BR> Constructor that copies the attribute values and the weight from the given instance.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> </CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#Instance(int)">Instance</A></B>(int numAttributes)</CODE><BR> Constructor of an instance that sets weight to one, all values to be missing, and the reference to the dataset to null.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../weka/core/Attribute.html">Attribute</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#attribute(int)">attribute</A></B>(int index)</CODE><BR> Returns the attribute with the given index.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../weka/core/Attribute.html">Attribute</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#attributeSparse(int)">attributeSparse</A></B>(int indexOfIndex)</CODE><BR> Returns the attribute with the given index.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../weka/core/Attribute.html">Attribute</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#classAttribute()">classAttribute</A></B>()</CODE><BR> Returns class attribute.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#classIndex()">classIndex</A></B>()</CODE><BR> Returns the class attribute's index.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#classIsMissing()">classIsMissing</A></B>()</CODE><BR> Tests if an instance's class is missing.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> double</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#classValue()">classValue</A></B>()</CODE><BR> Returns an instance's class value in internal format.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> java.lang.Object</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#copy()">copy</A></B>()</CODE><BR> Produces a shallow copy of this instance.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../weka/core/Instances.html">Instances</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#dataset()">dataset</A></B>()</CODE><BR> Returns the dataset this instance has access to.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#deleteAttributeAt(int)">deleteAttributeAt</A></B>(int position)</CODE><BR> Deletes an attribute at the given position (0 to numAttributes() - 1).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> java.util.Enumeration</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#enumerateAttributes()">enumerateAttributes</A></B>()</CODE><BR> Returns an enumeration of all the attributes.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#equalHeaders(weka.core.Instance)">equalHeaders</A></B>(<A HREF="../../weka/core/Instance.html">Instance</A> inst)</CODE><BR> Tests if the headers of two instances are equivalent.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#index(int)">index</A></B>(int position)</CODE><BR> Returns the index of the attribute stored at the given position.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#insertAttributeAt(int)">insertAttributeAt</A></B>(int position)</CODE><BR> Inserts an attribute at the given position (0 to numAttributes()).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#isMissing(weka.core.Attribute)">isMissing</A></B>(<A HREF="../../weka/core/Attribute.html">Attribute</A> att)</CODE><BR> Tests if a specific value is "missing".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#isMissing(int)">isMissing</A></B>(int attIndex)</CODE><BR> Tests if a specific value is "missing".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#isMissingSparse(int)">isMissingSparse</A></B>(int indexOfIndex)</CODE><BR> Tests if a specific value is "missing".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#isMissingValue(double)">isMissingValue</A></B>(double val)</CODE><BR> Tests if the given value codes "missing".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static void</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#main(java.lang.String[])">main</A></B>(java.lang.String[] options)</CODE><BR> Main method for testing this class.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../weka/core/Instance.html">Instance</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#mergeInstance(weka.core.Instance)">mergeInstance</A></B>(<A HREF="../../weka/core/Instance.html">Instance</A> inst)</CODE><BR> Merges this instance with the given instance and returns the result.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static double</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#missingValue()">missingValue</A></B>()</CODE><BR> Returns the double that codes "missing".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../weka/core/Instance.html#numAttributes()">numAttributes</A></B>()</CODE><BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -