-
Notifications
You must be signed in to change notification settings - Fork 28
PeTTa Refactoring #362
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
Open
K1rubel
wants to merge
10
commits into
iCog-Labs-Dev:ref/PeTTa
Choose a base branch
from
K1rubel:ref/PeTTa
base: ref/PeTTa
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PeTTa Refactoring #362
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c0bc8d6
PeTTa refactoring exemplar selection and test file
K1rubel 14e7686
PeTTa refactoring - list methods
K1rubel 0a063e9
PeTTa refactoring exemplar-type and exemplar-type-test files
K1rubel 7329a88
PeTTa refactoring metapoplation.metta and test file
K1rubel c1736a1
minor fixes to general helpers and test file
K1rubel 39321ef
renamed old test files
K1rubel a15d15e
minor-fix in imported file
K1rubel 9d5b150
minor fixes in imported files
K1rubel 7a6b5bb
Delete utilities/tests/list-methods-testold.metta
K1rubel 3a9cfa2
Delete metapopulation/tests/metapopulation-testold.metta
K1rubel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,109 @@ | ||
| ; !(register-module! ../../../metta-moses) | ||
| !(import! &self ../../../metta-moses/utilities/ordered-set) | ||
| !(import! &self ../../../metta-moses/utilities/list-methods) | ||
| !(import! &self ../../../metta-moses/utilities/general-helpers) | ||
| !(import! &self ../../../metta-moses/metapopulation/exemplar-selection) | ||
| !(import! &self ../../../metta-moses/metapopulation/metapopulation) | ||
| !(import! &self ../../../metta-moses/utilities/tree) | ||
| (: A Bool) | ||
| ;; Get penalized scores | ||
| ; !(assertEqual (getPnScore NilOS) Nil) | ||
| ; !(assertEqual | ||
| ; (getPnScore | ||
| ; (ConsOS (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode NOT) (Cons (mkTree (mkNode A) Nil) Nil)) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil))) (mkDemeId "1") (mkCscore -0.2 1 0.1 0.1 -0.4) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| ; (ConsOS (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil)) (mkDemeId "1") (mkCscore -0.1 2 0.2 0.3 -0.6) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| ; NilOS))) | ||
| ; (Cons -0.4 (Cons -0.6 Nil))) | ||
| ; !(assertEqual | ||
| ; (getPnScore | ||
| ; (ConsOS | ||
| ; (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil)) (mkDemeId "1") (mkCscore -0.1 2 0.2 0.3 -0.6) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| ; (ConsOS | ||
| ; (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil)) (mkDemeId "1") (mkCscore -0.1 2 0.2 0.3 -0.6) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| ; NilOS))) | ||
| ; (Cons -0.6 (Cons -0.6 Nil))) | ||
|
|
||
| ; ;; max of list of values of (List $a) type | ||
| ; !(assertEqual (List.max >= Nil) Nil) | ||
| ; !(assertEqual (List.max >= (Cons 0.75 Nil)) 0.75) | ||
| ; !(assertEqual (List.max >= (Cons 0.9 (Cons 0.5 Nil))) 0.9) | ||
| ; !(assertEqual (List.max >= (Cons 0.1 (Cons 0.4 (Cons 0.65 (Cons 0.9 Nil))))) 0.9) | ||
|
|
||
| ; ;; Boltzman adjusted probablity values | ||
| ; !(assertEqual (let $a (List.sum (normalizeProbs (INV_TEMP) 0.5 (Cons 0.3 Nil))) (get-type $a)) Number) | ||
| ; !(assertEqual (let $a (List.sum (normalizeProbs (INV_TEMP) 0.7 (Cons 0.6 (Cons 0.2 Nil)))) (get-type $a)) Number) | ||
| ; !(assertEqual (let $a (List.sum (normalizeProbs (INV_TEMP) 0.95 (Cons 0.95 (Cons 0.9 (Cons 0.85 Nil))))) (get-type $a)) Number) | ||
| ; !(assertEqual (let $a (List.sum (normalizeProbs (INV_TEMP) 1.0 (Cons 0.9 (Cons 0.85 (Cons 0.95 (Cons 0.7 Nil)))))) (get-type $a)) Number) | ||
|
|
||
| ; ;; roulette -- spinning the wheel favoring expressions with higher scores | ||
| ; !(assertEqual (roulette (Cons 1.0 Nil) 0 0.57) 0) | ||
| ; !(assertEqual (roulette (Cons 1.0 (Cons 0.0067 Nil)) 0 0.9564) 0) | ||
| ; !(assertEqual (roulette (Cons 0.0821 (Cons 0.0067 (Cons 1 Nil))) 0 0.7622) 2) | ||
| ; !(assertEqual (roulette (Cons 0.2 (Cons 0.5 (Cons 0.6 (Cons 0.2 Nil)))) 0 1.1) 2) | ||
| ; !(assertEqual (roulette (Cons 0.0067 (Cons 0.0821 (Cons 1.0 Nil))) 0 0.0108) 1) | ||
|
|
||
| ;; Tree Definitions | ||
| (= (treeA) (mkTree (mkNode A) Nil)) | ||
| (= (treeB) (mkTree (mkNode AND) (Cons (mkTree (mkNode A) Nil) (Cons (mkTree (mkNode C) Nil) Nil)))) | ||
| (= (treeC) (mkTree (mkNode OR) (Cons (mkTree (mkNode A) Nil) (Cons (mkTree (mkNode B) Nil) Nil)))) | ||
| (= (treeY) (mkTree (mkNode AND) (Cons (mkTree (mkNode A) Nil) (Cons (mkTree (mkNode Z) Nil) Nil)))) | ||
| (= (treeZ) (mkTree (mkNode OR) (Cons (mkTree (mkNode A) Nil) (Cons (mkTree (mkNode X) Nil) Nil)))) | ||
| (= (tree2) (mkTree (mkNode AND) (Cons (mkTree (mkNode A) Nil) Nil))) | ||
| (= (tree3) (mkTree (mkNode AND) (Cons (mkTree (mkNode A) Nil) (Cons (mkTree (mkNode E) Nil) Nil)))) | ||
|
|
||
| ;; rouletteSelect | ||
| (= (exemplar-list0) (ConsOS (mkExemplar (treeA) (mkDemeId "1") (mkCscore 0.9 0.5 0.2 0.1 -0.6) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| (ConsOS (mkExemplar (treeB) (mkDemeId "2") (mkCscore 0.85 0.6 0.1 0.05 0.6) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| (ConsOS (mkExemplar (treeC) (mkDemeId "3") (mkCscore 0.4 0.7 0.05 0.01 0.3) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| NilOS)))) | ||
| !(assertEqual | ||
| (let $choice (rouletteSelect (exemplar-list0) | ||
| (Cons 0.996 (Cons 1.0 (Cons 0.9857 Nil))) 2.9817) | ||
| (OS.contains (exemplar-list0) $choice)) True) | ||
|
|
||
| (= (exemplar-list1) (ConsOS (mkExemplar (treeA) (mkDemeId "9") (mkCscore 0.91 0.3 0.25 0.13 0.3) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| (ConsOS (mkExemplar (treeY) (mkDemeId "10") (mkCscore 0.88 0.4 0.22 0.12 0.4) (mkBscore (Cons 1 (Cons 1 Nil)))) | ||
| (ConsOS (mkExemplar (treeZ) (mkDemeId "11") (mkCscore 0.83 0.5 0.15 0.10 0.5) (mkBscore (Cons 0 (Cons 1 Nil)))) | ||
| NilOS)))) | ||
| !(assertEqual | ||
| (let $choice (rouletteSelect (exemplar-list1) (Cons 0.9753 (Cons 0.9936 (Cons 1.0 Nil))) 2.9689) | ||
| (OS.contains (exemplar-list1) $choice )) True) | ||
|
|
||
| (= (exemplar-list2) (ConsOS (mkExemplar (treeA) (mkDemeId "7") (mkCscore 0.95 0.3 0.2 0.1 0.2) (mkBscore (Cons 1 (Cons 1 Nil)))) | ||
| (ConsOS (mkExemplar (tree2) (mkDemeId "8") (mkCscore 0.80 0.6 0.1 0.05 0.2) (mkBscore (Cons 1 (Cons 1 Nil)))) | ||
| (ConsOS (mkExemplar (tree3) (mkDemeId "12") (mkCscore 0.5 0.9 0.05 0.03 0.1) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| NilOS)))) | ||
|
|
||
| !(assertEqual | ||
| (let $choice (rouletteSelect (exemplar-list2) (Cons 0.9654 (Cons 1.0 (Cons 0.9057 Nil))) 2.8711) | ||
| (OS.contains (exemplar-list2) $choice)) True) | ||
|
|
||
| ;; selectExemplar | ||
| !(assertEqual (selectExemplar NilOS) (Error NilOS "empty metapopulation")) | ||
|
|
||
| (= (treeA-x) (mkExemplar treeA (mkDemeId "7") (mkCscore 0.95 0.3 0.2 0.1 0.4) (mkBscore (Cons 1 (Cons 1 Nil))))) | ||
|
|
||
| !(assertEqual (selectExemplar (ConsOS (treeA-x) NilOS)) (treeA-x)) | ||
|
|
||
| (= (test1-exemplars) | ||
| (ConsOS (mkExemplar (treeA) (mkDemeId "1") (mkCscore 0.8 0.3 0.1 0.01 0.4) (mkBscore (Cons 1 (Cons 1 Nil)))) | ||
| (ConsOS (mkExemplar (tree2) (mkDemeId "2") (mkCscore 0.7 0.4 0.05 0.05 0.5) (mkBscore (Cons 0 (Cons 1 Nil)))) | ||
| (ConsOS (mkExemplar (tree3) (mkDemeId "3") (mkCscore 0.6 0.5 0.0 0.0 0.6) (mkBscore (Cons 1 (Cons 0 Nil)))) | ||
| NilOS)))) | ||
|
|
||
| !(assertEqual (let $choice (selectExemplar (test1-exemplars)) (OS.contains (test1-exemplars) $choice)) True) | ||
|
|
||
| (= (test2-exemplars) | ||
| (ConsOS (mkExemplar (treeA) (mkDemeId "101") (mkCscore 0.9 0.3 0.05 0.02 0.6) | ||
| (mkBscore (Cons 1 (Cons 1 (Cons 1 (Cons 1 Nil)))))) | ||
| (ConsOS (mkExemplar (treeB) (mkDemeId "102") (mkCscore 0.6 0.5 0.1 0.1 0.5) (mkBscore (Cons 1 (Cons 1 (Cons 1 (Cons 1 Nil)))))) | ||
| (ConsOS (mkExemplar (treeC) (mkDemeId "103") (mkCscore 0.4 0.4 0.05 0.1 0.4) (mkBscore (Cons 0 (Cons 0 (Cons 1 (Cons 0 Nil)))))) | ||
| NilOS)))) | ||
| !(assertEqual (let $choice (selectExemplar (test2-exemplars)) (OS.contains (test2-exemplars) $choice)) True) | ||
|
|
||
| (= (metaPop) (ConsOS (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode NOT) (Cons (mkTree (mkNode A) Nil) Nil)) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil))) (mkDemeId "1") (mkCscore -0.2 1 0.1 0.1 5) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| (ConsOS (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil)) (mkDemeId "1") (mkCscore -0.1 2 0.2 0.3 -0.6) (mkBScore (Cons 0 (Cons 0 Nil)))) | ||
| (ConsOS (mkExemplar (mkTree (mkNode OR) (Cons (mkTree (mkNode OR) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode B) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode C) Nil) Nil)) (Cons (mkTree (mkNode AND) (Cons (mkTree (mkNode D) Nil) Nil)) Nil)))) Nil)) (mkDemeId "1") (mkCscore -0.1 2 0.2 0.3 -0.006) (mkBScore (Cons 0 (Cons 0 Nil)))) NilOS)))) | ||
|
|
||
| ; ! (assertEqual (let $choice (selectExemplar metaPop) ((get-type $choice) (OS.contains metaPop $choice))) ((Exemplar Bool) True)) | ||
| !(assertEqual (let $choice (selectExemplar (metaPop)) (OS.contains (metaPop) $choice)) True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
py-atomwork in PeTTa?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doens't. When there is a file import statement PeTTa won't run if there is syntax error in the imported file. So, I was just fixing that. Not looking into the correctness of the python binidings.