📄 tfuzzyrule.h
字号:
////////////////////////////////////////////////////////////////////////////////
#ifndef TFuzzyRule_h
#define TFuzzyRule_h
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Rule == Predicate | if Predicate then Consequent
// Predicate == Premise AND|OR Premise AND|OR Premise ...
// Consequent == Premise
// Premise == scalar is (member of) fuzzyset
// scalar == input parameter | defuzzified Consequent
//
//
// e.g.
//
// assume
// x, y, z == scalar
// X, Y, Z == fuzzyset
// then
// Unconditinal Rule == x is X
// Conditinal Rule == if x is X AND y is Y OR z is Z then q is Q
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#include "TFuzzySet.h"
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Premise == scalar is (member of) fuzzyset
class TPremise
{
private:
double scalar; // set_scalar unifies it to fuzzyset->variable domain
public:
TFuzzySet* fuzzyset;
public:
TPremise(TFuzzySet* _fuzzyset, double _scalar=0.0);
virtual ~TPremise();
void set_scalar(double _scalar=0.0);
double Evaluate();
bool operator == (TPremise& premise2);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Predicate == Premise AND|OR Premise AND|OR Premise ...
#define MAX_PREMISES_PER_PREDICATE 16
#define INVALID_OPERATOR -1
#define AND 0
#define OR 1
#define NOT 2
class TPredicate
{
private:
public:
TPremise* premises[MAX_PREMISES_PER_PREDICATE];
int operators[MAX_PREMISES_PER_PREDICATE - 1];
public:
TPredicate();
virtual ~TPredicate();
void clear_premises();
void add_premise(TPremise* _premise);
void remove_premise(TPremise* _premise);
void clear_operators();
void add_operator(int _operator);
void remove_operator(int _operator);
// return collective truth of premises
double Aggregate(int how=ZADEH); // ZADEH, MEAN, ... PRODUCT, BONDEDSUM
bool operator == (TPredicate& predicate2);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Consequent == Premise
class TConsequent
{
public:
TPremise* premise;
public:
TConsequent();
virtual ~TConsequent();
void set_premise(TPremise* _premise);
// return new correlated fuzzyset using aggregated-inputs and premise->fuzzyset,
// doesn't modify premise->fuzzyset
TFuzzySet* Correlate(double aggregation_scalar, int how=TRUNCATE); // TRUNCATE, SCALE
bool operator == (TConsequent& consequent2);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Rule == Predicate | if Predicate then Consequent
class TFuzzyRule
{
private:
bool conditional;
void Correlate ( // correlate aggregated inputs to output
int aggregation_method=ZADEH, // ZADEH, MEAN, ... PRODUCT, BONDEDSUM
int correlation_method=TRUNCATE // TRUNCATE, SCALE
);
void ApplyAlphaCut( // restrict weighed correlated output to area >= or > alphaCut
int alphaCut_type // STRONG, WEAK
);
void ApplyWeight ( // scale-down correlated output by weight
);
public:
TPredicate* predicate; // if-part
TConsequent* consequent; // then-part
TFuzzySet* result_set; // (alpha cutted (weighed (correlated) ) )
double alphaCut;
double weight;
public:
TFuzzyRule(bool _conditional=true, double _alphaCut=0.00, double _weight=1.0);
virtual ~TFuzzyRule();
TFuzzySet* Evaluate (
int aggregation_method=ZADEH, // ZADEH, MEAN, ... PRODUCT, BONDEDSUM
int correlation_method=TRUNCATE, // TRUNCATE, SCALE
int alphaCut_type=STRONG // STRONG, WEAK
);
bool operator == (TFuzzyRule& rule2);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -