📄 rsesreduct.cpp
字号:
return (reduct_->AttrInReduct(attribute_no) == 1);
}
catch (Error &error) {
Message::RSESError("Error accessing embedded RSES reduct.", error.GetMessage());
return false;
}
}
//-------------------------------------------------------------------
// Method........: Reindex
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Reindexes the attribute indexes according to some
// supplied vector of new indices.
//
// Example:
//
// R = {0, 3, 4}
// R.Reindex([3, 4, 6, 7, 9]);
// R = {3, 7, 9}
//
// Comments......:
// Revisions.....:
//===================================================================
bool
RSESReduct::Reindex(const Vector(int) &indices) {
// If the embedded RSES reduct is NULL, there's nothing to do.
if (reduct_ == NULL)
return true;
int no_attributes = GetNoAttributes();
Vector(int) reindexed;
// Reserve space to avoid unneeded allocations.
reindexed.reserve(no_attributes);
int i;
// Check that supplied index vector is large enough.
for (i = 0; i < no_attributes; i++) {
reindexed.push_back(GetAttribute(i));
if (reindexed[i] >= indices.size()) {
Message::Error("Supplied index vector is too short.");
return false;
}
}
// Do the reindexing.
for (i = 0; i < no_attributes; i++)
reindexed[i] = indices[reindexed[i]];
// Clear the present RSES internal representation.
try {
TIntSack *pattr = reduct_->GetPAttr();
if (pattr != NULL) {
while (pattr->GetNoElem() > 0)
pattr->RemoveElem(pattr->GetNoElem() - 1);
}
}
catch (Error &error) {
Message::RSESError("Error clearing embedded RSES reduct.", error.GetMessage());
return false;
}
// Create a new, reindexed internal RSES representation.
try {
TIntSack *pattr = reduct_->GetPAttr();
if (pattr != NULL) {
for (i = 0; i < no_attributes; i++)
pattr->AddElem(reindexed[i]);
}
}
catch (Error &error) {
Message::RSESError("Error building embedded RSES reduct.", error.GetMessage());
return false;
}
// We also have to reindex the decision attribute of any associated RSES rules.
try {
int no_rules = reduct_->NoRules();
for (i = 0; i < no_rules; i++) {
TRule *rule = reduct_->GetRule(i);
int decattr = rule->GetDecAttr();
if (decattr < 0) {
Message::Error("Decision attribute of embedded RSES rule is negative.");
continue;
}
if (decattr >= indices.size()) {
Message::Error("Supplied index vector is too short.");
return false;
}
rule->SetDecAttr(indices[decattr]);
}
}
catch (Error &error) {
Message::RSESError("Error reindexing embedded RSES rules.", error.GetMessage());
return false;
}
return true;
}
//-------------------------------------------------------------------
// Method........: GetDiscernibilityType
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the reduct discernibility type.
//
// DISCERNIBILITY_FULL: Among all objects.
// DISCERNIBILITY_OBJECTRELATED: Each object separately (relative
// to each object).
// Comments......:
// Revisions.....:
//===================================================================
Reduct::Discernibility
RSESReduct::GetDiscernibilityType() const {
int type;
#ifdef _DEBUG
// Is the RSES object instantiated?
if (reduct_ == NULL) {
Message::Error("RSES reduct is not properly instantiated.");
return DISCERNIBILITY_FULL;
}
#endif
// Get the reduct type.
try {
type = reduct_->GetRedType();
}
catch (Error &error) {
Message::RSESError("Error accessing embedded RSES reduct.", error.GetMessage());
return DISCERNIBILITY_FULL;
}
// Convert from RSES defined integer to class enum.
switch (type) {
case 0: return DISCERNIBILITY_FULL;
case 1: return DISCERNIBILITY_OBJECT;
}
// Unknown type.
Message::Error("Unknown reduct type returned from embedded RSES reduct.");
return DISCERNIBILITY_FULL;
}
//-------------------------------------------------------------------
// Method........: SetDiscernibilityType
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Cf. the GetDiscernibilityType method.
// Comments......:
// Revisions.....:
//===================================================================
bool
RSESReduct::SetDiscernibilityType(Reduct::Discernibility discernibility) {
int newtype;
#ifdef _DEBUG
// Is the RSES object instantiated?
if (reduct_ == NULL) {
Message::Error("RSES reduct is not properly instantiated.");
return false;
}
#endif
// Convert from class enum to RSES defined integer.
switch (discernibility) {
case DISCERNIBILITY_FULL: newtype = 0; break;
case DISCERNIBILITY_OBJECT: newtype = 1; break;
default: Message::Error("Reduct disc. type not recognized."); return false;
}
// Set the reduct type.
try {
reduct_->SetRedType(newtype);
}
catch (Error &error) {
Message::RSESError("Error accessing embedded RSES reduct.", error.GetMessage());
return false;
}
return true;
}
//-------------------------------------------------------------------
// Method........: GetObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: If the reduct is relative to an object, returns
// the object the reduct is relative to.
// Comments......:
// Revisions.....:
//===================================================================
int
RSESReduct::GetObject() const {
// Is the reduct really object-related?
if (GetDiscernibilityType() == DISCERNIBILITY_FULL)
return Undefined::Integer();
Message::Error("RSESReduct::GetObject() not implemented, not supported by RSES.", false);
return Undefined::Integer();
}
//-------------------------------------------------------------------
// Method........: SetObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Cf. GetObject method.
// Revisions.....:
//===================================================================
bool
RSESReduct::SetObject(int /*object_no*/) {
Message::Debug("RSESReduct::SetObject(int) not implemented, not supported by RSES.");
return false;
}
//-------------------------------------------------------------------
// Method........: GetSupport
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the "support" of the reduct.
//
// Excerpt from the RSES technical doc.:
//
// int TReduct::GetQuality(void);
//
// Returns the quality of the reduct, i.e. number
// of samples that reduct occured in.
// Comments......:
// Revisions.....:
//===================================================================
int
RSESReduct::GetSupport() const {
#ifdef _DEBUG
// Is the RSES object instantiated?
if (reduct_ == NULL) {
Message::Error("RSES reduct is not properly instantiated.");
return Undefined::Integer();
}
#endif
// Get the reduct strength.
try {
return reduct_->GetQuality();
}
catch (Error &error) {
Message::RSESError("Error accessing embedded RSES reduct.", error.GetMessage());
return Undefined::Integer();
}
}
//-------------------------------------------------------------------
// Method........: SetSupport
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Cf. the GetSupport method.
// Comments......:
// Revisions.....:
//===================================================================
bool
RSESReduct::SetSupport(int support) {
#ifdef _DEBUG
// Is the RSES object instantiated?
if (reduct_ == NULL) {
Message::Error("RSES reduct is not properly instantiated.");
return false;
}
#endif
// Set the reduct strength.
try {
reduct_->SetQuality(support);
}
catch (Error &error) {
Message::RSESError("Error accessing embedded RSES reduct.", error.GetMessage());
return false;
}
return true;
}
//-------------------------------------------------------------------
// Method........: IsModuloDecision
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Is the reduct computed modulo the decision?
// Comments......:
// Revisions.....:
//===================================================================
bool
RSESReduct::IsModuloDecision() const {
Message::Error("RSESReduct::IsModuloDecision() not implemented, not supported by RSES.", false);
return false;
}
bool
RSESReduct::IsModuloDecision(bool /*modulo*/) {
Message::Debug("RSESReduct::IsModuloDecision(bool) not implemented, not supported by RSES.");
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -