Skip to content

Commit 739870b

Browse files
Merge pull request #102 from aclai-lab/minor-edit-to-manyvalued-module
Minor edit to many-expert-algebras related code
2 parents 47755a3 + aaec1c0 commit 739870b

File tree

5 files changed

+171
-10
lines changed

5 files changed

+171
-10
lines changed

src/many-valued-logics/check.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ function SoleLogics.collatetruth(
222222
ntuple(i -> SoleLogics.collatetruth(, (x[i], y[i]), a.experts[i]), M)
223223
end
224224

225+
function SoleLogics.check(
226+
φ::SyntaxTree,
227+
i::Interpretation,
228+
a::ManyExpertAlgebra,
229+
args...;
230+
kwargs...)
231+
232+
interpret(φ, i, a, args...; kwargs...)
233+
end
234+
225235
"""
226236
alphacheck(
227237
α::FiniteTruth,

src/many-valued-logics/fuzzylogics.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ struct FuzzyLogic{T} <: AbstractAlgebra{ContinuousTruth}
1313
end
1414

1515
function Base.show(io::IO, a::FuzzyLogic)
16-
println(string(typeof(a)))
17-
println("t-norm: " * string(a.tnorm.func))
16+
tnorm_name = if a.tnorm === GodelTNorm
17+
"Gödel (min)"
18+
elseif a.tnorm === LukasiewiczTNorm
19+
"Łukasiewicz"
20+
elseif a.tnorm === ProductTNorm
21+
"Product (*)"
22+
else
23+
string(a.tnorm.func)
24+
end
25+
print(io, "FuzzyLogic(t-norm: ", tnorm_name, ")")
1826
end
1927

2028
iscrisp(::FuzzyLogic) = false

src/many-valued-logics/many-expert-algebras.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ..SoleLogics: AbstractAlgebra, top, bot, iscrisp
22
using StaticArrays
33

44
"""
5-
struct ManyExpertAlgebra{N, A <: SVector{N, FuzzyLogic}} <: AbstractAlgebra{ContinuousTruth}
5+
struct ManyExpertAlgebra <: AbstractAlgebra{ContinuousTruth}
66
experts::A
77
end
88
A Many Expert Algebra is a combination of N continuous fuzzy logics, each potentially
@@ -21,8 +21,12 @@ struct ManyExpertAlgebra <: AbstractAlgebra{ContinuousTruth}
2121
end
2222

2323
function Base.show(io::IO, a::ManyExpertAlgebra)
24-
println(typeof(a))
25-
for expert in a.experts print(expert) end
24+
n = length(a.experts)
25+
print(io, "ManyExpertAlgebra with ", n, " expert", n == 1 ? "" : "s", ":")
26+
for (i, expert) in enumerate(a.experts)
27+
print(io, "\n [", i, "] ")
28+
show(io, expert)
29+
end
2630
end
2731

2832
function addexperts!(a::ManyExpertAlgebra, experts::FuzzyLogic...)

src/many-valued-logics/order-utilities.jl

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ end
4747
T1<:Truth,
4848
T2<:Truth
4949
}
50-
Return true if `t1` < `t2` in fuzzy logic `l`. For continuous truth values,
50+
51+
Return true if `t1` ≤ `t2` in fuzzy logic `l`. For continuous truth values,
5152
this is the standard strict less-than ordering on real numbers in [0,1].
5253
5354
See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
@@ -65,6 +66,37 @@ See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
6566
return t1.value <= t2.value ? true : false
6667
end
6768

