Skip to content

Commit

Permalink
fixing evaluation functions, adding dispatch to already existing func…
Browse files Browse the repository at this point in the history
…tion as npropositions, check and creating new function conjunctiveformulas
  • Loading branch information
Michele21 committed Aug 17, 2023
1 parent f564d91 commit 7b5c18f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
55 changes: 55 additions & 0 deletions src/logisets/multilogiset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ function SoleLogics.normalize(φ::MultiFormula{F}; kwargs...) where {F<:Abstract
MultiFormula(Dict{Int,F}([i_modality => SoleLogics.normalize(f; kwargs...) for (i_modality,f) in pairs(modforms(φ))]))
end

function conjunctiveformulas(children::NTuple{N,MultiFormula}) where {N}
@assert N > 0 "Nothing in tuple passed, there must be at least one element"

if N == 1
return first(children)
end

return joinformulas(,(children[1],conjunctiveformulas(children[2:end])))
end

npropositions::LeftmostConjunctiveForm{<:MultiFormula}) = npropositions(children(φ))
npropositions::MultiFormula{<:SyntaxTree}) = npropositions((φ,))
function npropositions(children::NTuple{N,MultiFormula}) where {N}
i_modalities = unique(vcat(collect.(keys.([modforms(ch) for ch in children]))...))

return sum([begin
chs = filter(ch->haskey(modforms(ch), i_modality), children)
fs = map(ch->modforms(ch)[i_modality], chs)
npropositions.(fs)
end for i_modality in i_modalities])
end

function check(
φ::MultiFormula,
X::MultiLogiset,
Expand All @@ -292,6 +314,39 @@ function check(
for (i_modality, f) in modforms(φ)])
end

function check(
φ::MultiFormula,
d::AbstractInterpretationSet{M},
args...;
kwargs...,
)::Vector{truthtype(M)} where {M<:AbstractInterpretation}
X = MultiLogiset(d)
map(i_instance->check(
φ,
X,
i_instance,
args...;
kwargs...
), 1:ninstances(d))
end

# # TODO join MultiFormula leads to a SyntaxTree with MultiFormula children
# function joinformulas(op::AbstractOperator, children::NTuple{N,MultiFormula{F}}) where {N,F}
# end

function check(
φ::LeftmostConjunctiveForm{<:MultiFormula},
X::AbstractInterpretationSet{<:AbstractKripkeStructure},
i_instance::Integer,
args...;
kwargs...
)
λ = conjunctiveformulas((children(φ)...,))
check(λ, MultiLogiset(X), i_instance, args...; kwargs...)
end

function npropositions(
φ::LeftmostConjunctiveForm{<:MultiFormula},
)

end
2 changes: 1 addition & 1 deletion src/models/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Base: convert, length, getindex, isopen

using SoleData: slicedataset

import SoleLogics: check, syntaxstring
import SoleLogics: check, syntaxstring, conjuncts, nconjuncts, disjuncts, ndisjuncts
using SoleLogics: LeftmostLinearForm, LeftmostConjunctiveForm, LeftmostDisjunctiveForm
using SoleModels: TopFormula

Expand Down
8 changes: 5 additions & 3 deletions src/models/evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ See also
function evaluaterule(
rule::Rule{O,A,FM},
X::AbstractInterpretationSet,
Y::AbstractVector{<:Label}
Y::AbstractVector{<:Label};
kwargs...,
) where {O,A,FM<:AbstractModel}
ys = apply(rule,X)

Expand Down Expand Up @@ -143,9 +144,10 @@ See also
function rulemetrics(
rule::Rule{O,A,FM},
X::AbstractInterpretationSet,
Y::AbstractVector{<:Label}
Y::AbstractVector{<:Label};
kwargs...,
) where {O,A,FM<:AbstractModel}
eval_result = evaluaterule(rule, X, Y)
eval_result = evaluaterule(rule, X, Y; kwargs...)
ys = eval_result[:ys]
antsat = eval_result[:antsat]
n_instances = ninstances(X)
Expand Down

0 comments on commit 7b5c18f

Please sign in to comment.