SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
BalancedConditionalProbabilityTree.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Chiyuan Zhang
8  * Copyright (C) 2012 Chiyuan Zhang
9  */
10 
12 
13 using namespace shogun;
14 
16  :m_alpha(0.4)
17 {
18  SG_ADD(&m_alpha, "m_alpha", "Trade-off parameter of tree balance", MS_NOT_AVAILABLE);
19 }
20 
22 {
23  if (alpha < 0 || alpha > 1)
24  SG_ERROR("expect 0 <= alpha <= 1, but got %g\n", alpha)
25  m_alpha = alpha;
26 }
27 
29 {
30  float64_t pred = predict_node(ex, node);
31  float64_t depth_left = tree_depth(node->left());
32  float64_t depth_right = tree_depth(node->right());
33 
34  float64_t cnt_left = CMath::pow(2.0, depth_left);
35  float64_t cnt_right = CMath::pow(2.0, depth_right);
36 
37  float64_t obj_val = (1-m_alpha) * 2 * (pred-0.5) + m_alpha * CMath::log2(cnt_left/cnt_right);
38 
39  if (obj_val > 0)
40  return false; // go right
41  return true; // go left
42 }
43 
44 int32_t CBalancedConditionalProbabilityTree::tree_depth(bnode_t *node)
45 {
46  int32_t depth = 0;
47  while (node != NULL)
48  {
49  depth++;
50  node = node->left();
51  }
52 
53  return depth;
54 }
The node of the tree structure forming a TreeMachine The node contains pointer to its parent and poin...
virtual bool which_subtree(bnode_t *node, SGVector< float32_t > ex)
#define SG_ERROR(...)
Definition: SGIO.h:129
float64_t predict_node(SGVector< float32_t > ex, bnode_t *node)
void right(CBinaryTreeMachineNode *r)
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static float64_t log2(float64_t v)
log10(x), x being a complex128_t
Definition: Math.h:909
#define SG_ADD(...)
Definition: SGObject.h:84
void left(CBinaryTreeMachineNode *l)
static int32_t pow(bool x, int32_t n)
Definition: Math.h:535

SHOGUN Machine Learning Toolbox - Documentation