69+
"""
70+
function precedeq(
71+
l::ManyExpertAlgebra,
72+
t1::NTuple{N, T1},
73+
t2::NTuple{N, T2}
74+
) where {
75+
T1 <: Truth,
76+
T2 <: Truth,
77+
N
78+
}
79+
80+
Return true if each truth in the tuple `t1` ≤ `t2` in a many expert algebra. For continuous
81+
truth values, this is the standard strict less-than ordering on real numbers in [0,1].
82+
83+
See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
84+
"""
85+
function precedeq(
86+
l::ManyExpertAlgebra,
87+
t1::NTuple{N, T1},
88+
t2::NTuple{N, T2}
89+
) where {
90+
T1 <: Truth,
91+
T2 <: Truth,
92+
N
93+
}
94+
for i in 1:N
95+
if !precedeq(l.experts[i], t1[i], t2[i]) return false end
96+
end
97+
return true
98+
end
99+
68100
"""
69101
function precedes(
70102
l::L,
@@ -127,6 +159,38 @@ See also [`precedeq`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
127159
return t1.value < t2.value ? true : false
128160
end
129161

162+
"""
163+
function precedes(
164+
l::ManyExpertAlgebra,
165+
t1::NTuple{N, T1},
166+
t2::NTuple{N, T2}
167+
) where {
168+
T1 <: Truth,
169+
T2 <: Truth,
170+
N
171+
}
172+
173+
Return true if each truth in the tuple `t1` < `t2` in a many expert algebra. For continuous
174+
truth values, this is the standard strict less-than ordering on real numbers in [0,1].
175+
176+
See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
177+
"""
178+
179+
function precedes(
180+
l::ManyExpertAlgebra,
181+
t1::NTuple{N, T1},
182+
t2::NTuple{N, T2}
183+
) where {
184+
T1 <: Truth,
185+
T2 <: Truth,
186+
N
187+
}
188+
for i in 1:N
189+
if !precedes(l.experts[i], t1[i], t2[i]) return false end
190+
end
191+
return true
192+
end
193+
130194
"""
131195
function succeedeq(
132196
l::L,
@@ -189,6 +253,38 @@ See also [`precedes`](@ref), [`precedeq`](@ref), [`succeedes`](@ref).
189253
return t1.value >= t2.value ? true : false
190254
end
191255

256+
"""
257+
function succedeq(
258+
l::ManyExpertAlgebra,
259+
t1::NTuple{N, T1},
260+
t2::NTuple{N, T2}
261+
) where {
262+
T1 <: Truth,
263+
T2 <: Truth,
264+
N
265+
}
266+
267+
Return true if each truth in the tuple `t1` ≥ `t2` in a many expert algebra. For continuous
268+
truth values, this is the standard strict less-than ordering on real numbers in [0,1].
269+
270+
See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
271+
"""
272+
273+
function succeedeq(
274+
l::ManyExpertAlgebra,
275+
t1::NTuple{N, T1},
276+
t2::NTuple{N, T2}
277+
) where {
278+
T1 <: Truth,
279+
T2 <: Truth,
280+
N
281+
}
282+
for i in 1:N
283+
if !succeedeq(l.experts[i], t1[i], t2[i]) return false end
284+
end
285+
return true
286+
end
287+
192288
"""
193289
function succeedes(
194290
l::L,
@@ -251,6 +347,38 @@ See also [`precedes`](@ref), [`precedeq`](@ref), [`succeedeq`](@ref).
251347
return t1.value > t2.value ? true : false
252348
end
253349

350+
"""
351+
function succedes(
352+
l::ManyExpertAlgebra,
353+
t1::NTuple{N, T1},
354+
t2::NTuple{N, T2}
355+
) where {
356+
T1 <: Truth,
357+
T2 <: Truth,
358+
N
359+
}
360+
361+
Return true if each truth in the tuple `t1` > `t2` in a many expert algebra. For continuous
362+
truth values, this is the standard strict less-than ordering on real numbers in [0,1].
363+
364+
See also [`precedes`](@ref), [`succeedes`](@ref), [`succeedeq`](@ref).
365+
"""
366+
367+
function succeedes(
368+
l::ManyExpertAlgebra,
369+
t1::NTuple{N, T1},
370+
t2::NTuple{N, T2}
371+
) where {
372+
T1 <: Truth,
373+
T2 <: Truth,
374+
N
375+
}
376+
for i in 1:N
377+
if !succeedes(l.experts[i], t1[i], t2[i]) return false end
378+
end
379+
return true
380+
end
381+
254382
"""
255383
function lesservalues(
256384
l::L,

test/many-valued-logics.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,22 @@ FuzzyLogic(GodelTNorm)
164164
MXA = ManyExpertAlgebra(GodelLogic)
165165
addexperts!(MXA, LukasiewiczLogic, ProductLogic)
166166

167+
@test occursin("Gödel", sprint(show, MXA))
168+
@test occursin("Łukasiewicz", sprint(show, MXA))
169+
@test occursin("Product", sprint(show, MXA))
170+
171+
@test occursin("+", sprint(show, FuzzyLogic(ContinuousBinaryOperation(+))))
172+
167173
@test iscrisp(MXA) == false
168174

169175
@test top(MXA) == ntuple(i -> top(MXA.experts[i]), 3)
170176
@test bot(MXA) == ntuple(i -> bot(MXA.experts[i]), 3)
171177

178+
@test precedeq(MXA, (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)), (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)))
179+
@test precedes(MXA, (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)), (ContinuousTruth(1.0), ContinuousTruth(1.0), ContinuousTruth(0.7)))
180+
@test succeedeq(MXA, (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)), (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)))
181+
@test succeedes(MXA, (ContinuousTruth(1.0), ContinuousTruth(1.0), ContinuousTruth(0.7)), (ContinuousTruth(0.0), ContinuousTruth(0.0), ContinuousTruth(0.5)))
182+
172183

