Skip to content

Commit

Permalink
DecisionList refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-milella committed Oct 25, 2024
1 parent 7b1d32c commit 110299f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/types/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ and enclose a *tree* of `AbstractModel`s (with `LeafModel`s at the leaves).
- `wrap(m::AbstractModel)`
# Examples
TODO:
TODO
See also [`apply`](@ref), [`Branch`](@ref), [`info`](@ref), [`isopen`](@ref),
[`LeafModel`](@ref), [`outcometype`](@ref), [`Rule`](@ref).
Expand Down
44 changes: 35 additions & 9 deletions src/utils/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ function Base.getindex(
Branch{O}(typeof(a)(children(a)[idxs]), posconsequent(m), negconsequent(m))
end

############################################################################################
############################################################################################
############################################################################################

Expand All @@ -533,6 +534,7 @@ checkantecedent(
) = check(antecedent(m), d, args...; kwargs...)

############################################################################################
################################### DecisionList ###########################################
############################################################################################

"""
Expand All @@ -551,16 +553,14 @@ has the semantics of an IF-ELSEIF-ELSE block:
ELSEIF (antecedent_n) THEN (consequent_n)
ELSE (consequent_default) END
where the antecedents are formulas to be, and the consequents are the feasible
local outcomes of the block.
Using the classical semantics, the antecedents are evaluated in order,
and a consequent is returned as soon as a valid antecedent is found,
or when the computation reaches the ELSE clause.
where the [`antecedent`](@ref)s are formulas to be, and the [`consequent`](@ref)s are the
feasible local outcomes of the block.
See also
[`Rule`](@ref),
[`DecisionTree`](@ref),
[`AbstractModel`](@ref).
Using the classical semantics, the [`antecedent`](@ref)s are evaluated in order, and a
[`consequent`](@ref) is returned as soon as a valid antecedent is found, or when the
computation reaches the ELSE clause.
See also [`AbstractModel`](@ref), [`DecisionTree`](@ref), [`Rule`](@ref).
"""
struct DecisionList{O} <: AbstractModel{O}
rulebase::Vector{Rule{_O} where {_O<:O}}
Expand All @@ -578,7 +578,26 @@ struct DecisionList{O} <: AbstractModel{O}
end
end

"""
rulebase(m::DecisionList)
Getter for the [`Rule`](@ref)s list wrapped within `m`.
See also [`DecisionList`](@ref), [`Rule`](@ref).
"""
rulebase(m::DecisionList) = m.rulebase

"""
defaultconsequent(m::DecisionList)
Return the default [`consequent`](@ref) for any [`Rule`](@ref) wrapped within `m`.
!!! note
If the model returned by this getter is open, then `m` is open too.
See also [`isopen`](@ref).
See also [`AbstractModel`](@ref), [`DecisionList`](@ref), [`Rule`](@ref).
"""
defaultconsequent(m::DecisionList) = m.defaultconsequent

isopen(m::DecisionList) = isopen(defaultconsequent(m))
Expand Down Expand Up @@ -628,9 +647,16 @@ function apply(
end


############################################################################################
################################### DecisionTree ###########################################
############################################################################################

"""
struct DecisionTree{O} <: AbstractModel{O}
root::M where {M<:Union{LeafModel{O},Branch{O}}}
info::NamedTuple
end
A `DecisionTree` is a symbolic model that operates as a nested structure of
IF-THEN-ELSE blocks:
Expand Down

0 comments on commit 110299f

Please sign in to comment.