OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AttentionValue.cc
Go to the documentation of this file.
1 /*
2  * opencog/atomspace/AttentionValue.cc
3  *
4  * Copyright (C) 2002-2007 Novamente LLC
5  * All Rights Reserved
6  *
7  * Written by Tony Lofthouse <tony_lofthouse@btinternet.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License v3 as
11  * published by the Free Software Foundation and including the exceptions
12  * at http://opencog.org/wiki/Licenses
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program; if not, write to:
21  * Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #include "Atom.h"
26 #include "AttentionValue.h"
27 
28 using namespace opencog;
29 
33 
35 {
36  // Prevent m_STI from wrapping around... should really compare to system
37  // constant though.
38  if (m_STI != -32768) m_STI--;
39 }
40 
41 std::string AttentionValue::toString() const
42 {
43  char buffer[256];
44  sprintf(buffer, "[%d, %d, %s]", (int)m_STI, (int)m_LTI, m_VLTI ? "NONDISPOSABLE" : "DISPOSABLE");
45  return buffer;
46 }
47 
48 bool AttentionValue::STISort::test(const AtomPtr& h1, const AtomPtr& h2) const
49 {
50  return h1->getAttentionValue()->getSTI() >
51  h2->getAttentionValue()->getSTI();
52 }
53 
55 {
56  lti_t lti1, lti2;
57  float tv1, tv2;
58 
59  tv1 = fabs(h1->getTruthValue()->getMean());
60  tv2 = fabs(h2->getTruthValue()->getMean());
61 
62  lti1 = h1->getAttentionValue()->getLTI();
63  lti2 = h2->getAttentionValue()->getLTI();
64 
65  if (lti1 < 0)
66  tv1 = lti1 * (1.0f - tv1);
67  else
68  tv1 = lti1 * tv1;
69 
70  if (lti2 < 0)
71  tv2 = lti2 * (1.0f - tv2);
72  else
73  tv2 = lti2 * tv2;
74 
75  return tv1 < tv2;
76 }
77 
79 {
80  lti_t lti1, lti2;
81  lti1 = h1->getAttentionValue()->getLTI();
82  lti2 = h2->getAttentionValue()->getLTI();
83 
84  if (lti1 != lti2) return lti1 < lti2;
85 
86  float tv1, tv2;
87  tv1 = h1->getTruthValue()->getMean();
88  tv2 = h2->getTruthValue()->getMean();
89  return tv1 < tv2;
90 }
virtual bool test(const AtomPtr &, const AtomPtr &) const
std::shared_ptr< Atom > AtomPtr
Definition: Handle.h:48
short vlti_t
very long-term importance type
virtual bool test(const AtomPtr &, const AtomPtr &) const
short lti_t
long-term importance type
static const lti_t DEFAULTATOMLTI
long-term importance default
virtual bool test(const AtomPtr &, const AtomPtr &) const
short sti_t
short-term importance type
sti_t m_STI
short-term importance
void decaySTI()
default attention value
std::string toString() const
Returns const string "[sti_val, lti_val, vlti_val]".
static const sti_t DEFAULTATOMSTI
short-term importance default
lti_t m_LTI
long-term importance
static const vlti_t DEFAULTATOMVLTI
very long-term default