Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
puffin444 committed Jul 6, 2012
2 parents 3711463 + 564295a commit 79cfd56
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 88 deletions.
22 changes: 14 additions & 8 deletions src/shogun/lib/IndexBlockTree.cpp
Expand Up @@ -33,20 +33,22 @@ struct block_tree_node_t
float64_t weight;
};

int count_sub_nodes_recursive(tree_node_t* node)
int count_sub_nodes_recursive(tree_node_t* node, int32_t self)
{
if (node->n_desc==0)
{
return 1;
}
else
{
node->sub_nodes_count = 0;
int c = 0;
for (int32_t i=0; i<node->n_desc; i++)
{
node->sub_nodes_count += count_sub_nodes_recursive(node->desc[i]);
c += count_sub_nodes_recursive(node->desc[i], self);
}
return node->sub_nodes_count;
if (self)
node->sub_nodes_count = c;
return c + self;
}
}

Expand All @@ -64,7 +66,7 @@ void fill_ind_recursive(tree_node_t* node, vector<block_tree_node_t>* tree_nodes
int32_t l = lower;
for (int32_t i=0; i<node->n_desc; i++)
{
int32_t c = node->desc[i]->n_desc;
int32_t c = node->desc[i]->sub_nodes_count;
if (c>0)
{
tree_nodes->push_back(block_tree_node_t(l,l+c-1,1.0));
Expand Down Expand Up @@ -139,9 +141,11 @@ CIndexBlockTree::CIndexBlockTree(SGMatrix<float64_t> adjacency_matrix) :
}
SG_FREE(nz_row);

count_sub_nodes_recursive(nodes);
//print_tree(nodes,0);
m_precomputed_ind_t = SGVector<float64_t>(3*(n_features-nodes[0].sub_nodes_count));
count_sub_nodes_recursive(nodes,1);
print_tree(nodes,0);
int32_t n_leaves = count_sub_nodes_recursive(nodes,0);
m_precomputed_ind_t = SGVector<float64_t>((n_features-n_leaves)*3);
SG_PRINT("n_leaves = %d\n",n_leaves);
vector<block_tree_node_t> blocks;
fill_ind_recursive(nodes, &blocks, 1);
m_precomputed_ind_t[0] = -1;
Expand All @@ -154,6 +158,8 @@ CIndexBlockTree::CIndexBlockTree(SGMatrix<float64_t> adjacency_matrix) :
m_precomputed_ind_t[3+3*i+1] = blocks[i].t_max_index;
m_precomputed_ind_t[3+3*i+2] = blocks[i].weight;
}
for (int32_t i=0; i<n_features; i++)
SG_FREE(nodes[i].desc);
SG_FREE(nodes);
}

Expand Down
11 changes: 7 additions & 4 deletions src/shogun/structure/DualLibQPBMSOSVM.cpp
Expand Up @@ -9,7 +9,6 @@
*/

#include <shogun/structure/DualLibQPBMSOSVM.h>
#include <shogun/structure/libbmrm.h>

using namespace shogun;

Expand All @@ -31,6 +30,10 @@ CDualLibQPBMSOSVM::CDualLibQPBMSOSVM(
set_TolAbs(0.0);
set_BufSize(1000);
set_lambda(lambda);
set_cleanICP(true);
set_cleanAfter(10);
set_K(0.4);
set_Tmax(100);
m_risk_function=risk_function;
}

Expand All @@ -53,10 +56,10 @@ bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
bmrm_data.w_dim=nDim;

// call the BMRM solver
bmrm_return_value_T result = svm_bmrm_solver(&bmrm_data, m_w.vector, m_TolRel, m_TolAbs, m_lambda,
m_BufSize, m_risk_function);
m_bmrm_result = svm_bmrm_solver(&bmrm_data, m_w.vector, m_TolRel, m_TolAbs, m_lambda,
m_BufSize, m_cleanICP, m_cleanAfter, m_K, m_Tmax, m_risk_function);

if (result.exitflag==1)
if (m_bmrm_result.exitflag==1)
{
return true;
} else {
Expand Down
43 changes: 43 additions & 0 deletions src/shogun/structure/DualLibQPBMSOSVM.h
Expand Up @@ -13,6 +13,7 @@

#include <shogun/machine/LinearStructuredOutputMachine.h>
#include <shogun/structure/RiskFunction.h>
#include <shogun/structure/libbmrm.h>

namespace shogun
{
Expand Down Expand Up @@ -55,6 +56,33 @@ class CDualLibQPBMSOSVM : public CLinearStructuredOutputMachine
/** get size of cutting plane buffer */
inline uint32_t get_BufSize() { return m_BufSize; }

/** set ICP removal flag */
inline void set_cleanICP(bool cleanICP) { m_cleanICP=cleanICP; }

/** get ICP removal flag */
inline bool get_cleanICP() { return m_cleanICP; }

/** set number of iterations for cleaning ICP */
inline void set_cleanAfter(uint32_t cleanAfter) { m_cleanAfter=cleanAfter; }

/** get number of iterations for cleaninng ICP */
inline uint32_t get_cleanAfter() { return m_cleanAfter; }

/** set K */
inline void set_K(float64_t K) { m_K=K; }

/** get K */
inline float64_t get_K() { return m_K; }

/** set Tmax */
inline void set_Tmax(uint32_t Tmax) { m_Tmax=Tmax; }

/** get Tmax */
inline uint32_t get_Tmax() { return m_Tmax; }

/** get bmrm result */
inline bmrm_return_value_T get_bmrm_result() { return m_bmrm_result; }

protected:
/** train dual SO-SVM
*
Expand All @@ -75,9 +103,24 @@ class CDualLibQPBMSOSVM : public CLinearStructuredOutputMachine
/** BufSize */
uint32_t m_BufSize;

/** Clean ICP */
bool m_cleanICP;

/** Clean ICP after n-th iteration */
uint32_t m_cleanAfter;

/** K */
float64_t m_K;

/** Tmax */
uint32_t m_Tmax;

/** Risk function */
CRiskFunction* m_risk_function;

/** BMRM result */
bmrm_return_value_T m_bmrm_result;

}; /* class CDualLibQPBMSOSVM */

} /* namespace shogun */
Expand Down

0 comments on commit 79cfd56

Please sign in to comment.