Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
gtsam::DecisionTree< L, Y >::Choice< L, Y > Struct Template Reference

#include <DecisionTree-inl.h>

Inheritance diagram for gtsam::DecisionTree< L, Y >::Choice< L, Y >:
Inheritance graph
[legend]

Public Member Functions

NodePtr apply (const Unary &op) const override
 apply unary operator. More...
 
NodePtr apply (const UnaryAssignment &op, const Assignment< L > &assignment) const override
 Apply unary operator with assignment. More...
 
NodePtr apply_f_op_g (const Node &g, const Binary &op) const override
 
template<typename OP >
NodePtr apply_fC_op_gL (const Leaf &gL, OP op) const
 
NodePtr apply_g_op_fC (const Choice &fC, const Binary &op) const override
 
NodePtr apply_g_op_fL (const Leaf &fL, const Binary &op) const override
 
std::vector< NodePtr > & branches ()
 
const std::vector< NodePtr > & branches () const
 
 Choice ()
 Default constructor for serialization. More...
 
 Choice (const Choice &f, const Choice &g, const Binary &op)
 Construct from applying binary op to two Choice nodes. More...
 
 Choice (const L &label, const Choice &f, const Unary &op)
 Construct from applying unary op to a Choice node. More...
 
 Choice (const L &label, const Choice &f, const UnaryAssignment &op, const Assignment< L > &assignment)
 Constructor which accepts a UnaryAssignment op and the corresponding assignment. More...
 
 Choice (const L &label, size_t count)
 Constructor, given choice label and mandatory expected branch count. More...
 
NodePtr choose (const L &label, size_t index) const override
 
void dot (std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero) const override
 
bool equals (const Node &q, const CompareFunc &compare) const override
 equality More...
 
bool isLeaf () const override
 
const Llabel () const
 Return the label of this choice node. More...
 
size_t nrChoices () const
 
const Yoperator() (const Assignment< L > &x) const override
 evaluate More...
 
