forked from trueagi-io/hyperon-experimental
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request trueagi-io#550 from astroseger/simple-bhv-binding
Minimal integration of Hypervectors to Metta (via PyBHV python library)
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
!(extend-py! bhv_binding) | ||
|
||
!(bind! &a (bhv-new)) | ||
!(bind! &b (bhv-new)) | ||
!(bind! &c (bhv-new)) | ||
|
||
!(bind! &abc (bhv-majority &a &b &c )) | ||
|
||
!(bhv-std-apart-relative &a &abc) | ||
!(bhv-is-related &a &abc) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
!(extend-py! bhv_binding) | ||
|
||
!(bind! &a (bhv-new)) | ||
!(bind! &b (bhv-new)) | ||
|
||
!(bind! &perm1 (bhv-new-perm)) | ||
(= (perm1 $x) (bhv-apply-perm &perm1 $x)) | ||
|
||
!(bind! ab (bhv-majority &a &b )) | ||
|
||
; Should return False since a is permuted but ab is not permuted | ||
!(bhv-is-related (perm1 &a) ab) | ||
|
||
;Should return True | ||
!(bhv-is-related (perm1 &a) (perm1 ab)) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
!(extend-py! bhv_binding) | ||
|
||
!(bind! &v1 (bhv-new)) | ||
!(bind! &v2 (bhv-new)) | ||
!(bind! &v3 (bhv-new)) | ||
!(bind! &k1 (bhv-new)) | ||
!(bind! &k2 (bhv-new)) | ||
!(bind! &k3 (bhv-new)) | ||
|
||
|
||
!(bind! dict (bhv-majority (bhv-bind &v1 &k1) (bhv-bind &v2 &k2) (bhv-bind &v3 &k3) )) | ||
!(bind! v1_retrived (bhv-bind &k1 dict)) | ||
|
||
!(bhv-std-apart-relative v1_retrived &v1) | ||
!(bhv-is-related v1_retrived &v1) | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
python/sandbox/bhv_binding/04_example_dollar_of_mexico.metta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
!(extend-py! bhv_binding) | ||
|
||
!(bind! &name (bhv-new)) | ||
!(bind! &capital_city (bhv-new)) | ||
!(bind! &money (bhv-new)) | ||
!(bind! &united_states (bhv-new)) | ||
!(bind! &washington_dc (bhv-new)) | ||
!(bind! &dollar (bhv-new)) | ||
!(bind! &mexico (bhv-new)) | ||
!(bind! &mexico_city (bhv-new)) | ||
!(bind! &peso (bhv-new)) | ||
|
||
|
||
!(bind! USA (bhv-majority (bhv-bind &name &united_states) (bhv-bind &capital_city &washington_dc) (bhv-bind &money &dollar) )) | ||
!(bind! MEX (bhv-majority (bhv-bind &name &mexico) (bhv-bind &capital_city &mexico_city) (bhv-bind &money &peso) )) | ||
|
||
!(bind! Pair (bhv-bind USA MEX)) | ||
|
||
; should return True here | ||
!(bhv-is-related (bhv-bind USA &money) &dollar) | ||
|
||
|
||
!(bind! dollar_of_mexico (bhv-bind &dollar Pair)) | ||
|
||
; should return True here. "Dollar of mexico" is peso | ||
!(bhv-is-related dollar_of_mexico &peso) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from hyperon.atoms import OperationAtom | ||
from hyperon.ext import register_atoms | ||
from bhv.np import NumPyBoolBHV as BHV, NumPyBoolPermutation as Perm | ||
|
||
|
||
@register_atoms | ||
def my_atoms(): | ||
return { | ||
'bhv-new': OperationAtom('bhv-new', BHV.rand), | ||
'bhv-majority': OperationAtom('bhv-majority', lambda *args: BHV.majority(list(args))), | ||
'bhv-bind': OperationAtom('bhv-bind', lambda a,b: a^b), | ||
'bhv-std-apart-relative': OperationAtom('bhv-std-apart-relative', lambda a,b: a.std_apart(b, relative = True)), | ||
'bhv-is-related': OperationAtom('bhv-is-related', lambda a,b: a.related(b)), | ||
'bhv-new-perm': OperationAtom('bhv-perm', Perm.random), | ||
'bhv-apply-perm': OperationAtom('bhv-apply-perm', lambda a, b: a(b)) | ||
} |