예제 #1
0
		/// <summary> Builds the tree structure.
		/// 
		/// </summary>
		/// <param name="data">the data for which the tree structure is to be
		/// generated.
		/// </param>
		/// <param name="keepData">is training data to be kept?
		/// </param>
		/// <exception cref="Exception">if something goes wrong
		/// </exception>
		public virtual void  buildTree(Instances data, bool keepData)
		{
			
			Instances[] localInstances;
			
			if (keepData)
			{
				m_train = data;
			}
			m_test = null;
			m_isLeaf = false;
			m_isEmpty = false;
			m_sons = null;
			m_localModel = m_toSelectModel.selectModel(data);
			if (m_localModel.numSubsets() > 1)
			{
				localInstances = m_localModel.split(data);
				data = null;
				m_sons = new ClassifierTree[m_localModel.numSubsets()];
				for (int i = 0; i < m_sons.Length; i++)
				{
					m_sons[i] = getNewTree(localInstances[i]);
					localInstances[i] = null;
				}
			}
			else
			{
				m_isLeaf = true;
				if (Utils.eq(data.sumOfWeights(), 0))
					m_isEmpty = true;
				data = null;
			}
		}
예제 #2
0
		/// <summary> Builds the tree structure with hold out set
		/// 
		/// </summary>
		/// <param name="train">the data for which the tree structure is to be
		/// generated.
		/// </param>
		/// <param name="test">the test data for potential pruning
		/// </param>
		/// <param name="keepData">is training Data to be kept?
		/// </param>
		/// <exception cref="Exception">if something goes wrong
		/// </exception>
		public virtual void  buildTree(Instances train, Instances test, bool keepData)
		{
			
			Instances[] localTrain, localTest;
			int i;
			
			if (keepData)
			{
				m_train = train;
			}
			m_isLeaf = false;
			m_isEmpty = false;
			m_sons = null;
			m_localModel = m_toSelectModel.selectModel(train, test);
			m_test = new Distribution(test, m_localModel);
			if (m_localModel.numSubsets() > 1)
			{
				localTrain = m_localModel.split(train);
				localTest = m_localModel.split(test);
				train = test = null;
				m_sons = new ClassifierTree[m_localModel.numSubsets()];
				for (i = 0; i < m_sons.Length; i++)
				{
					m_sons[i] = getNewTree(localTrain[i], localTest[i]);
					localTrain[i] = null;
					localTest[i] = null;
				}
			}
			else
			{
				m_isLeaf = true;
				if (Utils.eq(train.sumOfWeights(), 0))
					m_isEmpty = true;
				train = test = null;
			}
		}
예제 #3
0
		/// <summary> Creates a distribution according to given instances and
		/// split model.
		/// 
		/// </summary>
		/// <exception cref="Exception">if something goes wrong
		/// </exception>
		
		public Distribution(Instances source, ClassifierSplitModel modelToUse)
		{
			
			int index;
			Instance instance;
			double[] weights;
			
			m_perClassPerBag = new double[modelToUse.numSubsets()][];
			for (int i = 0; i < modelToUse.numSubsets(); i++)
			{
				m_perClassPerBag[i] = new double[0];
			}
			m_perBag = new double[modelToUse.numSubsets()];
			totaL = 0;
			m_perClass = new double[source.numClasses()];
			for (int i = 0; i < modelToUse.numSubsets(); i++)
				m_perClassPerBag[i] = new double[source.numClasses()];
			System.Collections.IEnumerator enu = source.enumerateInstances();
			//UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
			while (enu.MoveNext())
			{
				//UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
				instance = (Instance) enu.Current;
				index = modelToUse.whichSubset(instance);
				if (index != - 1)
					add(index, instance);
				else
				{
					weights = modelToUse.GetWeights(instance);
					addWeights(instance, weights);
				}
			}
		}