Last active
March 3, 2026 01:59
-
-
Save Habush/7e5ac6a8fe3bb5b6250d1aef0b432740 to your computer and use it in GitHub Desktop.
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
| !(import! &self (library lib_spaces)) | |
| !(import! &self (library lib_patrick)) | |
| !(import! &self (library lib_pln)) | |
| !(import! &self (library lib_import)) | |
| !(import_prolog_function string_concat) | |
| ; 1. PLN IMPLICATION TO CLAUSE COMPILATION EXTENSION: | |
| (: => (-> Expression Expression Atom Atom)) | |
| (= (=> (cons , $args) $C $stvImp) | |
| (progn (add-atom &self (= $C (Truth_ModusPonens (foldl-atom $args (stv 1.0 1.0) Truth_ModusPonens) $stvImp))))) | |
| ; 2. Independent OR Truth Function (Noisy-OR) for ProbLog semantics | |
| (= (Truth_NoisyOr (stv $f1 $c1) (stv $f2 $c2)) | |
| (stv (- (+ $f1 $f2) (* $f1 $f2)) (min 1.0 (max $c1 $c2)))) | |
| ; 3. AND-NOT FN: P(A) * (1 - P(B)) | |
| (= (Truth_AndNot (stv $f1 $c1) (stv $f2 $c2)) | |
| (stv (* $f1 (- 1.0 $f2)) (min 1.0 (max 0 (- (+ $c1 $c2) (* $c1 $c2)))))) ;not so sure abt the confidence calculation | |
| ; 3. QUERY FN FOR NOISY-OR | |
| (: ?noisy-or (-> Expression Atom)) | |
| (= (?noisy-or $term) | |
| (unique-atom (collapse ($term (progn (reduce $term) | |
| (foldl-atom (collapse (reduce $term)) (stv 0.0 0.0) Truth_NoisyOr)))))) | |
| (= (get-stv (($term $stv))) $stv) | |
| (= (get-stv ()) (stv 0.0 0.0)) | |
| ; --- KNOWLEDGE BASE --- | |
| ; evidence(c1,true). evidence(c2,true). | |
| !(add-atom &self (= (c1) (stv 1.0 0.6))) | |
| !(add-atom &self (= (c2) (stv 1.0 0.4))) | |
| ; --- RULES FOR e1 --- | |
| ; 0.3::e1 :- c1. | |
| !(=> (, (c1)) (e1_pos) (stv 0.3 0.9)) | |
| ; 0.2::\+e1 :- c2. | |
| !(=> (, (c2)) (e1_neg) (stv 0.2 0.9)) | |
| ; --- RULES FOR e2 --- | |
| ; 0.4::e2 :- c2. | |
| !(=> (, (c2)) (e2_pos) (stv 0.4 0.9)) | |
| ; 0.2::\+e2 :- c1. | |
| !(=> (, (c1)) (e2_neg) (stv 0.2 0.9)) | |
| ; positive causes AND NOT negative causes | |
| !(add-atom &self (= (e1) (Truth_AndNot (get-stv (?noisy-or (e1_pos))) (get-stv (?noisy-or (e1_neg)))))) | |
| !(add-atom &self (= (e2) (Truth_AndNot (get-stv (?noisy-or (e2_pos))) (get-stv (?noisy-or (e2_neg)))))) | |
| ; e :- e1. | |
| ; e :- e2. | |
| !(=> (, (e1)) (e) (stv 1.0 1.0)) | |
| !(=> (, (e2)) (e) (stv 1.0 1.0)) | |
| ; --- QUERY --- | |
| !(?noisy-or (e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment