Skip to content

Commit

Permalink
Fixed bmrm_return_value issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Mar 14, 2013
1 parent 5a9e1c8 commit 436952b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 73 deletions.
Expand Up @@ -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()
Expand Down
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/modular/Structure.i
Expand Up @@ -37,7 +37,6 @@
%rename(DirectorStructuredModel) CDirectorStructuredModel;
%rename(DualLibQPBMSOSVM) CDualLibQPBMSOSVM;


#ifdef USE_MOSEK
%rename(PrimalMosekSOSVM) CPrimalMosekSOSVM;
#endif /* USE_MOSEK */
Expand All @@ -55,6 +54,7 @@
%include <shogun/machine/LinearStructuredOutputMachine.h>
%include <shogun/machine/KernelStructuredOutputMachine.h>

%include <shogun/structure/bmrm_return_value.h>
%include <shogun/structure/StructuredModel.h>
%include <shogun/structure/MulticlassModel.h>
%include <shogun/structure/MulticlassSOLabels.h>
Expand All @@ -66,7 +66,6 @@
%include <shogun/structure/DirectorStructuredModel.h>
%include <shogun/structure/DualLibQPBMSOSVM.h>


#ifdef USE_MOSEK
%include <shogun/structure/PrimalMosekSOSVM.h>
#endif /* USE_MOSEK */
1 change: 1 addition & 0 deletions src/interfaces/modular/Structure_includes.i
Expand Up @@ -11,6 +11,7 @@
#include <shogun/machine/LinearStructuredOutputMachine.h>
#include <shogun/machine/KernelStructuredOutputMachine.h>

#include <shogun/structure/bmrm_return_value.h>
#include <shogun/structure/StructuredModel.h>
#include <shogun/structure/MulticlassModel.h>
#include <shogun/structure/MulticlassSOLabels.h>
Expand Down
93 changes: 93 additions & 0 deletions 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 <shogun/lib/common.h>
#include <shogun/io/SerializableFile.h>
#include <shogun/lib/SGVector.h>

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
60 changes: 1 addition & 59 deletions src/shogun/structure/libbmrm.h
Expand Up @@ -13,6 +13,7 @@

#include <shogun/lib/common.h>
#include <shogun/structure/StructuredModel.h>
#include <shogun/structure/bmrm_return_value.h>

#ifndef libbmrm_h
#define libbmrm_h
Expand All @@ -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 */
Expand Down

0 comments on commit 436952b

Please sign in to comment.