173184
################################################################################
174185
#### Nine-valued algebra (Heyting case) ########################################
@@ -274,15 +285,15 @@ z = Atom("z")
274285
################################################################################
275286

276287
@test interpret(parseformula("v∧w"), TruthDict([v => ⊤, w => ⊤]), MXA) == top(MXA)
277-
@test interpret(parseformula("v∨w"), TruthDict([v => ⊥, w => ⊥]), MXA) == bot(MXA)
278-
@test interpret(parseformula("v∧w"), TruthDict([v => ⊥, w => ⊤]), MXA) == bot(MXA)
288+
@test check(parseformula("v∨w"), TruthDict([v => ⊥, w => ⊥]), MXA) == bot(MXA)
289+
@test check(parseformula("v∧w"), TruthDict([v => ⊥, w => ⊤]), MXA) == bot(MXA)
279290
@test interpret(parseformula("v∨w"), TruthDict([v => ⊤, w => ⊥]), MXA) == top(MXA)
280291
@test top(MXA) == interpret(parseformula("v∨w"), TruthDict([v => ContinuousTruth(0), w => ⊤]), MXA)
281292
@test bot(MXA) == interpret(parseformula("(v∧w∧x)∨(y∧z)"), TruthDict([v => ⊥, w => ContinuousTruth(0.5), x => ContinuousTruth(0.0), y => ⊥, z => ContinuousTruth(0.4)]), MXA)
282293
@test top(MXA) == interpret(parseformula("v→w"), TruthDict([v => ⊥, w => ⊤]), MXA)
283-
@test interpret(parseformula("(v→w)∧(w→v)"), TruthDict([v => ContinuousTruth(0.3), w => ContinuousTruth(0.6)]), MXA) == (ContinuousTruth(0.3), ContinuousTruth(0.7), ContinuousTruth(0.5))
294+
@test check(parseformula("(v→w)∧(w→v)"), TruthDict([v => ContinuousTruth(0.3), w => ContinuousTruth(0.6)]), MXA) == (ContinuousTruth(0.3), ContinuousTruth(0.7), ContinuousTruth(0.5))
284295
@test interpret(parseformula("((v→w)∨(w→x))∧(v∨x)"), TruthDict([v => ContinuousTruth(0.7), w => ContinuousTruth(0.2), x => ContinuousTruth(0.5)]), MXA) == (ContinuousTruth(0.7), ContinuousTruth(0.7), ContinuousTruth(0.7))
285-
@test interpret(parseformula("(v∧(w∨x))→(y∨z)"), TruthDict([v => ContinuousTruth(0.6), w => ContinuousTruth(0.4), x => ContinuousTruth(0.9), y => ContinuousTruth(0.3), z => ContinuousTruth(0.8)]), MXA) == (ContinuousTruth(1.0), ContinuousTruth(1.0), ContinuousTruth(1.0))
296+
@test check(parseformula("(v∧(w∨x))→(y∨z)"), TruthDict([v => ContinuousTruth(0.6), w => ContinuousTruth(0.4), x => ContinuousTruth(0.9), y => ContinuousTruth(0.3), z => ContinuousTruth(0.8)]), MXA) == (ContinuousTruth(1.0), ContinuousTruth(1.0), ContinuousTruth(1.0))
286297

287298
################################################################################
288299
#### Finite FLew-chains generation #############################################

0 commit comments

Comments
 (0)