Shark Machine Learning Library
  • About Shark
  • Sourceforge
    • Project Summary
    • Downloads
    • Subversion Repository
  • Getting Started
  • Tutorials
  • FAQ
  • Main Modules
    • ReClaM
    • EALib
    • MOO-EALib
    • Fuzzy
  • Tools
    • Mixture
    • Array
    • Rng
    • LinAlg
    • FileUtil
  • Main Page
  • Related Pages
  • Classes

Rule.h

Go to the documentation of this file.
00001 
00009 /* $log$ */
00010 
00011 #ifndef RULE_H
00012 #define RULE_H
00013 
00014 #include <vector>
00015 #include "RCPtr.h"
00016 #include <stdarg.h>  //variable length parameter lists
00017 #include "FuzzySet.h"
00018 #include "FuzzyException.h"
00019 #include "RCPtr.h"
00020 #include "RCObject.h"
00021 
00022 
00023 
00024 class FuzzyException;
00025 class LinguisticTerm;
00026 class RuleBase;
00027 class NDimFS;
00028 
00029 enum Connective {
00030     AND, 
00031     OR, 
00032     PROD, 
00033     PROBOR
00034 }; //order is important cf parsing
00035 
00036 
00037 
00048 class Rule: virtual public RCObject {
00049 public:
00050     typedef std::vector< RCPtr<FuzzySet> >  IORuleType;
00051     typedef std::vector< RCPtr<FuzzySet> >  ConclusionType;
00052 
00053 
00058     Rule(Connective c=AND,
00059          RuleBase * belongsTo = NULL,
00060          double  _weight = 1.0);
00061 
00079 Rule( std::string ruleText,
00080       RuleBase * belongsTo,
00081       double _weight = 1.0 );
00082 
00083 // destructor
00084 virtual                      ~Rule();
00085 
00096 double                       Activation(const std::vector<double> & inputs) const;
00097 
00098 
00099 
00100 
00101 //If single input is required allow double as parameter: (instead of a vector of one element)
00102 
00113 inline double                Activation(double input) const;
00114    
00115    
00116    
00117 
00118 //Allow variable length parameter lists, where the first parameter indictes the number of double arguments: #ARGUMENTS, DOUBLE, DOUBLE...
00119 
00120     // double                       Activation(...) const;
00121 
00122 
00128 void                         setConnective(Connective con);
00129 
00135 std::string                  printRule() const;
00136     
00137     
00143 virtual void                 addPremise(const RCPtr<LinguisticTerm> & lt);
00144     
00151 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00152                         const RCPtr<LinguisticTerm> & lt2);
00153                                             
00161 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00162              const RCPtr<LinguisticTerm> & lt2,
00163              const RCPtr<LinguisticTerm> & lt3);
00164                                             
00173 virtual void addPremise(const RCPtr<LinguisticTerm> & lt1,
00174              const RCPtr<LinguisticTerm> & lt2,
00175              const RCPtr<LinguisticTerm> & lt3,
00176              const RCPtr<LinguisticTerm> & lt4);
00177 
00178 // We are presuming complete conclusions, i.e. each rule in a rule base has the
00179 // same number of entries in the conclusions and the n-th entry in each rule
00180 // refers to the same output.
00181 
00187 virtual void addConclusion(const  RCPtr<LinguisticTerm>& lt);
00188 
00194 NDimFS * getPremise();
00195     
00201 inline const ConclusionType& getConclusion() const {
00202     return(conclusion);
00203 };
00204 
00205 
00211 inline double getWeight() const {
00212     return(weight);
00213 };
00214     
00215 protected:
00216     
00217     RuleBase *                   ruleBasePtr;
00218     
00219 private:
00220     
00221     typedef double ConnectiveFuncType( double, double );
00222     
00223     ConnectiveFuncType*          connectiveFunc;
00224 
00225 //Attributes:
00226     Connective                   ruleConnective;
00227     IORuleType                   premise;
00228     ConclusionType               conclusion;
00229     double                       weight;
00230 
00231 //Methods:
00232     void                         initializePremise();
00233     // The following method is dangerous, because it allows to set the premise
00234     // which must be of normalized form, which is not checked. (cf addPremise)
00235     void                         setRule(IORuleType &, Connective, ConclusionType &);
00236     char*                        nextToken(char* tokenPtr);
00237 };
00238 
00239 #endif