void print (const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const override
 print (as a tree). More...
 
void push_back (NodePtr &&node)
 
bool sameLeaf (const Leaf &q) const override
 Choice-Leaf equality: always false. More...
 
bool sameLeaf (const Node &q) const override
 polymorphic equality: if q is a leaf, could be... More...
 
 ~Choice () override
 
- Public Member Functions inherited from gtsam::DecisionTree< L, Y >::Node
const void * id () const
 
 Node ()
 
virtual ~Node ()
 

Static Public Member Functions

static NodePtr Unique (const NodePtr &node)
 Merge branches with equal leaf values for every choice node in a decision tree. If all branches are the same (i.e. have the same leaf value), replace the choice node with the equivalent leaf node. More...
 

Public Attributes

std::vector< NodePtrbranches_
 
L label_
 

Private Types

using Base = DecisionTree< L, Y >::Node
 
using ChoicePtr = std::shared_ptr< const Choice >
 

Private Attributes

size_t allSame_
 

Additional Inherited Members

- Public Types inherited from gtsam::DecisionTree< L, Y >::Node
using Ptr = std::shared_ptr< Node >
 

Detailed Description

template<typename L, typename Y>
template<typename L, typename Y>
struct gtsam::DecisionTree< L, Y >::Choice< L, Y >

Definition at line 162 of file DecisionTree-inl.h.

Member Typedef Documentation

◆ Base

template<typename L , typename Y >
template<typename L , typename Y >
using gtsam::DecisionTree< L, Y >::Choice< L, Y >::Base = DecisionTree<L, Y>::Node
private

Definition at line 472 of file DecisionTree-inl.h.

◆ ChoicePtr

template<typename L , typename Y >
template<typename L , typename Y >
using gtsam::DecisionTree< L, Y >::Choice< L, Y >::ChoicePtr = std::shared_ptr<const Choice>
private

Definition at line 176 of file DecisionTree-inl.h.

Constructor & Destructor Documentation

◆ Choice() [1/5]

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::Choice ( )
inline

Default constructor for serialization.

Definition at line 180 of file DecisionTree-inl.h.

◆ ~Choice()

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::~Choice ( )
inlineoverride

Definition at line 182 of file DecisionTree-inl.h.

◆ Choice() [2/5]

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::Choice ( const L label,
size_t  count 
)
inline

Constructor, given choice label and mandatory expected branch count.

Definition at line 238 of file DecisionTree-inl.h.

◆ Choice() [3/5]

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::Choice ( const Choice< L, Y > &  f,
const Choice< L, Y > &  g,
const Binary op 
)
inline

Construct from applying binary op to two Choice nodes.

Definition at line 244 of file DecisionTree-inl.h.

◆ Choice() [4/5]

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::Choice ( const L label,
const Choice< L, Y > &  f,
const Unary op 
)
inline

Construct from applying unary op to a Choice node.

Definition at line 376 of file DecisionTree-inl.h.

◆ Choice() [5/5]

template<typename L , typename Y >
template<typename L , typename Y >
gtsam::DecisionTree< L, Y >::Choice< L, Y >::Choice ( const L label,
const Choice< L, Y > &  f,
const UnaryAssignment op,
const Assignment< L > &  assignment 
)
inline

Constructor which accepts a UnaryAssignment op and the corresponding assignment.

Parameters
labelThe label for this node.
fThe original choice node to apply the op on.
opFunction to apply on the choice node. Takes Assignment and value as arguments.
assignmentThe Assignment that will go to op.

Definition at line 394 of file DecisionTree-inl.h.

Member Function Documentation

◆ apply() [1/2]

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply ( const Unary op) const
inlineoverridevirtual

apply unary operator.

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 414 of file DecisionTree-inl.h.

◆ apply() [2/2]

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply ( const UnaryAssignment op,
const Assignment< L > &  assignment 
) const
inlineoverridevirtual

Apply unary operator with assignment.

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 420 of file DecisionTree-inl.h.

◆ apply_f_op_g()

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply_f_op_g ( const Node g,
const Binary op 
) const
inlineoverridevirtual

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 431 of file DecisionTree-inl.h.

◆ apply_fC_op_gL()

template<typename L , typename Y >
template<typename L , typename Y >
template<typename OP >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply_fC_op_gL ( const Leaf gL,
OP  op 
) const
inline

Definition at line 451 of file DecisionTree-inl.h.

◆ apply_g_op_fC()

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply_g_op_fC ( const Choice< L, Y > &  fC,
const Binary op 
) const
inlineoverridevirtual

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 444 of file DecisionTree-inl.h.

◆ apply_g_op_fL()

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::apply_g_op_fL ( const Leaf fL,
const Binary op 
) const
inlineoverridevirtual

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 436 of file DecisionTree-inl.h.

◆ branches() [1/2]

template<typename L , typename Y >
template<typename L , typename Y >
std::vector<NodePtr>& gtsam::DecisionTree< L, Y >::Choice< L, Y >::branches ( )
inline

Definition at line 290 of file DecisionTree-inl.h.

◆ branches() [2/2]

template<typename L , typename Y >
template<typename L , typename Y >
const std::vector<NodePtr>& gtsam::DecisionTree< L, Y >::Choice< L, Y >::branches ( ) const
inline

Definition at line 286 of file DecisionTree-inl.h.

◆ choose()

template<typename L , typename Y >
template<typename L , typename Y >
NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::choose ( const L label,
size_t  index 
) const
inlineoverridevirtual

choose a branch, recursively

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 459 of file DecisionTree-inl.h.

◆ dot()

template<typename L , typename Y >
template<typename L , typename Y >
void gtsam::DecisionTree< L, Y >::Choice< L, Y >::dot ( std::ostream &  os,
const LabelFormatter labelFormatter,
const ValueFormatter valueFormatter,
bool  showZero 
) const
inlineoverridevirtual

output to graphviz (as a a graph)

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 314 of file DecisionTree-inl.h.

◆ equals()

template<typename L , typename Y >
template<typename L , typename Y >
bool gtsam::DecisionTree< L, Y >::Choice< L, Y >::equals ( const Node q,
const CompareFunc compare 
) const
inlineoverridevirtual

equality

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 348 of file DecisionTree-inl.h.

◆ isLeaf()

template<typename L , typename Y >
template<typename L , typename Y >
bool gtsam::DecisionTree< L, Y >::Choice< L, Y >::isLeaf ( ) const
inlineoverridevirtual

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 235 of file DecisionTree-inl.h.

◆ label()

template<typename L , typename Y >
template<typename L , typename Y >
const L& gtsam::DecisionTree< L, Y >::Choice< L, Y >::label ( ) const
inline

Return the label of this choice node.

Definition at line 278 of file DecisionTree-inl.h.

◆ nrChoices()

template<typename L , typename Y >
template<typename L , typename Y >
size_t gtsam::DecisionTree< L, Y >::Choice< L, Y >::nrChoices ( ) const
inline

Definition at line 282 of file DecisionTree-inl.h.

◆ operator()()

template<typename L , typename Y >
template<typename L , typename Y >
const Y& gtsam::DecisionTree< L, Y >::Choice< L, Y >::operator() ( const Assignment< L > &  x) const
inlineoverridevirtual

evaluate

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 361 of file DecisionTree-inl.h.

◆ print()

template<typename L , typename Y >
template<typename L , typename Y >
void gtsam::DecisionTree< L, Y >::Choice< L, Y >::print ( const std::string &  s,
const LabelFormatter labelFormatter,
const ValueFormatter valueFormatter 
) const
inlineoverridevirtual

print (as a tree).

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 304 of file DecisionTree-inl.h.

◆ push_back()

template<typename L , typename Y >
template<typename L , typename Y >
void gtsam::DecisionTree< L, Y >::Choice< L, Y >::push_back ( NodePtr &&  node)
inline

add a branch: TODO merge into constructor

Definition at line 295 of file DecisionTree-inl.h.

◆ sameLeaf() [1/2]

template<typename L , typename Y >
template<typename L , typename Y >
bool gtsam::DecisionTree< L, Y >::Choice< L, Y >::sameLeaf ( const Leaf q) const
inlineoverridevirtual

Choice-Leaf equality: always false.

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 338 of file DecisionTree-inl.h.

◆ sameLeaf() [2/2]

template<typename L , typename Y >
template<typename L , typename Y >
bool gtsam::DecisionTree< L, Y >::Choice< L, Y >::sameLeaf ( const Node q) const
inlineoverridevirtual

polymorphic equality: if q is a leaf, could be...

Implements gtsam::DecisionTree< L, Y >::Node.

Definition at line 343 of file DecisionTree-inl.h.

◆ Unique()

template<typename L , typename Y >
template<typename L , typename Y >
static NodePtr gtsam::DecisionTree< L, Y >::Choice< L, Y >::Unique ( const NodePtr node)
inlinestatic

Merge branches with equal leaf values for every choice node in a decision tree. If all branches are the same (i.e. have the same leaf value), replace the choice node with the equivalent leaf node.

This function applies the branch merging (if enabled) recursively on the decision tree represented by the root node passed in as the argument. It recurses to the leaf nodes and merges branches with equal leaf values in a bottom-up fashion.

Thus, if all branches of a choice node f are the same, just return a single branch at each recursion step.

Parameters
nodeThe root node of the decision tree.
Returns
NodePtr

Definition at line 205 of file DecisionTree-inl.h.

Member Data Documentation

◆ allSame_

template<typename L , typename Y >
template<typename L , typename Y >
size_t gtsam::DecisionTree< L, Y >::Choice< L, Y >::allSame_
private

Incremental allSame. Records if all the branches are the same leaf.

Definition at line 174 of file DecisionTree-inl.h.

◆ branches_

template<typename L , typename Y >
template<typename L , typename Y >
std::vector<NodePtr> gtsam::DecisionTree< L, Y >::Choice< L, Y >::branches_

The children of this Choice node.

Definition at line 167 of file DecisionTree-inl.h.

◆ label_

template<typename L , typename Y >
template<typename L , typename Y >
L gtsam::DecisionTree< L, Y >::Choice< L, Y >::label_

the label of the variable on which we split

Definition at line 164 of file DecisionTree-inl.h.


The documentation for this struct was generated from the following file:


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:51:15