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

📄 rsesclassifier.cpp

📁 粗慥集成算法集合 ,并有详细的文档资料和测试数据处
💻 CPP
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........: 960619
// Description...:
// Revisions.....:
//===================================================================

#include <stdafx.h> // Precompiled headers.
#include <copyright.h>

#include <kernel/rses/algorithms/rsesclassifier.h>

#include <kernel/rses/structures/rsesdecisiontable.h>
#include <kernel/rses/structures/rsesreducts.h>
#include <kernel/rses/structures/rsesrules.h>

#include <kernel/rses/library/tdtable.h>
#include <kernel/rses/library/trr_mem.h>
#include <kernel/rses/library/tdec_gen.h>
#include <kernel/rses/library/err.h>

#include <kernel/algorithms/keyword.h>

#include <kernel/structures/informationvector.h>
#include <kernel/structures/classification.h>
#include <kernel/structures/rule.h>

#include <kernel/utilities/creator.h>

#include <kernel/basic/message.h>

//-------------------------------------------------------------------
// Methods for class RSESClassifier.
//===================================================================

//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================

//-------------------------------------------------------------------
// Method........: Constructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

RSESClassifier::RSESClassifier() {

  // Initialize embedded algorithm.
	try {
		classifier_ = new TDecGenerator();
	}
	catch (Error &error) {
		Message::RSESError("Could not instantiate embedded RSES classifier algorithm.", error.GetMessage());
		classifier_ = NULL;
	}

	// Set default parameters.
	SetVotingStrategy(VOTING_MAJORITY);
	SetFilteringStrategy(FILTERING_SUPPORT);
	SetSupportThreshold(0.0);
	SetStabilityThreshold(1.0);
	SetFilename(Undefined::String());

	// Set mutable flag.
	has_read_file_ = false;

}

//-------------------------------------------------------------------
// Method........: Destructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

RSESClassifier::~RSESClassifier() {

  // Delete embedded algorithm.
	try {
		delete classifier_;
	}
	catch (Error &error) {
		Message::RSESError("Error deleting embedded RSES classifier algorithm.", error.GetMessage());
	}

}

//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================

IMPLEMENTIDMETHODS(RSESClassifier, RSESCLASSIFIER, RuleBasedClassifier)

//-------------------------------------------------------------------
// Methods inherited from Algorithm.
//===================================================================

//-------------------------------------------------------------------
// Method........: GetParameters
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

String
RSESClassifier::GetParameters() const {

	String parameters;

	// Get parameters higher up.
	parameters += RuleBasedClassifier::GetParameters();

	parameters += Keyword::Separator();

	// Voting strategy.
	parameters += Keyword::Voting();
	parameters += Keyword::Assignment();
	parameters += GetString(GetVotingStrategy());

	// Filename with distance matrix, if relevant.
	if (GetVotingStrategy() == VOTING_TUNED) {

		parameters += Keyword::Separator();

		parameters += Keyword::Filename();
		parameters += Keyword::Assignment();
		parameters += GetFilename();

	}

	parameters += Keyword::Separator();

	// Filtering strategy.
	parameters += Keyword::Filtering();
	parameters += Keyword::Assignment();
	parameters += GetString(GetFilteringStrategy());

	// Support threshold, if relevant.
	if (GetFilteringStrategy() == FILTERING_SUPPORT) {

		parameters += Keyword::Separator();

		parameters += Keyword::Threshold() + Keyword::Dot() + Keyword::Support();
		parameters += Keyword::Assignment();
		parameters += String::Format(GetSupportThreshold());

	}

	// Stability threshold, if relevant.
	if (GetFilteringStrategy() == FILTERING_STABILITY) {

		parameters += Keyword::Separator();

		parameters += Keyword::Threshold() + Keyword::Dot() + Keyword::Stability();
		parameters += Keyword::Assignment();
		parameters += String::Format(GetStabilityThreshold());

	}

	return parameters;

}

//-------------------------------------------------------------------
// Method........: SetParameter
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

bool
RSESClassifier::SetParameter(const String &keyword, const String &value) {

	// Voting strategy.
	if (keyword == Keyword::Voting()) {
		if (value == GetString(VOTING_MAJORITY))
			return SetVotingStrategy(VOTING_MAJORITY);
		if (value == GetString(VOTING_TUNED))
			return SetVotingStrategy(VOTING_TUNED);
		return false;
	}

	// Filtering strategy.
	if (keyword == Keyword::Filtering()) {
		if (value == GetString(FILTERING_SUPPORT))
			return SetFilteringStrategy(FILTERING_SUPPORT);
		if (value == GetString(FILTERING_STABILITY))
			return SetFilteringStrategy(FILTERING_STABILITY);
		return false;
	}

	// Support threshold.
	if ((keyword == Keyword::Threshold() + Keyword::Dot() + Keyword::Support()) && value.IsFloat())
		return SetSupportThreshold(value.GetFloat());

	// Stability threshold.
	if ((keyword == Keyword::Threshold() + Keyword::Dot() + Keyword::Stability()) && value.IsFloat())
		return SetStabilityThreshold(value.GetFloat());

	// Filename.
	if (keyword == Keyword::Filename())
		return SetFilename(value);

	// Unknown keyword, at least at this level.
	return RuleBasedClassifier::SetParameter(keyword, value);

}

//-------------------------------------------------------------------
// Method........: IsApplicable
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns true if the algorithm is applicable to the
//                 structure, false otherwise.
// Comments......:
// Revisions.....:
//===================================================================

bool
RSESClassifier::IsApplicable(const Structure &structure, bool warn) const {
	return Classifier::IsApplicable(structure, warn);
}

//-------------------------------------------------------------------
// Method........: Apply
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Assumes that library clients use handles.
// Revisions.....: A

⌨️ 快捷键说明

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