Reference

Config

Module defining global configs.

Mainly used by the Optimizer class, it defines basic solver parameters, such as tolerance and time limit.

See also

Gurobi tolerances and the limitations of double-precision arithmetic.

config.epsilon = 0.0001

Strict inequality epsilon used for split decisions (defined in the paper). (float)

config.indicator_constraints = True

Flag to implement linear separator constraints as indicator constraints.

config.solver_feas_tol = 1e-07

Gurobi primal feasibility tolerance (Gurobi default: 1e-6). (float)

config.solver_int_tol = 1e-06

Gurobi integer feasibility tolerance (Gurobi default: 1e-5). (float)

config.solver_opt_tol = 1e-07

Gurobi dual feasibility tolerance (Gurobi default: 1e-6). (float)

config.time_limit = 60

Solver time limit (in seconds) (int)

config.verbose = True

Flag to enable verbose output.

Dataset

Topology

class topology.Topology(nonterminal_width_list, data, long_arcs=True, verbose=False)

Collection of structures that define a decision diagram topology.

Instantiation of this class is intended for internal modules only.

Parameters
nonterminal_width_listlist of int

List defining the number of internal layers and their respective width (i.e. node count). The list must start with a 1, representing the root.

dataDataset

Dataset instance.

long_arcsbool, default True

If true, every internal node will be assigned a long arc to all leaves.

verbosebool, default False

Flag to turn on verbose logging.

Attributes
layer_widthslist of int

Lists layers’ widths, including the terminal layer.

long_arcsbool

Indicates if topology has long arcs.

root_nodeint

Index of root node.

layersint

Total number of layers in the topology.

nodeslist of int

List of node indexes.

internal_nodeslist of int

List of internal node indexes.

nodes_per_layerdict of int: list of int

For each layer, lists all of its nodes indexes.

layer_of_nodedict of int: int

Layer index of each node.

has_internal_nodesbool

Indicates whether topology has any internal nodes (other than the root).

node_classdict of int: int

Dictionary where the keys are leaf node indexes and the values are each node’s respective class index.

class_nodedict of int: int

Dictionary where the keys are classes and values are each class’s corresponding leaf node.

arcslist of tuple

List of possible arcs in the topology. Arcs are tuples (s,u,v) where s is a side (+ or -), u is the parent node and v is the child node.

arcs_departing_nodedict of int: list of tuple

For each node, lists all arcs departing it (see arcs attribute description).

pos_arcs_departing_nodedict of int: list of tuple

For each node, lists all positive arcs departing it (see arcs attribute description).

neg_arcs_departing_nodedict of int: list of tuple

For each node, lists all negative arcs departing it (see arcs attribute description).

arcs_arriving_at_nodedict of int: list of tuple

For each node, lists all arcs arriving at it (see arcs attribute description).

Solution

class solution.Solution(data, topology)

Collection of structures that define a built decision diagram.

Instantiation of this class is intended for internal modules only.

Parameters
dataDataset

Dataset instance used to build the decision diagram.

topologyTopology

Topology instance used to build the decision diagram.

Attributes
used_nodesSet

Set of nodes used in the solution.

node_hyperplanedict of int: list of int

Splitting hyperplane of each used node. For univariate splits, the list will have all zeroes, except for the index of the splitting feature.

node_interceptdict of int: float

Intercept of the splitting hyperplane of each used node.

node_positive_arcdict of int: int

For each node, determines the child node its positive arc points to.

node_negative_arcdict of int: int

For each node, determines the child node its negative arc points to.

node_classdict of int: int

Class assigned to each leaf node.

mip_gapfloat

Optimality gap found by an Optimizer instance.

obj_valfloat

Objective value found by an Optimizer instance.

obj_lbfloat

Objective lower bound found by an Optimizer instance.

bb_nodesint

Number of branch-and-cut nodes explored by an Optimizer instance.

Methods

count_class_nodes()

Calculates and returns the number of used leaf nodes.

count_internal_nodes()

Calculates and returns the number of internal nodes.

fragmentation_per_node()

Calculates and returns the proportion of training samples that reaches each used node.

objective_value(alpha, top_internal_nodes)

Calculates and returns the objective value.

print()

Prints a structured description of the decision diagram solution.

test_accuracy()

Calculates and returns the test accuracy.

training_accuracy()

Calculates and returns the training accuracy.

validation_accuracy()

Calculates and returns the validation accuracy.

count_class_nodes()

Calculates and returns the number of used leaf nodes.

count_internal_nodes()

Calculates and returns the number of internal nodes.

fragmentation_per_node()

Calculates and returns the proportion of training samples that reaches each used node.

objective_value(alpha, top_internal_nodes)

Calculates and returns the objective value.

Parameters
alphafloat

Alpha hyperparameter for controlling model complexity.

top_internal_nodesint

Number of possible internal nodes in the diagram’s topology.

Returns
objective_valuefloat

Objective value for the solution instance.

print()

Prints a structured description of the decision diagram solution.

test_accuracy()

Calculates and returns the test accuracy.

training_accuracy()

Calculates and returns the training accuracy.

validation_accuracy()

Calculates and returns the validation accuracy.

Heuristic

class heuristic.Heuristic(data, topology, randomize_splits=False, feature_subset_ratio=0.6, seed=None, alpha=0.0, verbose=False)

Builds a decision diagram using a top-down constructive heuristic with bottom-up pruning.

Parameters
dataDataset

Dataset instance to be used for building the diagram.

topologyTopology

Topology instance to be used for building the diagram.

randomize_splitsbool, default False

If True, each split decision will be made using a randomly selected set of features, according to feature_subset_ratio.

feature_subset_ratiofloat, default 0.6

Ratio of features to be used when randomize_splits=True.

seedint or None, default None

Random seed to be used when randomize_splits=True.

alphafloat, default 0.0

Alpha hyperparameter.

verbosebool, default False

Flag to turn on verbose logging.

Attributes
solutionSolution

The decision diagram Solution instance generated by the heuristic algorithm.

Optimizer

Visualizer