predicates.h
Go to the documentation of this file.
00001 #ifndef IRI_RULE_LEARNER_PREDICATESS_H
00002 #define IRI_RULE_LEARNER_PREDICATESS_H 1
00003 
00004 #include <iri_rule_learner/RuleLearnerConfig.h>
00005 #include <fstream>
00006 #include <symbols.h>
00007 
00008 class Predicate : public Symbol
00009 {
00010     public:
00011         bool positive_;
00012         
00013         Predicate(std::string name, std::vector<std::string> param_names, bool positive) :
00014             Symbol(name, param_names),
00015             positive_(positive)
00016         { }
00017         
00018         Predicate(Symbol symbol, bool positive) :
00019             Symbol(symbol),
00020             positive_(positive)
00021         { }
00022         
00023         bool satisfies(Predicate predicate)
00024         {
00025                 // TODO param names?
00026             if ( (this->name_.compare(predicate.name_) == 0) && (this->positive_ == predicate.positive_))
00027                 return true;
00028             else
00029                 return false;
00030         }
00031         
00032         Predicate get_negated()
00033         {
00034             return Predicate(*this, !positive_);
00035         }
00036         
00037         friend bool operator==(Predicate &p1, Predicate &p2);
00038         friend std::ostream& operator<<(std::ostream &out, const Predicate& p);
00039 };
00040 
00041 
00042 
00043 typedef std::vector<Predicate> PredicateList;
00044 
00045 class PredicateGroup
00046 {
00047     public:
00048         PredicateList predicates_;
00049         
00050         PredicateGroup( ){ }
00051         PredicateGroup(PredicateList predicates);
00052         PredicateGroup(std::string predicates);
00053         
00054         bool is_satisfied(PredicateList predicates);
00055         
00056         int count_satisfied(PredicateList predicates);
00057         
00058         int number_parameters();
00059         
00060         void change_variable(std::string orig_var, std::string new_var);
00061         
00062         PredicateGroup get_predicates_with_vars(std::vector< std::string > variables) ;
00063         
00064         void add_positive_differences(PredicateGroup compared_group);
00065         PredicateGroup get_differences(const PredicateGroup compared_group);
00066         
00067         void remove_duplicated();
00068         void remove_variables_not_present(std::vector<std::string> variables);
00069         
00070         friend std::ostream& operator<<(std::ostream &out, const PredicateGroup& p);
00071 };
00072 
00073 
00074 class Outcome : public PredicateGroup
00075 {
00076     public:
00077         float init_probability_;
00078         float current_probability_;
00079         uint num_executions_;
00080         bool noisy_;
00081         
00082         Outcome(float init_probability, bool noisy = false) :
00083             PredicateGroup(),
00084             init_probability_(init_probability),
00085             current_probability_(init_probability),
00086             num_executions_(0),
00087             noisy_(noisy)
00088         { }
00089         
00090         Outcome(PredicateList predicates, float init_probability) :
00091             PredicateGroup(predicates),
00092             init_probability_(init_probability),
00093             current_probability_(init_probability),
00094             num_executions_(0),
00095             noisy_(false)
00096         { }
00097         
00098         void add_execution() { num_executions_++; }
00099         
00100         // m-estimate formula
00101         void update_probability(uint total_executions, uint m) 
00102         {
00103             current_probability_ =  ((init_probability_ * m) + num_executions_)/(m + total_executions);
00104         }
00105         
00106         friend std::ostream& operator<<(std::ostream &out, const Outcome& o);
00107 };
00108 
00109 typedef std::vector<Outcome> OutcomeList; 
00110 
00111 
00112 
00113 // get data from string
00114 PredicateList get_predicates_from_string(std::string line);
00115 Outcome get_outcome_from_string(std::string line);
00116 
00117 #endif


iri_rule_learner
Author(s): dmartinez
autogenerated on Fri Dec 6 2013 20:43:48