⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decisiongentreeoperator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
*
* $Author$
* $Date$
* $Revision$
* 
*/
package eti.bi.alphaminer.patch.standard.operation.operator;


import java.util.Vector;


import com.prudsys.pdm.Core.MiningAlgorithmSpecification;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.MiningModel;
import com.prudsys.pdm.Models.Classification.DecisionTree.DecisionTreeAlgorithm;
import com.prudsys.pdm.Models.Classification.DecisionTree.DecisionTreeMiningModel;
import com.prudsys.pdm.Models.Classification.DecisionTree.DecisionTreeSettings;
import com.prudsys.pdm.Models.Classification.DecisionTree.Algorithms.GenTree.GenTreeAlgorithm;
import com.prudsys.pdm.Utils.GeneralUtils;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.ModelOperator;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.alphaminer.vo.BIModel;
import eti.bi.alphaminer.vo.BIObject;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IBIModel;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.common.Locale.Resource;
import eti.bi.exception.SysException;

/**
* DecisionTreeOperator is a kind of Operator
*/
public class DecisionGenTreeOperator extends ModelOperator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	/**
	 * @param a_CaseID
	 * @param a_CaseWindow
	 * @param aOperatorInfo
	 */
	public DecisionGenTreeOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
		super(a_CaseID, aNodeInfo, aCaseHandler);
		// TODO Auto-generated constructor stub
	}
	private Vector m_Predicted;	  


	public boolean hasResult()
	{
		if (m_OutputBIObject != null)
		{
			return (m_OutputBIObject.hasResult(BIObject.DATA) &&
					m_OutputBIObject.hasResult(BIObject.MODEL));
		}else
		{
			return false;
		}
	}

	/*

	public MiningDataSpecification getApplyMetaData() {
		return m_ApplyMetaData;
	}
	public void setApplyMiningStoredData(MiningStoredData data) 
		throws MiningException
	{
		// Transform the input data before apply
		 MiningStoredData transformedData = null;
		 
		 if (m_TransformAction!=null)
		 {
		 	File tempFile = new File(m_TempFileLocation+"/case_"+getCaseID()+"/tmp_"+getNodeID()+m_TempFileExtension);
		 	try
			{
		 		transformedData = m_TransformAction.transform(data,tempFile);
		 		m_ApplyMiningStoredData = transformedData;
			} catch (Exception e)
			{
				m_ApplyMiningStoredData = data;
			}
			
		 }else
		 {
			m_ApplyMiningStoredData = data;
		 }			 
		
		if (m_ApplyMiningStoredData!=null)
		{
			m_ApplyMetaData = m_ApplyMiningStoredData.getMetaData();
			m_ApplyMiningStoredData.reset();
		}
	}
	
	public MiningStoredData getApplyMiningStoredData() {
		return m_ApplyMiningStoredData;
	}
*/	public Vector getPredicted() {
		return m_Predicted;
	}
	
	public void clearPredicted()
	{
		m_Predicted = null;
	}
	
	@SuppressWarnings("unchecked")
	public void addPredicted(String predict) {
		if (m_Predicted==null)
			m_Predicted = new Vector();
			
		if (predict==null)
			predict = "";
		m_Predicted.addElement(predict);	
	}
/*
	public boolean hasApplyResult()
	{
		return m_Predicted!=null;
	}

	public void clearApplyResult()
	{
		m_Predicted = null;
		m_ApplyMetaData = null;
		m_ApplyMiningStoredData = null;
	}
*/
	public void execute(IOperatorNode a_OperatorNode, Vector a_Parents)
		throws MiningException, SysException
	{
//		SystemMessagePanel systemMessage = (SystemMessagePanel) m_CaseWindow.getSystemMessagePanel();
				
/*		Operator parentOp = null;
		for (int i=0; i<a_Parents.size(); i++)
		{
			parentOp = ((CaseDiagramPanel) m_CaseWindow.getDiagramDrawingPanel()).getOperatorNode((String) a_Parents.elementAt(i));
			if (parentOp instanceof DataSetAttributesOperator)
				break;
			else
				parentOp = null;
		}
	*//*	
		if (parentOp==null)
		{
			throw new MiningException("Invalid parent operator node - Decision tree node must follows a Set Attributes node"); 
		}
		else
		{
			setTransformAction(parentOp.getTransformAction());
			setInputMiningStoredData(parentOp.getMiningStoredData());
			setTargetAttribute(((DataSetAttributesOperator)parentOp).getTargetAttribute());
		}*/
			
		/* Get parameter from user input */
		String sizeValue = (String) a_OperatorNode.getParameterValue("Size");
		if (sizeValue==null)
		{
			sizeValue = "0";
		}
		String depthValue = (String) a_OperatorNode.getParameterValue("Depth");
		if (depthValue==null)
		{
			depthValue = "100";			
		}
		String impurityValue = (String) a_OperatorNode.getParameterValue("Decrease impurity");
		if (impurityValue==null)
		{
			impurityValue = "0.1";
		}
		String measureValue = (String) a_OperatorNode.getParameterValue("Impurity measure");
		if (measureValue==null)
		{
			measureValue = String.valueOf(GenTreeAlgorithm.FS_GainRatio);
		}
		
		/* Get input mining object from parent node */
		Operator parentOp = (Operator)a_Parents.elementAt(0);
		setInputBIObject(parentOp.getOutputBIObject());
		IBIData aInputBIData = getInputBIObject().getBIData();
		aInputBIData.getMiningStoredData().reset();

		/* Prepare output data model */
		BIData aOutputBIData = new BIData(getCaseID(), getNodeID());
		aOutputBIData.setTargetAttribute(aInputBIData.getTargetAttribute());
		aOutputBIData.setTransformActionHistory(aInputBIData.getTransformActionHistory());
		aOutputBIData.setTargetAttribute(aInputBIData.getTargetAttribute());
		aOutputBIData.setMiningStoredData(aInputBIData.getMiningStoredData());
		BIModel aOutputBIModel = new BIModel(getCaseID(), getNodeID(), IBIModel.TYPE_CLASSIFIER);
		
		/* Execute model building */
		MiningAttribute targetAttribute = aInputBIData.getTargetAttribute();
		if (targetAttribute==null)
		{
			m_SystemMessageHandler.appendMessage("Target attribute is missing. Please add target attribute by using Data Set Attribute Node.");
			return;
		}

		DecisionTreeSettings miningSettings = new DecisionTreeSettings();		
		miningSettings.setTarget(targetAttribute);		
		miningSettings.setDataSpecification(aInputBIData.getMetaData());		
		miningSettings.setMinNodeSize(Integer.parseInt(sizeValue), DecisionTreeSettings.SIZE_UNIT_COUNT);
		miningSettings.setMaxDepth(Integer.parseInt(depthValue));
		miningSettings.setMinDecreaseInImpurity(Double.parseDouble(impurityValue));
		
		try
		{
			miningSettings.verifySettings();
		} catch(IllegalArgumentException e)
		{			
			m_SystemMessageHandler.appendMessage("Invalid building parameters.");
			throw new MiningException(e.getMessage());
		}
		// Set MiningSettings //
		aOutputBIModel.setMiningSettings((DecisionTreeSettings)miningSettings);
							
		MiningAlgorithmSpecification miningAlgorithmSpecification = MiningAlgorithmSpecification.getMiningAlgorithmSpecification("Decision tree (General)",getNodeInfo());				
		String className = miningAlgorithmSpecification.getClassname();		
		
		// Set MiningAlgorithmSpecification //
		miningAlgorithmSpecification.setMAPValue("impurityMeasureType", measureValue);
		aOutputBIModel.setMiningAlgorithmSpecification(miningAlgorithmSpecification);
				
		GeneralUtils.displayMiningAlgSpecParameters(miningAlgorithmSpecification);
		displayMiningAlgSpecParameters(miningAlgorithmSpecification);
		
		DecisionTreeAlgorithm algorithm = (DecisionTreeAlgorithm) GeneralUtils.createMiningAlgorithmInstance(className,this.getClass().getClassLoader());		
		algorithm.setMiningInputStream(aInputBIData.getMiningStoredData());
		algorithm.setMiningSettings(miningSettings);
		algorithm.setMiningAlgorithmSpecification(miningAlgorithmSpecification);
		algorithm.setStoreScoreDistribution(true);
		try
		{
			algorithm.verify();
		} catch(IllegalArgumentException e)
		{
			throw new MiningException(e.getMessage());
		}
		
		MiningModel model = algorithm.buildModel();

		m_SystemMessageHandler.appendMessage(Resource.srcStr("calculationtime")+" [s]: " + algorithm.getTimeSpentToBuildModel());
		
		/* set output mining data and model to the output mining object */ 
		// set MiningModel //
		aOutputBIModel.setMiningModel((DecisionTreeMiningModel) model);
		m_OutputBIObject.setBIData(aOutputBIData);	
		m_OutputBIObject.setBIModel(aOutputBIModel);
		aInputBIData.getMiningStoredData().reset();

		/* set run time parameter value to the node object (It needs to be stored in the BIML) */
		//a_OperatorNode.setParameterValue("Temporary model", aOutputBIModel.getTempBIModelPath());		

		//aOutputBIModel.writeTempBIModel();
	}
/*
	public void apply(OperatorNode a_OperatorNode, Vector a_Parents)
		throws MiningException
	{				
		Operator inputOp = (Operator) a_Parents.elementAt(0);
		setApplyMiningStoredData(inputOp.getMiningStoredData());
		
		getApplyMiningStoredData().reset();
		clearPredicted();	
		while (getApplyMiningStoredData().next())
		{
			MiningVector vector = getApplyMiningStoredData().read();
			double predicted = getDecisionTreeMiningModel().deployModelFunction(vector);
//double predicted = op.getDecisionTreeMiningModel().applyModelFunction(vector);
			Category predTarCat = ((CategoricalAttribute) getDecisionTreeSettings().getTarget()).getCategory(predicted);		
			addPredicted(predTarCat.toString());
		}
	}*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -