OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IndefiniteTruthValue.h
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/IndefiniteTruthValue.h
3  *
4  * Copyright (C) 2002-2007 Novamente LLC
5  * All Rights Reserved
6  *
7  * Written by Welter Silva <welter@vettalabs.com>
8  * Fabricio Silva <fabricio@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_INDEFINITE_TRUTH_VALUE_H
27 #define _OPENCOG_INDEFINITE_TRUTH_VALUE_H
28 
29 #include <memory>
30 #include <vector>
31 
33 
34 namespace opencog
35 {
41 typedef std::shared_ptr<IndefiniteTruthValue> IndefiniteTruthValuePtr;
42 
44  { return std::dynamic_pointer_cast<IndefiniteTruthValue>(tv); }
45 
51 {
52 private:
53 
57  bool symmetric;
58 
63 
72  mutable strength_t mean;
74  mutable count_t count;
77 
78  std::vector<strength_t*> firstOrderDistribution;
79 
80  void init(strength_t l = 0.0f, strength_t u = 0.0f,
82  void copy(const IndefiniteTruthValue&);
83 
86 
87 public:
92 
94  virtual bool operator==(const TruthValue& rhs) const;
95 
96  strength_t getMean() const;
97  strength_t getU() const;
98  strength_t getL() const;
101  const std::vector<strength_t*>& getFirstOrderDistribution() const;
102 
103  void setMean(strength_t);
104  void setU(strength_t);
105  void setL(strength_t);
107  void setDiff(strength_t);
108  void setFirstOrderDistribution(const std::vector<strength_t*>&);
109  void setSymmetric(bool s) { symmetric = s; }
110 
111  count_t getCount() const;
112  confidence_t getConfidence() const;
113  strength_t getU_() const;
114  strength_t getL_() const;
115  bool isSymmetric() const;
116 
118 
119  std::string toString() const;
120  TruthValueType getType() const;
121 
122  // clone method
124  {
125  if (tv->getType() != INDEFINITE_TRUTH_VALUE)
126  throw RuntimeException(TRACE_INFO, "Cannot clone non-indefinite TV");
127  return std::make_shared<IndefiniteTruthValue>(
128  static_cast<const IndefiniteTruthValue&>(*tv));
129  }
130 
132  {
133  return std::static_pointer_cast<TruthValue>(createITV(tv));
134  }
135 
138  {
139  return std::make_shared<IndefiniteTruthValue>(l, u, c);
140  }
141 
144  {
145  return std::static_pointer_cast<TruthValue>(createITV(l, u, c));
146  }
147 
149  {
150  return std::make_shared<IndefiniteTruthValue>(*this);
151  }
152 
154  {
155  return new IndefiniteTruthValue(*this);
156  }
157 
161  static strength_t s; //Nil : not that sure s should be strength_t
164  }
165  static void setDefaultK(count_t k) {
166  DEFAULT_K = k;
167  }
168 };
169 
171 } // namespace opencog
172 
173 #endif // _OPENCOG_INDEFINITE_TRUTH_VALUE_H
strength_t findDiff(strength_t idiff)
find diff by dichotomy
void setFirstOrderDistribution(const std::vector< strength_t * > &)
void init(strength_t l=0.0f, strength_t u=0.0f, confidence_t c=DEFAULT_CONFIDENCE_LEVEL)
const std::vector< strength_t * > & getFirstOrderDistribution() const
static IndefiniteTruthValuePtr createITV(strength_t l, strength_t u, confidence_t c=DEFAULT_CONFIDENCE_LEVEL)
TruthValueType
Definition: TruthValue.h:63
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::vector< strength_t * > firstOrderDistribution
static confidence_t DEFAULT_CONFIDENCE_LEVEL
static void setDefaultK(count_t k)
float strength_t
float confidence_t
double count_t
confidence_t getConfidenceLevel() const
static void setDefaultConfidenceLevel(confidence_t c)
std::shared_ptr< IndefiniteTruthValue > IndefiniteTruthValuePtr
static TruthValuePtr createTV(strength_t l, strength_t u, confidence_t c=DEFAULT_CONFIDENCE_LEVEL)
confidence_t confidenceLevel
referred as "b" in the paper
void copy(const IndefiniteTruthValue &)
TruthValuePtr merge(TruthValuePtr, TVMergeStyle ms=DEFAULT) const
static IndefiniteTruthValuePtr createITV(TruthValuePtr tv)
static TruthValuePtr createTV(TruthValuePtr tv)
virtual bool operator==(const TruthValue &rhs) const
it is a strict equality comparison, without error interval tolerance
static IndefiniteTruthValuePtr IndefiniteTVCast(TruthValuePtr tv)
TVMergeStyle
Definition: TruthValue.h:76