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

📄 reductperformancefilter.cpp

📁 The ROSETTA C++ library is a collection of C++ classes and routines that enable discernibility-based
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//-------------------------------------------------------------------// Author........: Aleksander 豩rn// Date..........:// Description...:// Revisions.....://===================================================================#include <stdafx.h> // Precompiled headers.#include <copyright.h>#include <kernel/algorithms/reductperformancefilter.h>#include <kernel/algorithms/keyword.h>#include <kernel/structures/reduct.h>#include <kernel/structures/reducts.h>#include <kernel/structures/rules.h>#include <kernel/structures/decisiontable.h>#include <kernel/structures/batchclassification.h>#include <kernel/utilities/mathkit.h>#include <kernel/utilities/iokit.h>#include <kernel/basic/algorithm.h>#include <kernel/basic/message.h>#include <kernel/system/fstream.h>#include <common/objectmanager.h>//-------------------------------------------------------------------// Static stuff, file scope (ugly hack).//===================================================================static ofstream *static_stream = NULL;//-------------------------------------------------------------------// Methods for class ReductPerformanceFilter.//===================================================================//-------------------------------------------------------------------// Constructors/destructor.//===================================================================ReductPerformanceFilter::ReductPerformanceFilter() {	SetCriterion(CRITERION_DIAGONAL);	SetIndex(0);	SetThreshold(0.5);	SetFilename(Undefined::String());}ReductPerformanceFilter::~ReductPerformanceFilter() {}//-------------------------------------------------------------------// Methods inherited from Identifier.//===================================================================IMPLEMENTIDMETHODS(ReductPerformanceFilter, REDUCTPERFORMANCEFILTER, ReductFilter)//-------------------------------------------------------------------// Methods inherited from Algorithm.//===================================================================//-------------------------------------------------------------------// Method........: GetParameters// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================StringReductPerformanceFilter::GetParameters() const {	String parameters;	// Ratio.	parameters += Keyword::Ratio();	parameters += Keyword::Assignment();	parameters += GetString(GetCriterion());	parameters += Keyword::Separator();	// Index.	parameters += Keyword::Index();	parameters += Keyword::Assignment();	parameters += String::Format(GetIndex());	parameters += Keyword::Separator();	// Threshold.	parameters += Keyword::Threshold();	parameters += Keyword::Assignment();	parameters += String::Format(GetThreshold());	parameters += Keyword::Separator();	// Filename.	parameters += Keyword::Filename();	parameters += Keyword::Assignment();	parameters += GetFilename();	parameters += Keyword::Separator();	// RGDecisionTable.	parameters += Keyword::RuleGenerator() + Keyword::Dot() + Keyword::DecisionTable();	parameters += Keyword::Assignment();	if (GetRGDecisionTable() == NULL)		parameters += "NULL";	else		parameters += GetRGDecisionTable()->GetName();	parameters += Keyword::Separator();	// BCDecisionTable.	parameters += Keyword::BatchClassifier() + Keyword::Dot() + Keyword::DecisionTable();	parameters += Keyword::Assignment();	if (GetBCDecisionTable() == NULL)		parameters += "NULL";	else		parameters += GetBCDecisionTable()->GetName();	parameters += Keyword::Separator();	// RuleGenerator.	parameters += Keyword::RuleGenerator();	parameters += Keyword::Assignment();	if (GetRuleGenerator() == NULL) {		parameters += "NULL";	}	else {		parameters += IdHolder::GetClassname(GetRuleGenerator()->GetId());		parameters += Keyword::Separator();		parameters += GetRuleGenerator()->GetParameters();	}	parameters += Keyword::Separator();	// BatchClassifier.	parameters += Keyword::BatchClassifier();	parameters += Keyword::Assignment();	if (GetBatchClassifier() == NULL) {		parameters += "NULL";	}	else {		parameters += IdHolder::GetClassname(GetBatchClassifier()->GetId());		parameters += Keyword::Separator();		parameters += GetBatchClassifier()->GetParameters();	}	parameters += Keyword::Separator();	return parameters + ReductFilter::GetParameters();}//-------------------------------------------------------------------// Method........: SetParameter// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolReductPerformanceFilter::SetParameter(const String &keyword, const String &value) {	// Ratio.	if (keyword == Keyword::Ratio()) {		if (value == GetString(CRITERION_ROW))			return SetCriterion(CRITERION_ROW);		if (value == GetString(CRITERION_COLUMN))			return SetCriterion(CRITERION_COLUMN);		if (value == GetString(CRITERION_DIAGONAL))			return SetCriterion(CRITERION_DIAGONAL);		return false;	}	// Index.	if (keyword == Keyword::Index() && value.IsInteger())		return SetIndex(value.GetInteger());	// Threshold.	if (keyword == Keyword::Threshold() && value.IsFloat())		return SetThreshold(value.GetFloat());	// Filename.	if (keyword == Keyword::Filename())		return SetFilename(value);	// RGDecisionTable (including backwards compatibility).	if ((keyword == Keyword::RGDecisionTable()) ||		  (keyword == Keyword::RuleGenerator() + Keyword::Dot() + Keyword::DecisionTable())) {		String value_lc(value);		value_lc.ToLowercase();		if (value_lc == "null")			return SetRGDecisionTable(Handle<DecisionTable>(NULL));		Message::Error("RGDecisionTable parameter cannot currently be set this way.");		return false;	}	// BCDecisionTable (including backwards compatibility).	if ((keyword == Keyword::BCDecisionTable()) ||		  (keyword == Keyword::BatchClassifier() + Keyword::Dot() + Keyword::DecisionTable())) {		String value_lc(value);		value_lc.ToLowercase();		if (value_lc == "null")			return SetBCDecisionTable(Handle<DecisionTable>(NULL));		Message::Error("BCDecisionTable parameter cannot currently be set this way.");		return false;	}	// RuleGenerator.	if (keyword == Keyword::RuleGenerator()) {		Handle<Algorithm> algorithm = ObjectManager::GetIdentifiedAlgorithm(IdHolder::GetId(value));		if (algorithm == NULL || !algorithm->IsA(RULEGENERATOR))			return false;		return SetRuleGenerator(dynamic_cast(RuleGenerator *, algorithm.GetPointer()));	}	// BatchClassifier.	if (keyword == Keyword::BatchClassifier()) {		Handle<Algorithm> algorithm = ObjectManager::GetIdentifiedAlgorithm(IdHolder::GetId(value));		if (algorithm == NULL || !algorithm->IsA(BATCHCLASSIFIER))			return false;		return SetBatchClassifier(dynamic_cast(BatchClassifier *, algorithm.GetPointer()));	}	// Pass on to RuleGenerator?	if (GetRuleGenerator() != NULL) {		if (GetRuleGenerator()->SetParameter(keyword, value))			return true;	}	// Pass on to BatchClassifier?	if (GetBatchClassifier() != NULL) {		if (GetBatchClassifier()->SetParameter(keyword, value))			return true;	}	return ReductFilter::SetParameter(keyword, value);}//-------------------------------------------------------------------// Method........: GetOutputFilenames// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolReductPerformanceFilter::GetOutputFilenames(Vector(String) &filenames) const {	if (!Algorithm::GetOutputFilenames(filenames))		return false;	if (GetFilename() != Undefined::String())		filenames.push_back(GetFilename());	return true;}//-------------------------------------------------------------------// Method........: Apply// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: If no decision tables are set for use with RG or BC,//                 tries to trace back to a parent table of the input//                 and uses this.// Revisions.....://===================================================================Structure *ReductPerformanceFilter::Apply(Structure &structure) const {	// This method is conceptually const only.	ReductPerformanceFilter *self = const_cast(ReductPerformanceFilter *, this);	// Reset mutable bookkeeping stuff.	(self->scores_).erase((self->scores_).begin(), (self->scores_).end());	(self->scores_).reserve(structure.GetNoStructures());	(self->only_scores_).erase((self->only_scores_).begin(), (self->only_scores_).end());	(self->only_scores_).reserve(structure.GetNoStructures());	// Check that vital parameters are set.	if (GetRuleGenerator() == NULL) {		Message::Error("No RuleGenerator specified.");		return NULL;	}	if (GetBatchClassifier() == NULL) {		Message::Error("No BatchClassifier specified.");		return NULL;	}	if (GetBatchClassifier()->GetClassifier() == NULL) {		Message::Error("The BatchClassifier has no Classifier set.");		return NULL;	}	bool use_parent_rg = (GetRGDecisionTable() == NULL);	bool use_parent_bc = (GetBCDecisionTable() == NULL);	// Use parent tables if possible and necessary.	if (use_parent_rg)		self->SetRGDecisionTable(dynamic_cast(DecisionTable *, structure.FindParent(DECISIONTABLE)));	if (use_parent_bc)		self->SetBCDecisionTable(dynamic_cast(DecisionTable *, structure.FindParent(DECISIONTABLE)));	if (GetRGDecisionTable() == NULL) {		Message::Error("No RGDecisionTable specified and parent not found.");		return NULL;	}	if (GetBCDecisionTable() == NULL) {		Message::Error("No BCDecisionTable specified and parent not found.");		return NULL;	}	ofstream stream;	// Initialize log file, if filename is set.	if (GetFilename() != Undefined::String()) {		if (!IOKit::Open(stream, GetFilename())) {			Message::Error("Failed to open " + GetFilename() + " for output.");			return NULL;		}		// Write file header.		stream << "% Output from ROSETTA, " + SystemKit::GetUser() + " " + SystemKit::GetTimestamp() << endl;		stream << "%" << endl;		stream << "% " + IdHolder::GetClassname(GetId()) << endl;		stream << "% {" + GetParameters() + "}" << endl;

⌨️ 快捷键说明

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