Talk:Atom

From OpenCog
Jump to: navigation, search

In OpenCog, an Atom captures the notion of an atomic formula (or atom) in mathematical logic. The primary differences between the concept of atoms in logic, and the concept of Atoms in OpenCog is that OpenCog Atoms have TruthValues that are more general than 'true' or 'false'. Another important difference is that AndLink and OrLink are Atoms themselves, and can be used to combine other Atoms, and so OpenCog does not draw a clear distinction between atomic formulas and atomic sentences: both are given equal footing. Likewise, the ForAllLink and ExistsLink are Atoms that are analogs for the logic expressions x and y, while LambdaLink corresponds to the lambda-calculus notion of λx. Patterns with variables to be grounded are specified using the BindLink.

Because all Atoms in OpenCog carry an immutable type, they are perhaps best understood as terms, in the sense of logic or type theory. Atoms are just type instances, annotated with truth values.

A TruthValue gives each Atom a valuation or an interpretation; thus all Atoms in a given, fixed AtomSpace always carry a default valuation/interpretation along with them. Additional interpretations can be created by using contexts and the ContextLink. When contexts are used, truth values resemble conditional probabilities; that is, the truth value of an atom A in context C can be roughly understood to behave as a probability P(A|C).

The more complex and more general notion of an interpretation or structure in model theory is handled by means of the EquivalenceLink and the SatisfyingSetLink. Atoms can be placed into multiple atom spaces for various convenience calculations.

The EvaluationLink allows a relational model to be specified (again, in the sense of model theory), and thus, the collection of Atoms in an AtomSpace can be thought of as being a generalization of a relational database. In a certain sense, the EvaluationLink is the most central and important atom type in OpenCog, as it is how OpenCog implements knowledge representation.

The atom types page provides a general overview of the various different atom types; see the Category:Atom Types for an index of the atom types currently in use.

Atom Types

Main article: Atom types

All Atoms in the AtomSpace have a type. The two most basic types of Atoms are the Node and the Link.

The list of supported atom types can be found in Category:Atom Types. The type of an atom can be specified using the TypeNode or the SignatureLink. Polymorphic types can be specified using the TypeChoice link.

The type, and more generally, the signature, can be checked with the type checker.

Type inheritance is discussed in OpenCogPrime:TypeInheritance.

Implementation

This page describes the Atom C++ class. For conceptual information, see also OpenCogPrime:Atom.

The type of an atom cannot be changed after the atom has been inserted into the AtomSpace: OpenCog atoms are immutable objects, in the programming-language sense. However, the truth value and the activation can be changed.

Scheme interface

Atoms can be created, manipulated and destroyed at the scheme shell command prompt. See scheme for details.

C++ Programming Interface

Atom is the superclass for Node and Link.

   class Atom {
     public:
       inline Type getType();
       TruthValue *getTruthValue();
       float getImportance();
       float getActivation();
       stc::vector<Handle> getIncomingSet();
       void setImportance(float);
       void setActivation(float);
       void setTruthValue(TruthValue *);
   };

One of the main challenges in implementing the core structures is to have code which allows the representation of knowledge patterns (the graph of nodes and links) in a data structure which was simultaneously very compact (in terms of memory usage), flexible in terms of the kind of allowed queries and time efficient for these queries. Our choice was to implement a storage structure based purely in a combination of hashmaps and linked lists, both having Atoms as their base element.

getType() returns the type of the Atom. Nodes and Links in the AtomSpace may have several different types. Types are used in OpenCog to distinguish among different kinds of information or relationships. To avoid problems associated with static typing, C++ classes are not directly used to identify Node and Link types.


getTruthValue() returns the TruthValue object of the Atom. Please read the documentation for the reasoning module to understand the meaning of truth values, and what types of objects may be returned by this method.

getIncomingSet() returns the incoming set of the Atom. The incoming set is explained in the page in Links.

The incoming set is stored inside the Atom in a single linked list while the outgoing set is stored in a Link as an array of Handles with 'arity' elements. The array and the linked list store the Handles and not the Atoms themselves.

Methods to freely update Atom properties:

   setTruthValue()
   setImportance()
   setActivation()

addIncomingHandle() , removeIncomingHandle() , merge() , markForRemoval() and unsetRemovalFlag() are used internally by friend classes, when atoms are being inserted/removed from the AtomSpace, so as to update the references accordingly.

All the other methods are used to maintain the indexing structures which allow fast lookups in queries. This indexing mechanism is detailed further in the document when we discuss the AtomTable implementation.


Class Diagram

AtomClassDiagram.png