Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor RiskFunction in structure methods This code refactoring basi…
…cally adds RiskFunction functionality into StructuredModel. This way we can remove RiskFunction and all the related objects and have only one user defined class (StructuredModel) for SO methods.
  • Loading branch information
vigsterkr committed Aug 15, 2012
1 parent f7116ba commit a72e3cf
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 727 deletions.
16 changes: 1 addition & 15 deletions examples/undocumented/libshogun/so_multiclass_BMRM.cpp
Expand Up @@ -21,7 +21,6 @@
#include <shogun/structure/MulticlassSOLabels.h>
#include <shogun/structure/MulticlassModel.h>
#include <shogun/structure/DualLibQPBMSOSVM.h>
#include <shogun/structure/MulticlassRiskFunction.h>
#include <shogun/io/StreamingAsciiFile.h>
#include <shogun/features/streaming/StreamingSparseFeatures.h>

Expand Down Expand Up @@ -134,27 +133,14 @@ int main(int argc, char * argv[])
// Create loss function
CHingeLoss* loss = new CHingeLoss();

// Create risk function
CMulticlassRiskFunction* risk = new CMulticlassRiskFunction();

// Create risk data
CMulticlassRiskData* risk_data =
new CMulticlassRiskData(
features,
labels,
model->get_dim(),
features->get_num_vectors());

// Create SO-SVM
CDualLibQPBMSOSVM* sosvm =
new CDualLibQPBMSOSVM(
model,
loss,
labels,
features,
lambda,
risk,
risk_data);
lambda);
SG_REF(sosvm);

sosvm->set_cleanAfter(10);
Expand Down
19 changes: 0 additions & 19 deletions src/interfaces/modular/Structure.i
Expand Up @@ -8,18 +8,6 @@
* Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
*/

#ifdef USE_SWIG_DIRECTORS
%feature("director") shogun::CDirectorRiskFunction;
%feature("director:except") {
if ($error != NULL) {
throw Swig::DirectorMethodException();
}
}
#endif

%rename(BaseRiskFunction) CRiskFunction;
%rename(DirectorRiskFunction) CDirectorRiskFunction;

/* Remove C Prefix */
%rename(PlifBase) CPlifBase;
%rename(Plif) CPlif;
Expand All @@ -42,9 +30,6 @@
%rename(StateModel) CStateModel;
%rename(TwoStateModel) CTwoStateModel;

%rename(RiskData) CRiskData;
%rename(MulticlassRiskFunction) CMulticlassRiskFunction;
%rename(MulticlassRiskData) CMulticlassRiskData;
%rename(DualLibQPBMSOSVM) CDualLibQPBMSOSVM;


Expand All @@ -53,9 +38,6 @@
#endif /* USE_MOSEK */

/* Include Class Headers to make them visible from within the target language */
%include <shogun/structure/RiskFunction.h>
%include <shogun/structure/DirectorRiskFunction.h>

%include <shogun/structure/PlifBase.h>
%include <shogun/structure/Plif.h>
%include <shogun/structure/PlifArray.h>
Expand All @@ -80,7 +62,6 @@
%include <shogun/structure/libbmrm.h>
%include <shogun/structure/libppbm.h>
%include <shogun/structure/libp3bm.h>
%include <shogun/structure/MulticlassRiskFunction.h>
%include <shogun/structure/DualLibQPBMSOSVM.h>


Expand Down
3 changes: 0 additions & 3 deletions src/interfaces/modular/Structure_includes.i
@@ -1,6 +1,4 @@
%{
#include <shogun/structure/RiskFunction.h>
#include <shogun/structure/DirectorRiskFunction.h>
#include <shogun/structure/PlifBase.h>
#include <shogun/structure/Plif.h>
#include <shogun/structure/PlifArray.h>
Expand All @@ -25,7 +23,6 @@
#include <shogun/structure/libbmrm.h>
#include <shogun/structure/libppbm.h>
#include <shogun/structure/libp3bm.h>
#include <shogun/structure/MulticlassRiskFunction.h>
#include <shogun/structure/DualLibQPBMSOSVM.h>

#ifdef USE_MOSEK
Expand Down
1 change: 0 additions & 1 deletion src/interfaces/modular/modshogun_ignores.i
Expand Up @@ -26,7 +26,6 @@
%ignore shogun::CStructuredModel::init_opt;
%ignore shogun::CIndexBlockTree::CIndexBlockTree(SGVector<float64_t> G, SGVector<float64_t> ind_t);
%ignore shogun::CKernelMeanMatching::CKernelMeanMatching(CKernel* kernel, SGVector<index_t> training_indices, SGVector<index_t> test_indices);
%ignore shogun::CDirectorRiskFunction::risk_directed(CDotFeatures* features, CLabels* labels, SGVector<float64_t> R, SGVector<float64_t> subgrad, const SGVector<float64_t> W);
#endif

%ignore shogun::bmrm_ll;
Expand Down
34 changes: 0 additions & 34 deletions src/shogun/latent/LatentRiskFunction.cpp

This file was deleted.

62 changes: 0 additions & 62 deletions src/shogun/latent/LatentRiskFunction.h

This file was deleted.

5 changes: 1 addition & 4 deletions src/shogun/latent/LatentSOSVM.cpp
Expand Up @@ -9,7 +9,6 @@
*/

#include <shogun/latent/LatentSOSVM.h>
#include <shogun/latent/LatentRiskFunction.h>
#include <shogun/structure/DualLibQPBMSOSVM.h>

using namespace shogun;
Expand Down Expand Up @@ -49,8 +48,7 @@ void CLatentSOSVM::set_so_solver(CLinearStructuredOutputMachine* so)
float64_t CLatentSOSVM::do_inner_loop(float64_t cooling_eps)
{
float64_t lambda = 1/m_C;
CLatentRiskFunction* risk = new CLatentRiskFunction();
CDualLibQPBMSOSVM* so = new CDualLibQPBMSOSVM(NULL, NULL, NULL, NULL, lambda, risk, NULL);
CDualLibQPBMSOSVM* so = new CDualLibQPBMSOSVM();
so->train();

/* copy the resulting w */
Expand All @@ -60,7 +58,6 @@ float64_t CLatentSOSVM::do_inner_loop(float64_t cooling_eps)
/* get the primal objective value */
float64_t po = so->get_result().Fp;

SG_UNREF(risk);
SG_UNREF(so);

return po;
Expand Down
73 changes: 0 additions & 73 deletions src/shogun/structure/DirectorRiskFunction.cpp

This file was deleted.

93 changes: 0 additions & 93 deletions src/shogun/structure/DirectorRiskFunction.h

This file was deleted.

0 comments on commit a72e3cf

Please sign in to comment.