📄 rbfnetworkoperator.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.
*
*/
/*
* $Author$
* $Date$
* $Revision$
*/
package eti.bi.alphaminer.patch.standard.operation.operator;
import java.util.Vector;
import com.prudsys.pdm.Core.MiningAlgorithm;
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.Core.NumericAttribute;
import com.prudsys.pdm.Models.Supervised.SupervisedMiningSettings;
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.AppException;
import eti.bi.exception.SysException;
/* @author XiaoguangXu HITSZ-ICE*/
public class RBFNetworkOperator extends ModelOperator {
public static String CLUSTERINGSEED = "clusteringseed";
public static String MAXITS = "maxits";
public static String NUMCLUSTERS = "numclusters";
public static String RIDGE = "ridge";
public static String DEFAULT_CLUSTERINGSEED = "1";
public static String DEFAULT_MAXITS = "-1";
public static String DEFAULT_NUMCLUSTERS = "20";
public static String DEFAULT_RIDGE = "1.0e-8";
/* Parameter name for MiningSettingSpecification and MiningAlgorithm */
public static final String ALGORITHM_NAME = "RBFNetwork (Weka)";
private static String MAP_WEKA_CLASS_PARAMETERS = "wekaClassParameters";
/**
* @param a_CaseID
* @param a_CaseWindow
* @param aOperatorInfo
*/
public RBFNetworkOperator(String a_CaseID, INodeInfo aNodeInfo, ICaseHandler aCaseHandler) {
super(a_CaseID, aNodeInfo, aCaseHandler);
setDefaultModelName("RBFNetwork model");
//2006/07/29 Xiaojun Chen
PredictionAssessmentOperator.registerParentsDefinitionID(aNodeInfo.getDefinitionID());
ScoreOperator.registerParentsDefinitionID(aNodeInfo.getDefinitionID());
}
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* 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 + "]");
setDefaultModelName(Resource.srcStr("RBFNetwork")+"_" + 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 + "]");
setDefaultModelName(Resource.srcStr("RBFNetwork")+"_" + m_NodeID);
}
@Override
public void execute(IOperatorNode a_OperatorNode, Vector a_Parents) throws SysException, AppException,
MiningException {
// TODO 自动生成方法存根
/* Get parameter from user input */
String RBFNetworkparameter = "";
String numclusters = (String) a_OperatorNode.getParameterValue(NUMCLUSTERS);
if (numclusters == null) {
numclusters= DEFAULT_NUMCLUSTERS;
}
RBFNetworkparameter += " -B " + numclusters;
String ridge = (String) a_OperatorNode.getParameterValue(RIDGE);
if (ridge == null) {
ridge= DEFAULT_RIDGE;
}
RBFNetworkparameter += " -R " + ridge;
String maxits = (String) a_OperatorNode.getParameterValue(MAXITS);
if (maxits == null) {
maxits = DEFAULT_MAXITS;
}
RBFNetworkparameter += " -M " + maxits;
String clusteringseed = (String) a_OperatorNode.getParameterValue(CLUSTERINGSEED);
if (clusteringseed == null) {
clusteringseed = DEFAULT_CLUSTERINGSEED;
}
RBFNetworkparameter += " -S " + clusteringseed;
/* Get input bi 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);
/* Check attributes */
MiningAttribute targetAttribute = aInputBIData.getTargetAttribute();
aOutputBIModel.setTargetAttribute(targetAttribute);
if (targetAttribute==null)
{
throw new AppException("Categorical Target attribute is missing. Please add target attribute by using Data Set Attribute Node.");
}else if (targetAttribute instanceof NumericAttribute)
{
m_SystemMessageHandler.appendMessage("Attribute \""+targetAttribute.getName() + "\" is not Categorical.");
throw new AppException("Attribute \""+targetAttribute.getName() + "\" should be Categorical.");
}
/*Create MiningSettings object and assign metadata*/
SupervisedMiningSettings miningSettings = new SupervisedMiningSettings();
miningSettings.setDataSpecification(aInputBIData.getMetaData());
/* Assign settings */
miningSettings.setTarget(targetAttribute);
try {
miningSettings.verifySettings();
} catch (Exception e)
{
m_SystemMessageHandler.appendMessage("Invalid parameters in building the Decision Tree model.");
throw new AppException("Invalid parameters in building the Decision Tree model.");
}
/* Set MiningSettings */
aOutputBIModel.setMiningSettings(miningSettings);
/* Get default mining algorithm specification from 'algorithms.xml' */
MiningAlgorithmSpecification miningAlgorithmSpecification =
MiningAlgorithmSpecification.getMiningAlgorithmSpecification( ALGORITHM_NAME, getNodeInfo());
if( miningAlgorithmSpecification == null )
throw new MiningException( "Can't find RBFNerwork classification method." );
/* Get class name from algorithms specification */
String className = miningAlgorithmSpecification.getClassname();
if( className == null )
throw new MiningException( "className attribute expected." );
/* Set MiningAlgorithmSpecification */
miningAlgorithmSpecification.setMAPValue(MAP_WEKA_CLASS_PARAMETERS, RBFNetworkparameter);
aOutputBIModel.setMiningAlgorithmSpecification(miningAlgorithmSpecification);
displayMiningAlgSpecParameters(miningAlgorithmSpecification);
/* Set and display mining parameters */
GeneralUtils.displayMiningAlgSpecParameters(miningAlgorithmSpecification);
/* Create algorithm object with default values */
MiningAlgorithm algorithm = GeneralUtils.createMiningAlgorithmInstance(className, this.getClass().getClassLoader());
algorithm.setMiningInputStream(aInputBIData.getMiningStoredData());
algorithm.setMiningSettings(miningSettings);
algorithm.setMiningAlgorithmSpecification(miningAlgorithmSpecification);
try
{
algorithm.verify();
} catch(IllegalArgumentException e)
{
throw new MiningException(e.getMessage());
}
MiningModel model = algorithm.buildModel();
m_SystemMessageHandler.appendMessage(Resource.srcStr("calculationtime")+" [s]: " + algorithm.getTimeSpentToBuildModel()+Resource.srcStr("ms"));
m_SystemMessageHandler.nextLine();
aOutputBIModel.setMiningModel(model);
aOutputBIModel.setModelName(m_DefaultModelName);
m_OutputBIObject.setBIData(aOutputBIData);
m_OutputBIObject.setBIModel(aOutputBIModel);
//a_OperatorNode.setParameterValue("Temporary model", aOutputBIModel.getTempBIModelPath());
//aOutputBIModel.writeTempBIModel();
}
@Override
/**
* Test if the NavieBayes Operator contains any results.
* @return true if NavieBayes Operator has result; false otherwise.
*/
public boolean hasResult() throws SysException {
if (m_OutputBIObject != null)
{
return (m_OutputBIObject.hasResult(BIObject.DATA) &&
m_OutputBIObject.hasResult(BIObject.MODEL));
}else
{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -