Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Atomese Formulas, and not scheme, for math #6

Open
linas opened this issue Dec 10, 2019 · 1 comment
Open

Use Atomese Formulas, and not scheme, for math #6

linas opened this issue Dec 10, 2019 · 1 comment

Comments

@linas
Copy link
Member

linas commented Dec 10, 2019

Friendly reminder, because I think it has fallen off the TODO-list. The new atomese formula support is likely to be a lot faster than using (GroundedPredicateNode "scm:foo-formula") See https://github.com/opencog/atomspace/blob/master/examples/atomspace/formulas.scm for a working example; I copy part of it below to give a flavor of it:

; Create a SimpleTruthValue with a non-trivial formula:
; It will be the TV := (1-sA*sB, cA*cB) where sA and sB are strenghts
; and cA, cB are confidence values. The PredicateFormulaLink assembles
; two floating-point values, and create a SimpleTruthValue out of them.
;
(cog-evaluate!
   (PredicateFormula
      (Minus
         (Number 1)
         (Times (StrengthOf (Concept "A")) (StrengthOf (Concept "B"))))
      (Times (ConfidenceOf (Concept "A")) (ConfidenceOf (Concept "B")))))

; The values do not need to be formulas; they can be hard-coded numbers.
(cog-evaluate!
   (PredicateFormula (Number 0.7) (Number 0.314)))

; The below computes a truth value, and attaches it to the
; EvaluationLink. Let's demo this in three parts: first define it,
; then evaluate it, then look at it.
;
(define my-ev-link
   (Evaluation
      (PredicateFormula (Number 0.7) (Number 0.314))
      (List
         (Concept "A")
         (Concept "B"))))

; Evaluate ...
(cog-evaluate! my-ev-link)

; Print.
(display my-ev-link)

; More typically, one wishes to have a formula in the abstract,
; with variables in it, so that one can apply it in any one of
; a number of different situations. In the below, the variables
; are automatically reduced with the Atoms in the ListLink, and
; then the formula is evaluated to obtain a TruthValue.
(cog-evaluate!
   (Evaluation
      ; Compute TV = (1-sA*sB, cA*cB)
      (PredicateFormula
         (Minus
            (Number 1)
            (Times
               (StrengthOf (Variable "$X"))
               (StrengthOf (Variable "$Y"))))
         (Times
            (ConfidenceOf (Variable "$X"))
            (ConfidenceOf (Variable "$Y"))))
      (List
         (Concept "A")
         (Concept "B"))))

and so on. The example gives even more details that make it even more PLN-useful.

@linas
Copy link
Member Author

linas commented Apr 24, 2020

ngeiswei pushed a commit to ngeiswei/pln that referenced this issue Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant