📄 predictionassessmentoperatorutil.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.
*/
/*
* Created on 2005-1-31
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package eti.bi.alphaminer.patch.standard.operation.operator;
import java.util.ArrayList;
import java.util.Vector;
import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.MiningAttribute;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.operation.operator.InputOperator;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.operation.operator.TransformOperator;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.exception.SysException;
/**
* @author fxu
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class PredictionAssessmentOperatorUtil {
public static final int UPSORTING = 0;
public static final int DOWNSORTING = 1;
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";
// 30/06/2005 Mark Li: Modify for Evauation target value>>
public static String DATASET_NAME_DELIMETER = "---";
private ICaseHandler m_CaseHandler;
private String m_CaseID;
@SuppressWarnings("unused")
private String m_NodeID;
//<<30/06/2005 Mark Li: Modify for Evauation target value
private ArrayList m_TargetValueSet;
@SuppressWarnings("unused")
private final static int m_ValueRangeIndex = 2;
// 30/06/2005 Mark Li: Modify for Evauation target value>>
public PredictionAssessmentOperatorUtil(String a_CaseID, String a_NodeID, ICaseHandler a_CaseHandler)
{
m_CaseHandler = a_CaseHandler;
m_CaseID = a_CaseID;
m_NodeID = a_NodeID;
}
/**
* The function groupedIndex(int nSourceLen, int nTargetLen) is responsible to
* group the source array according to the dividing target
*
* @param nSourceLen
* source arrary lenght
* @param nTargetLen:
* divide group target
* @return the dividing group index
*/
public static int[] groupedIndex(int nSourceLen, int nTargetLen) {
int[] orderIndex = new int[nTargetLen];
if (nSourceLen == 0 || nTargetLen == 0) {
return null;
}
if (nSourceLen == nTargetLen) {
for (int i = 0; i < nTargetLen; i++) {
orderIndex[i] = i;
}
} else if (nSourceLen > nTargetLen) {
//Call Extract Function
orderIndex = ExtractData(nSourceLen, nTargetLen);
} else //nSourceLen < nTargetLen
{
//Call Insert Function
orderIndex = InsertData(nSourceLen, nTargetLen);
}
return orderIndex;
}
/**
* function InsertData(int nSourceLen, int nTargetLen) is responsible to
* insert some value to group the source array to the target array
*
* @param nSourceLen:
* The input data array length;
* @param nTargetLen:
* The target group number
* @return the group Index
*/
private static int[] InsertData(int nSourceLen, int nTargetLen) {
int nTargetIndex = 0;
int nSourceIndex = 0;
int[] orderIndex = new int[nTargetLen];
int Residue = 0;
orderIndex[0] = 0;
for (nTargetIndex = 1; nTargetIndex < nTargetLen; nTargetIndex++) {
Residue = Residue + nSourceLen;
if (Residue >= nTargetLen) {
nSourceIndex = nSourceIndex + 1;
Residue = Residue - nTargetLen;
}
orderIndex[nTargetIndex] = nSourceIndex;
}
return orderIndex;
}
/**
* function ExtractData(int nSourceLen, int nTargetLen) is responsible to
* divide the source array to the target array
*
* @param nSourceLen:
* The input data array length;
* @param nTargetLen:
* The target group number
* @return the group Index
*/
private static int[] ExtractData(int nSourceLen, int nTargetLen) {
int nFactor, nResidue;
int nTargetIndex = 0;
int Residue = 0;
int[] orderIndex = new int[nTargetLen];
nFactor = nSourceLen / nTargetLen;
nResidue = nSourceLen % nTargetLen;
orderIndex[0] = 0;
for (nTargetIndex = 1; nTargetIndex < nTargetLen; nTargetIndex++) {
Residue += nResidue;
if (Residue >= nTargetLen) {
orderIndex[nTargetIndex] = orderIndex[nTargetIndex - 1]
+ nFactor + 1;
Residue = Residue - nTargetLen;
} else
orderIndex[nTargetIndex] = orderIndex[nTargetIndex - 1]
+ nFactor;
}
return orderIndex;
}
/**
*
* @param Src: The source array. The sorted also will sorting in src.
* @param arrayIndex: The array to store the sorted index.
* @param colIndex: Define the sorted column
* @param left: left footnote of the array.
* @param right: right footnote of the array
* @param upDownFlag: define whether is up sorting or down sorting
*/
public static void QuickSort(double[][] Src,int[] arrayIndex,int colIndex,int left,int right,int upDownFlag)
{
int i,j,strTemp;
@SuppressWarnings("unused") double iTemp;
double middle;
i = left;
j = right;
middle = Src[arrayIndex[(left+right)/2]][colIndex];
do{
if(upDownFlag == UPSORTING){
while((Src[arrayIndex[i]][colIndex]<middle) && (i<right))
i++;
while((Src[arrayIndex[j]][colIndex]>middle) && (j>left))
j--;
}
if(upDownFlag == DOWNSORTING){
while((Src[arrayIndex[i]][colIndex]>middle) && (i<right))
i++;
while((Src[arrayIndex[j]][colIndex]<middle) && (j>left))
j--;
}
if(i<=j)
{
strTemp = arrayIndex[i];
arrayIndex[i] = arrayIndex[j];
arrayIndex[j] = strTemp;
i++;
j--;
}
}while(i<=j);//If both footnotes meet, stop. Complette this comparison
if(left<j)
QuickSort(Src,arrayIndex,colIndex,left,j,upDownFlag);
if(right>i)
QuickSort(Src,arrayIndex,colIndex,i,right,upDownFlag);
}
public static int[] arraysorting(double src[][],int arrayLen,int sColumn){
int[] arrayIndex = new int[arrayLen];
if(src == null)
{
System.err.println("*****Warning:The array src is null");
return null;
}
for(int i = 0; i<arrayLen; i++)
arrayIndex[i] = i;
QuickSort(src,arrayIndex,sColumn,0,arrayLen-1,DOWNSORTING); //default use down sorting
return arrayIndex;
}
//Just for testing
public static void main(String s[]) {
double[][] testing = {{1.0d},{2.0d},{3.0d},{4.0d},{5.0d},{6.0d},{7.0d},{8.0d},{9.0d},{10.0d}};
int[] arrayIndex = new int[testing.length];
System.arraycopy(arraysorting(testing,testing.length,0),0,arrayIndex,0,arrayIndex.length);
for(int i = 0; i<testing.length;i++){
System.out.println("\n"+testing[arrayIndex[i]][0]);
System.out.println("\n"+arrayIndex[i]);
}
for(int i = 0; i<testing.length;i++){
System.err.println("\n"+testing[i][0]);
}
}
/**
* Add all datasets connected with a_parentOp into arraylists.
* TWang. Mar 31, 2005.
* @param a_parentOp
* @param a_SelectedCase
* @param a_DatasetsList: data set name
* @param a_DatasetsIDList: which node the data source comes from
* @return boolean
* @throws SysException
*/
@SuppressWarnings("unchecked")
public boolean addDataSet(Operator a_parentOp, ArrayList a_DatasetsList, ArrayList a_DatasetsIDList) throws SysException{
if(a_parentOp == null){
return false;
}
if (a_DatasetsList == null) {
a_DatasetsList = new ArrayList();
}
if (a_DatasetsIDList == null){
a_DatasetsIDList = new ArrayList();
}
//First add data source connected with Modeling Operator/Input Data Operator.
addDataSetRecursively(a_parentOp, a_DatasetsList, a_DatasetsIDList );
//Then add data source from TransformOperator
Vector parentOperators = m_CaseHandler.getParentOperators(m_CaseID,a_parentOp.getNodeID());
if (parentOperators != null){
for(int i = 0; i < parentOperators.size(); i++){
Operator parentOp = (Operator)parentOperators.elementAt(i);
if (parentOp instanceof TransformOperator) {
String dataSourceName = null;
if (parentOp.getName() != null) {
dataSourceName = parentOp.getName();
} else {
dataSourceName = parentOp.getDefaultDataSourceName();
}
a_DatasetsList.add(dataSourceName + " (" + parentOp.getDescription() + ")" + DATASET_NAME_DELIMETER
+ parentOp.getNodeID());
a_DatasetsIDList.add(parentOp.getNodeID());
}
}
}
return true;
}
/**
* Depth First Search the subtree rooted at a_parentOp.
* Record all the InputOperator instances connected with Modeling operators.
* By Twang, Feb 22, 2005.
* @param a_parentOp
*
* @throws SysException
*/
@SuppressWarnings("unchecked")
private void addDataSetRecursively(Operator a_parentOp, ArrayList a_DatasetsList, ArrayList a_DatasetsIDList) throws SysException {
/**
* Currently, only the InputDataOperator is recognized and processed.
*/
Vector parentOperators = m_CaseHandler.getParentOperators(m_CaseID, a_parentOp.getNodeID());
if (parentOperators == null)
return;
for (int i = 0; i < parentOperators.size(); i++) {
Operator parentOp = (Operator)parentOperators.elementAt(i);
if (parentOp instanceof InputOperator) {
if (!(a_DatasetsIDList.contains(parentOp.getNodeID()))) {
//The data source node ID is a subString of the Data Set
// Name. The position is
//after DATASET_NAME_DELIMETER.
IOperatorNode inputOperatorNode = null;
inputOperatorNode = m_CaseHandler.getOperatorNode(m_CaseID, parentOp.getNodeID());
String dataSourceName = null;
if (inputOperatorNode.getName() != null) {
dataSourceName = inputOperatorNode.getName();
} else {
dataSourceName = parentOp.getDefaultDataSourceName();
}
a_DatasetsList.add(dataSourceName + PredictionAssessmentOperatorUtil.DATASET_NAME_DELIMETER
+ parentOp.getNodeID());
a_DatasetsIDList.add(parentOp.getNodeID());
}
} else {
addDataSetRecursively(parentOp, a_DatasetsList, a_DatasetsIDList);
}
}
}
// MiningAttribute attribute = miningAttributes[m_ValueRangeIndex];
public void setTargetAttributeValue(MiningAttribute aAttribute){
m_TargetValueSet = ((CategoricalAttribute) aAttribute).getValues();
}
public ArrayList getTargetAttributeValue(){
return m_TargetValueSet;
}
// 30/06/2005 Mark Li: Modify for Evauation target value>>
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -