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

📄 predictionassessmentoperator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 *    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.
 */

package eti.bi.alphaminer.patch.standard.operation.operator;

import java.util.ArrayList;
import java.util.Vector;

import weka.classifiers.Classifier;
import weka.classifiers.CostMatrix;
import weka.classifiers.Evaluation;
import weka.classifiers.functions.Logistic;
import weka.classifiers.trees.J48;
import weka.core.Attribute;
import weka.core.Instances;

import com.prudsys.pdm.Adapters.Weka.WekaClassifier;
import com.prudsys.pdm.Adapters.Weka.WekaCoreAdapter;
import com.prudsys.pdm.Adapters.Weka.WekaSupervisedMiningModel;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Input.MiningStoredData;
import com.prudsys.pdm.Models.Supervised.SupervisedMiningSettings;

import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.core.transform.DataTransformAction;
import eti.bi.alphaminer.operation.operator.AssessmentOperator;
import eti.bi.alphaminer.operation.operator.INodeInfo;
import eti.bi.alphaminer.operation.operator.InputOperator;
import eti.bi.alphaminer.operation.operator.ModelOperator;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.operator.TransformOperator;
import eti.bi.alphaminer.patch.standard.operation.property.PredictionAssessmentOperatorProperty;
import eti.bi.alphaminer.ui.ICaseDiagram;
import eti.bi.alphaminer.vo.BIData;
import eti.bi.alphaminer.vo.BIModel;
import eti.bi.alphaminer.vo.IBIData;
import eti.bi.alphaminer.vo.IBIModel;
import eti.bi.alphaminer.vo.IBIObject;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;

/**
 * AssessmentOperator is a kind of Operator
 */
public class PredictionAssessmentOperator extends AssessmentOperator {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static String EVALUATIONMODE = "Evaluation Mode";
	public static String THRESHOLD = "Threshold";
	public static String TARGET_LEVEL = "Target Level";
	public static String CHART_TYPE = "Chart Type";
	public static String DRAW_STYLE = "Draw Style";

	public static String EVALUATION_CONFUSIONMATRIX_MODE = "Confusion Matrix";
	public static String EVALUATION_EVALUATIONCHART_MODE = "Evaluation Chart";
	// <<30/06/2005 Mark Li: Modify for Evauation target value
	public static String EVAUATION_TARGET_ZERO = "0";
	public static String EVAUATION_TARGET_ONE = "1";
	public static int EVAUATION_TARGETLEVEL_ZERO = 0;
	public static int EVAUATION_TARGETLEVEL_ONE = 1;
	// 30/06/2005 Mark Li: Modify for Evauation target value>>
	public static int MAX_INPUTMODEL_NUM = 3;
	public static int MAX_INPUTDATASETS_NUM = 3;
	public static int QUANTILE_NUM = 100;

	public static String[] TREE_CLASSIFIERSTATISTICS_NAMES = {"TP Rate(%)", "FP Rate(%)", "Precision(%)",
			"F-Measure(%)", "Fallout Rate(%)", "Rate(%) of Confidence > 90%"};
	public static String[] REGRESSION_CLASSIFIERSTATISTICS_NAMES = {"TP Rate(%)", "FP Rate(%)", "Precision(%)",
			"F-Measure(%)", "Fallout Rate(%)"};
	private ArrayList m_DatasetsList;
	private ArrayList m_DatasetsIDList;
	@SuppressWarnings("unused")
	private boolean m_DataSetBuilt = false;

	private ArrayList m_ConfusionMatrixLists;
	private ArrayList m_EvaluationChartDataLists;

	@SuppressWarnings("unused")
	private ICaseDiagram m_ParentPanel;
	private IOperatorNode m_OperatorNode;
	private IBIModel[] m_InputBIModels; /* To store input BI Models */
	private Operator[] m_InputModelOperators;
	private IBIData[] m_InputBIDatasets; /* To store input BI Datasets */
	private String[] m_InputBIDatasetsNames; /* To store input BI Datasets names for display */
	private int m_inputModelsNum = 0;
	private int m_inputDatasetsNum = 0;

	private static ArrayList<String> acceptParentsDefinitionID = new ArrayList<String>();
	
	/**
	 * Constructs an PredictionAssessmentOperator.
	 * 
	 * @param a_CaseID
	 *            ID of the Case containing the node represented by this AssessmentOperator.
	 * @param a_CaseWindow
	 *            CaseWindow in which this AssessmentOperator is added to.
	 * @throws SysException
	 */
	public PredictionAssessmentOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler)
			throws SysException {
		super(a_CaseID, aNodeInfo, aCaseHandler);

		m_DatasetsList = new ArrayList();
		m_DatasetsIDList = new ArrayList();
		m_InputBIModels = new BIModel[MAX_INPUTMODEL_NUM];
		m_InputModelOperators = new Operator[MAX_INPUTMODEL_NUM];
		m_InputBIDatasets = new BIData[MAX_INPUTDATASETS_NUM];
		m_InputBIDatasetsNames = new String[MAX_INPUTDATASETS_NUM];

		m_ParentPanel = m_CaseHandler.getCaseDiagram(m_CaseID);

	}

	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setNodeID(String a_NodeID) {
		setLabel(getDescription() + " [" + a_NodeID + "]");
		super.setNodeID(a_NodeID);
	}
	
	/**
	 * Set node id and update operator text of the DecisionTreeOperator at the same time.
	 * @param a_NodeID ID of the node
	 */
	public void setDescription(String a_Description) {
		m_Description = a_Description;
		setLabel(m_Description + " [" + m_NodeID + "]");
	}
	
	public ArrayList getConfusionMatrixLists() {
		return m_ConfusionMatrixLists;
	}

	public ArrayList getEvaluationChartDataLists() {
		return m_EvaluationChartDataLists;
	}

	public boolean hasResult() {
		// <<01/02/2005 Mark Li
		// Clear the NullPointer Exception;
		// refactored by Frank J. Xu
		if (((m_ConfusionMatrixLists != null) && (m_ConfusionMatrixLists.size() > 0))
				|| ((m_EvaluationChartDataLists != null) && (m_EvaluationChartDataLists.size() > 0)))
			return true;
		// 01/02/2005 Mark Li>>
		else
			return false;
	}

	public boolean hasConfusionMatrices() {
		if ((m_ConfusionMatrixLists != null) && (m_ConfusionMatrixLists.size() > 0))
			return true;
		else
			return false;
	}

	public boolean hasEvaluationChartData() {
		if ((m_EvaluationChartDataLists != null) && (m_EvaluationChartDataLists.size() > 0))
			return true;
		else
			return false;
	}

	public void clearResult() {
		super.clearResult();
		// Must test before clear.
		if (m_ConfusionMatrixLists != null) {
			m_ConfusionMatrixLists.clear();
		}
		if (m_EvaluationChartDataLists != null) {
			m_EvaluationChartDataLists.clear();
		}
	}

	public void execute(IOperatorNode a_OperatorNode, Vector a_Parents) throws MiningException, AppException,
			SysException {
		m_OperatorNode = a_OperatorNode;
		// initialize everytime the method is called.
		m_EvaluationChartDataLists = new ArrayList();
		m_ConfusionMatrixLists = new ArrayList();

		/* Get parameter from user input */
		String evaluationMode = (String) a_OperatorNode.getParameterValue(EVALUATIONMODE);
		String threshold = (String) a_OperatorNode.getParameterValue(THRESHOLD);
		String targetLevel = (String) a_OperatorNode.getParameterValue(TARGET_LEVEL);
		String chartType = (String) a_OperatorNode.getParameterValue(CHART_TYPE);

		// get selected models and datasets.
		getInputBIObjects(a_Parents, a_OperatorNode);

		if (m_inputModelsNum * m_inputDatasetsNum > 0) {
			if (evaluationMode.equalsIgnoreCase(EVALUATION_CONFUSIONMATRIX_MODE)) {
				caculateConfusionMatrices(Double.parseDouble(threshold));
			} else if (evaluationMode.equalsIgnoreCase(EVALUATION_EVALUATIONCHART_MODE)) {
				caculateEvaluationChartData(chartType, Integer.parseInt(targetLevel));
			}
		} else {
			throw new AppException("Please select both model and data sets.");
		}
	}

	/**
	 * Get input bi object from parent node
	 * 
	 * @param a_Parents:
	 *            parent nodes of currnet node.
	 * @param selectedModelsName:
	 *            selected models names connected to current node.
	 * @param selectedDatasetsName:
	 *            selected datesets connected to current node.
	 * @return null.
	 */
private void getInputBIObjects(Vector a_Parents, IOperatorNode a_OperatorNode)
			throws MiningException, AppException, SysException
	{
		// reset the index of input models
		m_inputModelsNum = 0; 
		m_inputDatasetsNum = 0;
		for (int i=0; i<a_Parents.size(); i++){
			Operator parentOp = (Operator)(a_Parents.elementAt(i));		
		
			// TODO Get DefaultModelName from the modeloperator instead of output BIModel
					
			IBIObject aBIObject = parentOp.getOutputBIObject(); 
			if (aBIObject != null){
				IBIModel aBIModel = aBIObject.getBIModel();
				@SuppressWarnings("unused") IBIData 	aBIData	 = aBIObject.getBIData();
				if (aBIModel !=null){
					String modelName = ((ModelOperator)parentOp).getDefaultModelName();
					String val = (String) a_OperatorNode.getParameterValue(modelName);
					if(val != null){
						if(val.equals("true")){
							m_InputModelOperators[m_inputModelsNum] = parentOp;
							m_InputBIModels[m_inputModelsNum++] = aBIModel;
						}
					}
				}
			}
		}
		   
		
		// re-add all the datasets
		m_DatasetsIDList.clear();
		m_DatasetsList.clear();
 // addDataSetRecursively(this);
		PredictionAssessmentOperatorUtil assessmentOperatorUtil = new PredictionAssessmentOperatorUtil(m_CaseID, m_NodeID, m_CaseHandler);
		assessmentOperatorUtil.addDataSet(this, m_DatasetsList, m_DatasetsIDList); 
 		
		for(int ii=0; ii<m_DatasetsList.size(); ii++){
			String datasetName = (String) m_DatasetsList.get(ii);
			
			String datasetValue = (String) a_OperatorNode.getParameterValue(datasetName);
			if (datasetValue != null){
			  if (datasetValue.equals("true")){
				String tempNodeIDs[] = datasetName.split(PredictionAssessmentOperatorUtil.DATASET_NAME_DELIMETER);
			
				if (tempNodeIDs == null){
					throw new SysException("Can not identify the Node ID from the data set name");
				}
				String nodeID = tempNodeIDs[tempNodeIDs.length-1];
			
				Operator parentOp = m_CaseHandler.getOperator(m_CaseID, nodeID);
				IBIObject aBIObject = parentOp.getOutputBIObject();

⌨️ 快捷键说明

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