forked from drspro/metta-wam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeductionFormula.metta
executable file
·54 lines (48 loc) · 2 KB
/
DeductionFormula.metta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;; Formula and other functions used for the deduction rule
;; Import modules
!(import! &self ../truthvalue/TruthValue.metta)
!(import! &self ../Num.metta)
; Consistency Conditions
(: smallest-intersection-probability (-> Number Number Number))
(= (smallest-intersection-probability $As $Bs)
(clamp (/ (- (+ $As $Bs) 1) $As) 0 1))
(: largest-intersection-probability (-> Number Number Number))
(= (largest-intersection-probability $As $Bs)
(clamp (/ $Bs $As) 0 1))
(: conditional-probability-consistency (-> Number Number Number Bool))
(= (conditional-probability-consistency $As $Bs $ABs)
(and (< 0 $As)
(and (<= (smallest-intersection-probability $As $Bs) $ABs)
(<= $ABs (largest-intersection-probability $As $Bs)))))
;; Main Formula
(: simple-deduction-strength-formula (-> Number Number Number Number Number Number))
(= (simple-deduction-strength-formula $As $Bs $Cs $ABs $BCs)
(if
(and
(conditional-probability-consistency $As $Bs $ABs)
(conditional-probability-consistency $Bs $Cs $BCs))
;; Preconditions are met
(if (< 0.99 $Bs)
;; sB tends to 1
$Cs
;; otherwise
(+ (* $ABs $BCs) (/ (* (- 1 $ABs) (- $Cs (* $Bs $BCs))) (- 1 $Bs))))
;; Preconditions are not met
0))
;; Alternate deduction formula hardwired for STV to make it faster.
(= (deduction-formula (STV $Ps $Pc)
(STV $Qs $Qc)
(STV $Rs $Rc)
(STV $PQs $PQc)
(STV $QRs $QRc))
(if (and (conditional-probability-consistency $Ps $Qs $PQs)
(conditional-probability-consistency $Qs $Rs $QRs))
;; Preconditions are met
(STV (if (< 0.9999 $Qs) ; avoid division by 0
;; Qs tends to 1
$Rs
;; Otherwise
(+ (* $PQs $QRs) (/ (* (- 1 $PQs) (- $Rs (* $Qs $QRs))) (- 1 $Qs))))
(min $Pc (min $Qc (min $Rc (min $PQc $QRc)))))
;; Preconditions are not met
(STV 1 0)))