Skip to content

Commit

Permalink
Added directored risk function
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Aug 11, 2012
1 parent bbf8c1f commit 949e7c9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/interfaces/modular/Structure.i
Expand Up @@ -7,7 +7,19 @@
* Written (W) 2009 Soeren Sonnenburg, 2012 Fernando José Iglesias García
* 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 @@ -30,6 +42,9 @@
#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 Down
2 changes: 2 additions & 0 deletions src/interfaces/modular/Structure_includes.i
@@ -1,4 +1,6 @@
%{
#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 Down
38 changes: 38 additions & 0 deletions src/shogun/structure/DirectorRiskFunction.cpp
@@ -0,0 +1,38 @@
/*
* 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 Sergey Lisitsyn
*/

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

using namespace shogun;

CDirectorRiskFunction::CDirectorRiskFunction()
: CRiskFunction()
{
}

CDirectorRiskFunction::~CDirectorRiskFunction()
{
}

void CDirectorRiskFunction::risk(void* data, float64_t* R, float64_t* subgrad, float64_t* W)
{
CDotFeatures* features = (CDotFeatures*)(((bmrm_data_T*)data)->X);
CLabels* labels = (CLabels*)(((bmrm_data_T*)data)->y);
int32_t w_dim = ((bmrm_data_T*)data)->w_dim;
risk_directed(features,labels,SGVector<float64_t>(R,1,false),
SGVector<float64_t>(subgrad,w_dim,false),
SGVector<float64_t>(W,w_dim,false));
}

void CDirectorRiskFunction::risk_directed(CDotFeatures* features, CLabels* labels, const SGVector<float64_t> R,
const SGVector<float64_t> subgrad, const SGVector<float64_t> W)
{
SG_NOTIMPLEMENTED;
}
48 changes: 48 additions & 0 deletions src/shogun/structure/DirectorRiskFunction.h
@@ -0,0 +1,48 @@
/*
* 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 Sergey Lisitsyn
*/

#ifndef DIRECTOR_RISK_FUNCTION_H_
#define DIRECTOR_RISK_FUNCTION_H_

#include <shogun/structure/RiskFunction.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/labels/Labels.h>

namespace shogun
{

/** @brief Class CDirectorRiskFunction TODO
*
*/
class CDirectorRiskFunction : public CRiskFunction
{
public:
/** default constructor */
CDirectorRiskFunction();

/** destructor */
virtual ~CDirectorRiskFunction();

/** computes the value of the risk function and sub-gradient at given point
*
*/
virtual void risk(void* data, float64_t* R, float64_t* subgrad, float64_t* W);

/** computes the value of the risk function and sub-gradient at given point
* director interface
*/
virtual void risk_directed(CDotFeatures* features, CLabels* labels, const SGVector<float64_t> R,
const SGVector<float64_t> subgrad, const SGVector<float64_t> W);

/** @return name of SGSerializable */
virtual const char* get_name() const { return "DirectorRiskFunction"; }

}; /* CDirectorRiskFunction */
}
#endif /* DIRECTOR_RISK_FUNCTION_H_ */

0 comments on commit 949e7c9

Please sign in to comment.