worked example: active-logic
description:
proof of concept using simple if-then machines
in this case, concerning wet grass, the sprinkler and rain
code:
-- learn the meaning of not:
not |no> => |yes>
not |yes> => |no>
not |don't know> => |don't know>
-- define our if-then machines:
pattern |node 1: 1> => |grass is wet> + |not rained last night>
then |node 1: 1> => 2.0|sprinkler was on> + -1.0|rained last night> + -1.0|not grass is wet>
pattern |node 2: 1> => |grass is wet> + |not sprinkler was on>
then |node 2: 1> => 2.0|rained last night> + -1.0|sprinkler was on> + -1.0|not grass is wet>
pattern |node 3: 1> => |sprinkler was on>
then |node 3: 1> => |grass is wet> + -1.0|not sprinkler was on>
pattern |node 3: 2> => |rained last night>
then |node 3: 2> => |grass is wet> + -1.0|not rained last night>
pattern |node 4: 1> => |not rained last night> + |not sprinkler was on>
then |node 4: 1> => 2.0|not grass is wet> + -1.0|rained last night> + -1.0|sprinkler was on>
-- learn state of activation:
active |rained last night> => |don't know>
active |not rained last night> #=> not active |rained last night>
active |sprinkler was on> => |don't know>
active |not sprinkler was on> #=> not active |sprinkler was on>
active |grass is wet> => |don't know>
active |not grass is wet> #=> not active |grass is wet>
-- activation states we want to unlearn:
the-unlearn |list> => |rained last night> + |sprinkler was on> + |grass is wet>
-- unlearn operators:
unlearn |*> #=> learn(|op: active>, |_self>, |don't know>)
unlearn-everything |*> #=> unlearn the-unlearn |list>
-- our 'active' operators:
make-active |*> #=> learn(|op: active>, remove-prefix["not "] |_self>, not has-prefix["not "] |_self>)
currently-active |*> #=> such-that[active] rel-kets[active] |>
read-sentence |*> #=> make-active words-to-list |_self>
-- define our conclude operators:
conclude |*> #=> drop then similar-input[pattern] such-that[active] rel-kets[active] |>
inverse-conclude |*> #=> pattern similar-input[then] such-that[active] rel-kets[active] |>
-- define short-cuts for our tables:
t |*> #=> table[state, unlearn-everything, read-sentence, currently-active, conclude, inverse-conclude] the-list-of |states>
t2 |*> #=> table[state, unlearn-everything, read-sentence, currently-active, conclude] the-list-of |states>
-- learn the list of states we want in our tables:
the-list-of |states> => |grass is wet>
the-list-of |states> +=> |sprinkler was on>
the-list-of |states> +=> |rained last night>
the-list-of |states> +=> |sprinkler was on and rained last night>
the-list-of |states> +=> |grass is wet and not rained last night>
the-list-of |states> +=> |grass is wet and not sprinkler was on>
the-list-of |states> +=> |not rained last night>
the-list-of |states> +=> |not sprinkler was on>
the-list-of |states> +=> |not rained last night and not sprinkler was on>
the-list-of |states> +=> |not grass is wet>
examples:
unlearn-everything
3|don't know>
read-sentence |grass is wet and not rained last night>
|yes> + |no>
currently-active
|not rained last night> + |grass is wet>
conclude
|sprinkler was on>
t2
+------------------------------------------------+--------------------+---------------+---------------------------------------------+-----------------------------------------------+
| state | unlearn-everything | read-sentence | currently-active | conclude |
+------------------------------------------------+--------------------+---------------+---------------------------------------------+-----------------------------------------------+
| grass is wet | 3 don't know | yes | grass is wet | 0.50 sprinkler was on, 0.50 rained last night |
| sprinkler was on | 3 don't know | yes | sprinkler was on | grass is wet |
| rained last night | 3 don't know | yes | rained last night | grass is wet |
| sprinkler was on and rained last night | 3 don't know | 2 yes | rained last night, sprinkler was on | grass is wet |
| grass is wet and not rained last night | 3 don't know | yes, no | not rained last night, grass is wet | sprinkler was on |
| grass is wet and not sprinkler was on | 3 don't know | yes, no | not sprinkler was on, grass is wet | rained last night |
| not rained last night | 3 don't know | no | not rained last night | 0.50 sprinkler was on, 0.50 not grass is wet |
| not sprinkler was on | 3 don't know | no | not sprinkler was on | 0.50 rained last night, 0.50 not grass is wet |
| not rained last night and not sprinkler was on | 3 don't know | 2 no | not rained last night, not sprinkler was on | not grass is wet |
| not grass is wet | 3 don't know | no | not grass is wet | |
+------------------------------------------------+--------------------+---------------+---------------------------------------------+-----------------------------------------------+
source code:
load improved-active-logic.sw
Home