-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtruth-value.maude
More file actions
161 lines (129 loc) · 5.92 KB
/
Copy pathtruth-value.maude
File metadata and controls
161 lines (129 loc) · 5.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
***( ================================================================
*** OpenCog in Pure Maude — OC-TRUTH-VALUE Module
***
*** Implements the probabilistic truth value system used throughout
*** OpenCog. A TruthValue is a pair (strength, confidence) where:
*** - strength ∈ [0,1] represents the probability/degree of truth
*** - confidence ∈ [0,1] represents the certainty of the strength
***
*** Based on: Goertzel et al., "Probabilistic Logic Networks"
*** ================================================================ )
fmod OC-TRUTH-VALUE is
protecting FLOAT .
protecting BOOL .
*** ---------------------------------------------------------------
*** Sort hierarchy for truth values
*** ---------------------------------------------------------------
sorts SimpleTruthValue CountTruthValue IndefiniteTruthValue OcTruthValue .
subsort SimpleTruthValue CountTruthValue IndefiniteTruthValue < OcTruthValue .
*** ---------------------------------------------------------------
*** Constructors
*** ---------------------------------------------------------------
*** Simple truth value: (strength, confidence)
op stv : Float Float -> SimpleTruthValue [ctor] .
*** Count truth value: (strength, confidence, count)
op ctv : Float Float Float -> CountTruthValue [ctor] .
*** Indefinite truth value: (lower, upper, confidence)
op itv : Float Float Float -> IndefiniteTruthValue [ctor] .
*** Default / null truth value
op nullTV : -> OcTruthValue [ctor] .
op defaultTV : -> SimpleTruthValue .
*** ---------------------------------------------------------------
*** Accessors
*** ---------------------------------------------------------------
op tvStrength : OcTruthValue -> Float .
op tvConfidence : OcTruthValue -> Float .
op tvCount : OcTruthValue -> Float .
*** ---------------------------------------------------------------
*** Truth value arithmetic (used by PLN formulas)
*** ---------------------------------------------------------------
op tvRevision : OcTruthValue OcTruthValue -> OcTruthValue .
op tvNegate : OcTruthValue -> OcTruthValue .
op tvAnd : OcTruthValue OcTruthValue -> OcTruthValue .
op tvOr : OcTruthValue OcTruthValue -> OcTruthValue .
*** Confidence-to-count conversion constant (default k = 800.0)
op kConst : -> Float .
*** Utility: clamp to [0,1]
op clamp01 : Float -> Float .
*** Utility: count-to-confidence and confidence-to-count
op countToConf : Float -> Float .
op confToCount : Float -> Float .
*** ---------------------------------------------------------------
*** Variables
*** ---------------------------------------------------------------
vars S S1 S2 C C1 C2 N N1 N2 L U : Float .
vars TV1X TV2X : OcTruthValue .
*** ---------------------------------------------------------------
*** Equations
*** ---------------------------------------------------------------
eq defaultTV = stv(1.0, 0.0) .
*** Accessors for SimpleTruthValue
eq tvStrength(stv(S, C)) = S .
eq tvConfidence(stv(S, C)) = C .
eq tvCount(stv(S, C)) = confToCount(C) .
*** Accessors for CountTruthValue
eq tvStrength(ctv(S, C, N)) = S .
eq tvConfidence(ctv(S, C, N)) = C .
eq tvCount(ctv(S, C, N)) = N .
*** Accessors for IndefiniteTruthValue
eq tvStrength(itv(L, U, C)) = (L + U) / 2.0 .
eq tvConfidence(itv(L, U, C)) = C .
eq tvCount(itv(L, U, C)) = confToCount(C) .
*** Null truth value accessors
eq tvStrength(nullTV) = 0.0 .
eq tvConfidence(nullTV) = 0.0 .
eq tvCount(nullTV) = 0.0 .
*** The confidence-count conversion constant
eq kConst = 800.0 .
*** Clamp a float to [0, 1]
eq clamp01(S) = if S < 0.0 then 0.0
else (if S > 1.0 then 1.0 else S fi) fi .
*** Count ↔ Confidence conversions
eq countToConf(N) = if N < 0.0 then 0.0
else N / (N + kConst) fi .
eq confToCount(C) = if C >= 1.0 then 1.0e10
else (if C <= 0.0 then 0.0
else kConst * C / (1.0 - C) fi) fi .
*** PLN Revision Rule
ceq tvRevision(stv(S1, C1), stv(S2, C2)) =
stv(clamp01(
if N1 + N2 > 0.0
then (S1 * N1 + S2 * N2) / (N1 + N2)
else 0.0 fi),
clamp01(countToConf(N1 + N2)))
if N1 := confToCount(C1) /\
N2 := confToCount(C2) .
*** Negation
eq tvNegate(stv(S, C)) = stv(clamp01(1.0 - S), C) .
eq tvNegate(nullTV) = nullTV .
*** Conjunction (independent assumption): s_and = s1 * s2
eq tvAnd(stv(S1, C1), stv(S2, C2)) =
stv(clamp01(S1 * S2), clamp01(min(C1, C2))) .
*** Disjunction (independent assumption): s_or = 1 - (1-s1)(1-s2)
eq tvOr(stv(S1, C1), stv(S2, C2)) =
stv(clamp01(1.0 - (1.0 - S1) * (1.0 - S2)), clamp01(min(C1, C2))) .
*** [Phase 1.1] Extended truth value arithmetic for ctv and itv.
*** tvNegate for CountTruthValue (preserves count)
eq tvNegate(ctv(S, C, N)) = ctv(clamp01(1.0 - S), C, N) .
*** tvNegate for IndefiniteTruthValue (flips interval)
eq tvNegate(itv(L, U, C)) = itv(clamp01(1.0 - U), clamp01(1.0 - L), C) .
*** [Phase 1.1] tvRevision for CountTruthValue: use counts directly
ceq tvRevision(ctv(S1, C1, N1), ctv(S2, C2, N2)) =
stv(clamp01(
if N1 + N2 > 0.0
then (S1 * N1 + S2 * N2) / (N1 + N2)
else 0.0 fi),
clamp01(countToConf(N1 + N2)))
if true .
*** [Phase 1.1] General tvRevision / tvAnd / tvOr for mixed or itv types:
*** project to (strength, confidence) and use the stv formula
eq tvRevision(TV1X, TV2X) =
tvRevision(stv(tvStrength(TV1X), tvConfidence(TV1X)),
stv(tvStrength(TV2X), tvConfidence(TV2X))) [owise] .
eq tvAnd(TV1X, TV2X) =
stv(clamp01(tvStrength(TV1X) * tvStrength(TV2X)),
clamp01(min(tvConfidence(TV1X), tvConfidence(TV2X)))) [owise] .
eq tvOr(TV1X, TV2X) =
stv(clamp01(1.0 - (1.0 - tvStrength(TV1X)) * (1.0 - tvStrength(TV2X))),
clamp01(min(tvConfidence(TV1X), tvConfidence(TV2X)))) [owise] .
endfm