📄 tfuzzyset.h
字号:
// negation
#define NOT 2 // ! // as defined in eOperator in FuzzyRules.h
// fuzzify a scalar, or widen
#define ABOUT 3 // fuzzify(singlton), or widen
#define AROUND ABOUT
#define ROUGHLY ABOUT
// restrict
#define ABOVE 4 // shift_right(50%)
#define LESS_THAN ABOVE
// restrict
#define BELOW 5 // shift_left(50%)
#define MORE_THAN BELOW
// contrast intensification (rotate_anti_clock_wise)
#define POSITIVELY 6 // if truths[x]<=0.5 --> n*(( x)^n), if x>=mid --> 1 - n*((1-x)^n) , [n=2]
#define ALMOST POSITIVELY
#define DEFINITELY POSITIVELY
// contrast diffusion (rotate_clock_wise)
#define GENERALLY 7 // if truths[x]> 0.5 --> ((1/n)*( x))^(1/n), if x>=mid --> 1 - ((1/n)*(1-x))^(1/n) , [n=2]
#define USUALLY GENERALLY
// approximate broadly
#define IN_THE_VICINITY_OF 8 // widen a lot
// approximate narrowly
#define CLOSE_TO 9 // narrow a lot
#define NEIGHBORING CLOSE_TO
// dilute
#define SLIGHTLY 10 // x^(1/n) , [n=3]
#define SOMEWHAT 11 // x^(1/n) , [n=2]
#define RATHER SOMEWHAT
#define QUITE SOMEWHAT
// intensify ^n
#define VERY 12 // x^n , [n=2]
#define EXTREMELY 13 // x^n , [n=3]
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// alpha cut types
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define STRONG 0 // restrict domain to x:truth(x) > alphaCut
#define WEAK 1 // restrict domain to x:truth(x) >= alphaCut
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logical operators implementation methods for and() or() not()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ZADEH 0 // min(s1,s2) max(s1,s2) 1-s1
#define MEAN 1 // (s1+s2)/2 (2*min(s1,s2)+4*max(s1,s2))/6 1-s1
#define MEANSQUARE 2 // ((s1+s2)/2)^2 ((2*min(s1,s2)+4*max(s1,s2))/6)^2 1-s1
#define MEANROOT 3 // ((s1+s2)/2)^.5 ((2*min(s1,s2)+4*max(s1,s2))/6)^.5 1-s1
#define PRODUCT 4 // s1*s2 (s1+s2)-(s1*s2) 1-s1
#define BOUNDEDSUM 5 // max(0,(s1+s2-1)) min(1,(s1+s2))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// aggregation methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// use logical operators for ANDing
#define ZADEH 0
#define MEAN 1
#define MEANSQUARE 2
#define MEANROOT 3
#define PRODUCT 4
#define BOUNDEDSUM 5
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// correlation methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define TRUNCATE 0 // limit consequence's maxTruth to predicates-aggregated value
#define SCALE 1 // scale-down consequence by the predicates-aggregated value
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// composition methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// use logical operators for ORing
#define ZADEH 0
#define MEAN 1
#define MEANSQUARE 2
#define MEANROOT 3
#define PRODUCT 4
#define BOUNDEDSUM 5
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// defuzzification methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define CENTROID 0 //find domain point x at the centre of gravity ({Xi*Yi}/{Yi})
#define COMPOSITE_MOMENTS CENTROID
#define COMPOSITE_MAXIMUM 1 //find domain point x with maximum truth, if plateau, then use either AVERAGE_MAXIMUM, or CENTRE_OF_MAXIMUMS
#define MAXIMUM_HEIGHT COMPOSITE_MAXIMUM
#define NEAR_EDGE 2 //find x at the left edge of usually a single-edged plateau
#define FAR_EDGE 3 //find x at the right edge of usually a single-edged plateau
#define CENTROID_SUPPORT_SET 4 //similar to CENTROID, but for only the part of the domain with truth(X) > alphaCut (STRONG)
#define AVERAGE_MAXIMUM 5 //similar to MAXIMUM_HEIGHT, but for only the highest plateau, or singlton
#define CENTRE_OF_MAXIMUMS 6 //similar to MAXIMUM_HEIGHT, but for only the two highest plateaus, or singltons
#define CENTRE_OF_MASS 7 //find x at the centre of the region supported by the maximum number of rules or evidence
#define BEST_EVIDENCE CENTRE_OF_MASS
#define LEAST_ENTROPY 8 //find x for the least degree of fuzzyness (information entropy)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TFuzzySet decleration
////////////////////////////////////////////////////////////////////////////////
class TFuzzySet
{
private:
TVariable* variable;
char* name;
int shape;
int direction;
double min; // start of domain
double mid1; // somewhere between min and mid
double mid; // near the middle of the domain
double mid2; // somewhere between mid and max
double max; // end of domain
double minTruth;
double maxTruth;
double truths[DOMAIN_POINTS]; // membership function points
int hedges[MAX_HEDGES]; // hedges applied to fuzzy set
double alphaCut; // restrict domain to x:truth(x) >= alphaCut (STRONG defualt)
void interpolate_truths();
public:
TFuzzySet( TVariable* _variable = NULL,
char* _name = NULL,
int _shape = NO_SHAPE,
int _direction = UP,
double _min = 0.00 * DOMAIN_WIDTH,
double _mid1 = 0.25 * DOMAIN_WIDTH,
double _mid = 0.50 * DOMAIN_WIDTH,
double _mid2 = 0.75 * DOMAIN_WIDTH,
double _max = 1.00 * DOMAIN_WIDTH,
double _minTruth = 0.0,
double _maxTruth = 1.0
);
TFuzzySet(TFuzzySet& set2); // copy constructor (for deep copy)
TFuzzySet(double scalar); // convert scalar into a singleton
virtual ~TFuzzySet();
TVariable* get_variable () {return variable;}
char* get_name () {return name;}
int get_shape () {return shape;}
int get_direction () {return direction;}
double get_min () {return ( (min * (variable->end - variable->begin))/DOMAIN_WIDTH + variable->begin );}
double get_mid1 () {return ( (mid1* (variable->end - variable->begin))/DOMAIN_WIDTH + variable->begin );}
double get_mid () {return ( (mid * (variable->end - variable->begin))/DOMAIN_WIDTH + variable->begin );}
double get_mid2 () {return ( (mid2* (variable->end - variable->begin))/DOMAIN_WIDTH + variable->begin );}
double get_max () {return ( (max * (variable->end - variable->begin))/DOMAIN_WIDTH + variable->begin );}
double get_minTruth () {return minTruth;}
double get_maxTruth () {return maxTruth;}
double truth (double x) { truths[(int)x];}
int get_hedge (int i) {return hedges[i];}
double get_alphaCut () {return alphaCut;}
void set_variable (TVariable* _variable) { variable = _variable; }
void set_name (char* _name) { if (name != NULL) delete[] name; name = new char[strlen(_name)+1]; strcpy(name, _name); }
void set_shape (int _shape) { shape = _shape; }
void set_direction (int _direction) { direction = _direction; }
void set_min (double _min ) { min = ((_min - variable->begin)/(variable->end - variable->begin))*DOMAIN_WIDTH ; }
void set_mid1 (double _mid1) { mid1 = ((_mid1 - variable->begin)/(variable->end - variable->begin))*DOMAIN_WIDTH ; }
void set_mid (double _mid ) { mid = ((_mid - variable->begin)/(variable->end - variable->begin))*DOMAIN_WIDTH ; }
void set_mid2 (double _mid2) { mid2 = ((_mid2 - variable->begin)/(variable->end - variable->begin))*DOMAIN_WIDTH ; }
void set_max (double _max ) { max = ((_max - variable->begin)/(variable->end - variable->begin))*DOMAIN_WIDTH ; }
void set_minTruth (double _minTruth) { minTruth = _minTruth; }
void set_maxTruth (double _maxTruth) { maxTruth = _maxTruth; }
void clear_hedges ();
void add_hedge (int type);
void remove_hedge (int type);
void set_alphaCut (double _alphaCut) { alphaCut = _alphaCut; }
// manipulator functions
void normalize (); // multiply all by 1.0/maxTruth() so that maxTruth()=1.0
bool normalized (); // is normalised?
void truncate (double _maxTruth); // for all truth(x) > _maxTruth make truth(x) = _maxTruth
void apply_alphaCut (int type=STRONG);
double defuzzify (int how=CENTROID); // convert to a scalar
// move and resize functions
void shift_left (double percent);
void shift_right (double percent);
void shift_up (double factor);
void shift_down (double percent);
void narrow (double percent);
void widen (double factor);
void scale_up (double factor);
void scale_down (double percent);
// logical operators (for all Zahed and non_Zadeh styles)
TFuzzySet& and (TFuzzySet& set2, int type=ZADEH);
TFuzzySet& or (TFuzzySet& set2, int type=ZADEH);
TFuzzySet& not (int type=ZADEH);
bool operator == (TFuzzySet& set2); // comparison
bool operator != (TFuzzySet& set2); // comparison
bool operator < (TFuzzySet& set2); // comparison
bool operator > (TFuzzySet& set2); // comparison
bool operator <= (TFuzzySet& set2); // comparison
bool operator >= (TFuzzySet& set2); // comparison
TFuzzySet& operator = (TFuzzySet& set2); // assignment
friend TFuzzySet& operator + (TFuzzySet& set1, TFuzzySet& set2); // WARNING: maxTruth can be > 1.0
friend TFuzzySet& operator + (TFuzzySet& set1, double shift); // shift-up
friend TFuzzySet& operator + (double shift, TFuzzySet& set1); // shift-up
friend TFuzzySet& operator - (TFuzzySet& set1, TFuzzySet& set2); // WARNING: maxTruth can be > 1.0
friend TFuzzySet& operator - (TFuzzySet& set1, double shift); // shift-down
friend TFuzzySet& operator - (double shift, TFuzzySet& set1); // shift-down
friend TFuzzySet& operator * (TFuzzySet& set1, TFuzzySet& set2); // WARNING: maxTruth can be > 1.0
friend TFuzzySet& operator * (TFuzzySet& set1, double factor); // scale up
friend TFuzzySet& operator * (double factor, TFuzzySet& set1); // scale up
friend TFuzzySet& operator / (TFuzzySet& set1, TFuzzySet& set2); // WARNING: maxTruth can be > 1.0
friend TFuzzySet& operator / (TFuzzySet& set1, double percent); // scale down
friend TFuzzySet& operator / (double percent, TFuzzySet& set1); // scale down
friend TFuzzySet& operator ^ (TFuzzySet& set1, double power); // hedge (dilute or intensify)
friend TFuzzySet& operator && (TFuzzySet& set1, TFuzzySet& set2); // Zadeh and
friend TFuzzySet& operator || (TFuzzySet& set1, TFuzzySet& set2); // Zadeh or
friend TFuzzySet& operator ! (TFuzzySet& set1); // Zadeh not
double operator [] (double x); // truth(double)
operator double (); // defuzzify (convert to double)
friend ostream& operator << (ostream& s, TFuzzySet& set1); // save
friend istream& operator >> (istream& s, TFuzzySet& set1); // load
// graphics
void Draw(TCanvas* canvas);
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -