From 436952b23991277a31418a1668195c3310e5b674 Mon Sep 17 00:00:00 2001 From: Sergey Lisitsyn Date: Thu, 14 Mar 2013 22:51:41 +0400 Subject: [PATCH] Fixed bmrm_return_value issues --- .../graphical/so_multiclass_BMRM.py | 12 +-- .../graphical/so_multiclass_director_BMRM.py | 12 +-- src/interfaces/modular/Structure.i | 3 +- src/interfaces/modular/Structure_includes.i | 1 + src/shogun/structure/bmrm_return_value.h | 93 +++++++++++++++++++ src/shogun/structure/libbmrm.h | 60 +----------- 6 files changed, 108 insertions(+), 73 deletions(-) create mode 100644 src/shogun/structure/bmrm_return_value.h diff --git a/examples/undocumented/python_modular/graphical/so_multiclass_BMRM.py b/examples/undocumented/python_modular/graphical/so_multiclass_BMRM.py index 6bbe01db307..19a950aa500 100644 --- a/examples/undocumented/python_modular/graphical/so_multiclass_BMRM.py +++ b/examples/undocumented/python_modular/graphical/so_multiclass_BMRM.py @@ -70,18 +70,18 @@ def get_so_labels(out): sosvm.train() res = sosvm.get_result() -Fps = np.array(res.hist_Fp) -Fds = np.array(res.hist_Fp) -wdists = np.array(res.hist_wdist) +Fps = np.array(res.get_hist_Fp()) +Fds = np.array(res.get_hist_Fp()) +wdists = np.array(res.get_hist_wdist()) plt.figure() plt.subplot(221) plt.title('Fp and Fd history') -plt.plot(xrange(res.nIter), Fps, hold=True) -plt.plot(xrange(res.nIter), Fds, hold=True) +plt.plot(xrange(res.get_nIter()), Fps, hold=True) +plt.plot(xrange(res.get_nIter()), Fds, hold=True) plt.subplot(222) plt.title('w dist history') -plt.plot(xrange(res.nIter), wdists) +plt.plot(xrange(res.get_nIter()), wdists) # Evaluation out = sosvm.apply() diff --git a/examples/undocumented/python_modular/graphical/so_multiclass_director_BMRM.py b/examples/undocumented/python_modular/graphical/so_multiclass_director_BMRM.py index 035e9210930..c684fe96b0c 100644 --- a/examples/undocumented/python_modular/graphical/so_multiclass_director_BMRM.py +++ b/examples/undocumented/python_modular/graphical/so_multiclass_director_BMRM.py @@ -118,18 +118,18 @@ def get_so_labels(out): sosvm.train() res = sosvm.get_result() -Fps = np.array([res.hist_Fp[i] for i in xrange(res.hist_Fp.size())]) -Fds = np.array([res.hist_Fd[i] for i in xrange(res.hist_Fd.size())]) -wdists = np.array([res.hist_wdist[i] for i in xrange(res.hist_wdist.size())]) +Fps = res.get_hist_Fp() +Fds = res.get_hist_Fd() +wdists = res.get_hist_wdist() plt.figure() plt.subplot(221) plt.title('Fp and Fd history') -plt.plot(xrange(res.nIter), Fps, hold=True) -plt.plot(xrange(res.nIter), Fds, hold=True) +plt.plot(xrange(res.get_nIter()), Fps, hold=True) +plt.plot(xrange(res.get_nIter()), Fds, hold=True) plt.subplot(222) plt.title('w dist history') -plt.plot(xrange(res.nIter), wdists) +plt.plot(xrange(res.get_nIter()), wdists) # Evaluation out = sosvm.apply() diff --git a/src/interfaces/modular/Structure.i b/src/interfaces/modular/Structure.i index e4465a311bc..050c53b44dc 100644 --- a/src/interfaces/modular/Structure.i +++ b/src/interfaces/modular/Structure.i @@ -37,7 +37,6 @@ %rename(DirectorStructuredModel) CDirectorStructuredModel; %rename(DualLibQPBMSOSVM) CDualLibQPBMSOSVM; - #ifdef USE_MOSEK %rename(PrimalMosekSOSVM) CPrimalMosekSOSVM; #endif /* USE_MOSEK */ @@ -55,6 +54,7 @@ %include %include +%include %include %include %include @@ -66,7 +66,6 @@ %include %include - #ifdef USE_MOSEK %include #endif /* USE_MOSEK */ diff --git a/src/interfaces/modular/Structure_includes.i b/src/interfaces/modular/Structure_includes.i index d2733279e41..25565e05788 100644 --- a/src/interfaces/modular/Structure_includes.i +++ b/src/interfaces/modular/Structure_includes.i @@ -11,6 +11,7 @@ #include #include + #include #include #include #include diff --git a/src/shogun/structure/bmrm_return_value.h b/src/shogun/structure/bmrm_return_value.h new file mode 100644 index 00000000000..543ac1aed69 --- /dev/null +++ b/src/shogun/structure/bmrm_return_value.h @@ -0,0 +1,93 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Copyright (C) 2012 Michal Uricar, uricamic@cmp.felk.cvut.cz + * + */ + +#ifndef BMRM_RETURN_VALUE_H_ +#define BMRM_RETURN_VALUE_H_ + +#include +#include +#include + +namespace shogun +{ + +/** BMRM result structure */ +struct bmrm_return_value_T +{ + /** constructor */ + bmrm_return_value_T() + { + nIter = 0; + nCP = 0; + nzA = 0; + Fp = 0; + Fd = 0; + qp_exitflag = 0; + exitflag = 0; + }; + + /** destructor */ + virtual ~bmrm_return_value_T() { }; + + /** dummy load serializable */ + bool load_serializable(CSerializableFile* file, const char* prefix="") { return false; } + + /** dummy save serializable */ + bool save_serializable(CSerializableFile* file, const char* prefix="") { return false; } + + /** number of iterations */ + uint32_t nIter; + + /** getter for nIter */ + uint32_t get_nIter() const { return nIter; } + + /** number of cutting planes */ + uint32_t nCP; + + /** number of active cutting planes */ + uint32_t nzA; + + /** primal objective value */ + float64_t Fp; + + /** reduced (dual) objective value */ + float64_t Fd; + + /** exitflag from the last call of the inner QP solver */ + int8_t qp_exitflag; + + /** 1 .. bmrm.Q_P - bmrm.Q_D <= TolRel*ABS(bmrm.Q_P) + * 2 .. bmrm.Q_P - bmrm.Q_D <= TolAbs + * -1 .. bmrm.nCutPlanes >= BufSize + * -2 .. not enough memory for the solver + */ + int8_t exitflag; + + /** Track of Fp values in individual iterations */ + SGVector< float64_t > hist_Fp; + + /** getter for hist_Fp */ + SGVector< float64_t > get_hist_Fp() const { return hist_Fp; }; + + /** Track of Fd values in individual iterations */ + SGVector< float64_t > hist_Fd; + + /** getter for hist_Fd */ + SGVector< float64_t > get_hist_Fd() const { return hist_Fd; }; + + /** Track of w_dist values in individual iterations */ + SGVector< float64_t > hist_wdist; + + /** getter for hist_wdist */ + SGVector< float64_t > get_hist_wdist() const { return hist_wdist; }; +}; + +} +#endif diff --git a/src/shogun/structure/libbmrm.h b/src/shogun/structure/libbmrm.h index ad047710b45..ab56c800a2d 100644 --- a/src/shogun/structure/libbmrm.h +++ b/src/shogun/structure/libbmrm.h @@ -13,6 +13,7 @@ #include #include +#include #ifndef libbmrm_h #define libbmrm_h @@ -28,65 +29,6 @@ namespace shogun { -/** BMRM result structure */ -struct bmrm_return_value_T -{ - /** constructor */ - bmrm_return_value_T() - { - nIter = 0; - nCP = 0; - nzA = 0; - Fp = 0; - Fd = 0; - qp_exitflag = 0; - exitflag = 0; - }; - - /** destructor */ - ~bmrm_return_value_T() { }; - - /** dummy load serializable */ - bool load_serializable(CSerializableFile* file, const char* prefix="") { return false; } - - /** dummy save serializable */ - bool save_serializable(CSerializableFile* file, const char* prefix="") { return false; } - - /** number of iterations */ - uint32_t nIter; - - /** number of cutting planes */ - uint32_t nCP; - - /** number of active cutting planes */ - uint32_t nzA; - - /** primal objective value */ - float64_t Fp; - - /** reduced (dual) objective value */ - float64_t Fd; - - /** exitflag from the last call of the inner QP solver */ - int8_t qp_exitflag; - - /** 1 .. bmrm.Q_P - bmrm.Q_D <= TolRel*ABS(bmrm.Q_P) - * 2 .. bmrm.Q_P - bmrm.Q_D <= TolAbs - * -1 .. bmrm.nCutPlanes >= BufSize - * -2 .. not enough memory for the solver - */ - int8_t exitflag; - - /** Track of Fp values in individual iterations */ - SGVector< float64_t > hist_Fp; - - /** Track of Fd values in individual iterations */ - SGVector< float64_t > hist_Fd; - - /** Track of w_dist values in individual iterations */ - SGVector< float64_t > hist_wdist; -}; - /** Linked list for cutting planes buffer management */ IGNORE_IN_CLASSLIST struct bmrm_ll { /** Pointer to previous CP entry */