示例#1
0
		/// <summary> Sets the format of the input instances.
		/// 
		/// </summary>
		/// <param name="instanceInfo">an Instances object containing the input instance
		/// structure (any instances contained in the object are ignored - only the
		/// structure is required).
		/// </param>
		/// <exception cref="UnsupportedAttributeTypeException">if the specified attribute
		/// is neither numeric or nominal.
		/// </exception>
		public override bool setInputFormat(Instances instanceInfo)
		{
			
			base.setInputFormat(instanceInfo);
			
			m_AttIndex.Upper=instanceInfo.numAttributes() - 1;
			if (!Numeric && !Nominal)
			{
				throw new Exception("Can only handle numeric " + "or nominal attributes.");
			}
			m_Values.Upper=instanceInfo.attribute(m_AttIndex.Index).numValues() - 1;
			if (Nominal && m_ModifyHeader)
			{
				instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
				Attribute oldAtt = instanceInfo.attribute(m_AttIndex.Index);
				int[] selection = m_Values.Selection;
				FastVector newVals = new FastVector();
				for (int i = 0; i < selection.Length; i++)
				{
					newVals.addElement(oldAtt.value_Renamed(selection[i]));
				}
				instanceInfo.deleteAttributeAt(m_AttIndex.Index);
				instanceInfo.insertAttributeAt(new Attribute(oldAtt.name(), newVals), m_AttIndex.Index);
				m_NominalMapping = new int[oldAtt.numValues()];
				for (int i = 0; i < m_NominalMapping.Length; i++)
				{
					bool found = false;
					for (int j = 0; j < selection.Length; j++)
					{
						if (selection[j] == i)
						{
							m_NominalMapping[i] = j;
							found = true;
							break;
						}
					}
					if (!found)
					{
						m_NominalMapping[i] = - 1;
					}
				}
			}
			setOutputFormat(instanceInfo);
			return true;
		}