Skip to main content

dtrees_rs/algorithms/optimal/dl85/
config.rs

1use crate::algorithms::common::config::BaseSearchConfig;
2use crate::algorithms::common::types::{
3    BranchingPolicy, LowerBoundPolicy, NodeDataType, OptimalDepth2Policy,
4};
5use serde::{Deserialize, Serialize};
6
7/// Settings of a [`DL85`](super::DL85) search. Set them through
8/// [`DL85Builder`](super::DL85Builder).
9#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
10pub struct DL85Config {
11    pub(crate) base: BaseSearchConfig,
12    /// Sort the features by the heuristic at every node, not only at the root.
13    pub(crate) always_sort: bool,
14    pub(crate) optimal_depth2policy: OptimalDepth2Policy,
15    pub(crate) lower_bound_policy: LowerBoundPolicy,
16    pub(crate) branching_policy: BranchingPolicy,
17    pub(crate) data_type: NodeDataType,
18}
19
20impl Default for DL85Config {
21    fn default() -> Self {
22        Self {
23            base: BaseSearchConfig::default(),
24            always_sort: false,
25            optimal_depth2policy: OptimalDepth2Policy::Disabled,
26            lower_bound_policy: LowerBoundPolicy::Disabled,
27            data_type: NodeDataType::ClassesSupport,
28            branching_policy: BranchingPolicy::Default,
29        }
30    }
31}
32
33impl DL85Config {
34    /// Whether nodes two levels from the bottom use the depth-2 solver.
35    ///
36    /// The solver works from class counts, so it is skipped when the error
37    /// function takes row indices ([`NodeDataType::Tids`]).
38    pub fn use_depth2_optimization(&self) -> bool {
39        self.optimal_depth2policy == OptimalDepth2Policy::Enabled
40            && self.data_type == NodeDataType::ClassesSupport
41    }
42
43    /// Whether the branch with the higher lower bound is searched first.
44    pub fn use_dynamic_branching(&self) -> bool {
45        self.branching_policy == BranchingPolicy::Dynamic
46    }
47
48    /// Whether the similarity lower bound is used.
49    pub fn use_similarity_lb(&self) -> bool {
50        self.lower_bound_policy == LowerBoundPolicy::Similarity
51    }
52}