From 110299f27dc29ce026883ad55c6f6bc3e8c786a8 Mon Sep 17 00:00:00 2001 From: mauro-milella Date: Fri, 25 Oct 2024 18:34:45 +0200 Subject: [PATCH] DecisionList refactoring --- src/types/base.jl | 2 +- src/utils/base.jl | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/types/base.jl b/src/types/base.jl index 4cf58f6..6dcebb2 100644 --- a/src/types/base.jl +++ b/src/types/base.jl @@ -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). diff --git a/src/utils/base.jl b/src/utils/base.jl index 7298f58..d904c3c 100644 --- a/src/utils/base.jl +++ b/src/utils/base.jl @@ -509,6 +509,7 @@ function Base.getindex( Branch{O}(typeof(a)(children(a)[idxs]), posconsequent(m), negconsequent(m)) end +############################################################################################ ############################################################################################ ############################################################################################ @@ -533,6 +534,7 @@ checkantecedent( ) = check(antecedent(m), d, args...; kwargs...) ############################################################################################ +################################### DecisionList ########################################### ############################################################################################ """ @@ -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}} @@ -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)) @@ -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: