OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TruthValue.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/TruthValue.h
3  *
4  * Copyright (C) 2002-2007 Novamente LLC
5  * All Rights Reserved
6  *
7  * Written by Guilherme Lamacie
8  * Welter Silva <welter@vettalabs.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License v3 as
12  * published by the Free Software Foundation and including the exceptions
13  * at http://opencog.org/wiki/Licenses
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program; if not, write to:
22  * Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #ifndef _OPENCOG_TRUTH_VALUE_H
27 #define _OPENCOG_TRUTH_VALUE_H
28 
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 #include <opencog/util/exceptions.h>
34 
39 class TruthValueUTest;
40 
41 namespace opencog
42 {
43 
44 // Truth-value components
45 // For essentially all truth-value calculations, float is enough, so
46 // we save space here, and use float. For counting, a float is not
47 // enough -- it gets up to 16 million (24 bits) and then clamps. So
48 // we use a double for counting, which should provide 48 bits. Since
49 // SimpleTruthValue does not store count anyway, there is no storage
50 // penalty associated with this.
51 typedef float strength_t;
52 typedef float confidence_t;
53 typedef double count_t;
54 
62 // NUMBER_OF_TRUTH_VALUE_TYPES must be the last one in this enum.
64 {
72 };
73 
74 //Flags for alternative ways of merging two different truth value types
75 //as described in https://github.com/opencog/opencog/issues/1295
77 {
83 };
84 
85 class TruthValue;
86 typedef std::shared_ptr<TruthValue> TruthValuePtr;
87 
89  : public std::enable_shared_from_this<TruthValue>
90 {
91  friend class SavingLoading;
92  friend class Atom;
93 
94  // the TruthValueUTest class needs to access private members from the
95  // TruthValue class, so we declare it as a friend class.
96  friend class ::TruthValueUTest;
97 
98  // Disallow assignment -- truth values are immutable!
100  throw RuntimeException(TRACE_INFO, "Cannot modify truth values!");
101  }
102 public:
103  virtual ~TruthValue() {}
104 
105  // Special TVs
106 
113  static TruthValuePtr NULL_TV();
119  static TruthValuePtr TRUE_TV();
125  static TruthValuePtr DEFAULT_TV();
131  static TruthValuePtr FALSE_TV();
137  static TruthValuePtr TRIVIAL_TV();
138 
139 // PURE VIRTUAL METHODS:
140 
141  virtual strength_t getMean() const = 0;
142  virtual confidence_t getConfidence() const = 0;
143  virtual count_t getCount() const = 0;
144 
145  virtual std::string toString() const = 0;
146  virtual TruthValueType getType() const = 0;
147  virtual TruthValuePtr clone() const = 0;
148  virtual TruthValue* rawclone() const = 0;
149 
155  virtual bool operator==(const TruthValue& rhs) const = 0;
156  inline bool operator!=(const TruthValue& rhs) const
157  { return !(*this == rhs); }
158 
159 // VIRTUAL METHODS:
160 
168  virtual TruthValuePtr merge(TruthValuePtr, TVMergeStyle ms=DEFAULT) const = 0;
169 
173  virtual bool isNullTv() const;
174 
178  virtual bool isDefaultTV() const;
179 };
180 
181 } // namespace opencog
182 
183 // overload of operator<< to print TruthValue
184 namespace std {
185  template<typename Out>
186  Out& operator<<(Out& out, const opencog::TruthValue& tv)
187  {
188  out << tv.toString();
189  return out;
190  }
191 } // ~namespace std
192 
193 
195 #endif // _OPENCOG_TRUTH_VALUE_H
TruthValue & operator=(const TruthValue &rhs)
Definition: TruthValue.h:99
virtual bool isDefaultTV() const
Definition: TruthValue.cc:85
virtual count_t getCount() const =0
virtual TruthValueType getType() const =0
static TruthValuePtr TRUE_TV()
Definition: TruthValue.cc:59
TruthValueType
Definition: TruthValue.h:63
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
virtual TruthValuePtr clone() const =0
float strength_t
friend class SavingLoading
Definition: TruthValue.h:91
float confidence_t
double count_t
virtual confidence_t getConfidence() const =0
virtual ~TruthValue()
Definition: TruthValue.h:103
static TruthValuePtr NULL_TV()
Definition: TruthValue.cc:46
virtual bool operator==(const TruthValue &rhs) const =0
static TruthValuePtr TRIVIAL_TV()
Definition: TruthValue.cc:73
bool operator!=(const TruthValue &rhs) const
Definition: TruthValue.h:156
static TruthValuePtr DEFAULT_TV()
Definition: TruthValue.cc:52
virtual TruthValuePtr merge(TruthValuePtr, TVMergeStyle ms=DEFAULT) const =0
static TruthValuePtr FALSE_TV()
Definition: TruthValue.cc:66
ostream & operator<<(ostream &out, const opencog::AtomSpace &as)
Definition: AtomSpace.cc:382
virtual std::string toString() const =0
virtual bool isNullTv() const
Definition: TruthValue.cc:80
virtual TruthValue * rawclone() const =0
virtual strength_t getMean() const =0
TVMergeStyle
Definition: TruthValue.h:76