SHOGUN  6.1.3
BalancedConditionalProbabilityTree.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
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 {
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:128
float64_t predict_node(SGVector< float32_t > ex, bnode_t *node)
void right(CBinaryTreeMachineNode *r)
double float64_t
Definition: common.h:60
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:705