Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
634 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* 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. | ||
* | ||
* Written (W) 1999-2012 Soeren Sonnenburg and Sergey Lisitsyn | ||
* Copyright (C) 1999-2012 Fraunhofer Institute FIRST and Max-Planck-Society | ||
*/ | ||
|
||
#ifndef _KERNELMULTICLASSMACHINE_H___ | ||
#define _KERNELMULTICLASSMACHINE_H___ | ||
|
||
#include <shogun/lib/common.h> | ||
#include <shogun/features/Features.h> | ||
#include <shogun/kernel/Kernel.h> | ||
#include <shogun/machine/MulticlassMachine.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CKernel; | ||
class CKernelMachine; | ||
|
||
/** @brief generic kernel multiclass */ | ||
class CKernelMulticlassMachine : public CMulticlassMachine | ||
{ | ||
public: | ||
/** default constructor */ | ||
CKernelMulticlassMachine() : CMulticlassMachine(), m_kernel(NULL) | ||
{ | ||
m_parameters->add((CSGObject**)&m_kernel,"m_kernel"); | ||
} | ||
|
||
/** standard constructor | ||
* @param strategy multiclass strategy | ||
* @param machine machine | ||
* @param labels labels | ||
*/ | ||
CKernelMulticlassMachine(EMulticlassStrategy strategy, CKernel* kernel, CKernelMachine* machine, CLabels* labs) : | ||
CMulticlassMachine(strategy,machine,labs), m_kernel(NULL) | ||
{ | ||
set_kernel(kernel); | ||
m_parameters->add((CSGObject**)&m_kernel,"m_kernel"); | ||
} | ||
|
||
/** destructor */ | ||
virtual ~CKernelMulticlassMachine() | ||
{ | ||
SG_UNREF(m_kernel); | ||
} | ||
|
||
/** get name */ | ||
virtual const char* get_name() const | ||
{ | ||
return "KernelMulticlassMachine"; | ||
} | ||
|
||
/** set kernel | ||
* | ||
* @param k kernel | ||
*/ | ||
void set_kernel(CKernel* k) | ||
{ | ||
SG_REF(k); | ||
SG_UNREF(m_kernel); | ||
m_kernel=k; | ||
} | ||
|
||
/** get kernel | ||
* | ||
* @return kernel | ||
*/ | ||
CKernel* get_kernel() | ||
{ | ||
SG_REF(m_kernel); | ||
return m_kernel; | ||
} | ||
|
||
protected: | ||
|
||
virtual bool init_machine_for_train(CFeatures* data) | ||
{ | ||
if (data) | ||
m_kernel->init(data,data); | ||
|
||
((CKernelMachine*)m_machine)->set_kernel(m_kernel); | ||
|
||
return true; | ||
} | ||
|
||
virtual bool init_machines_for_apply(CFeatures* data) | ||
{ | ||
if (data) | ||
m_kernel->init(m_kernel->get_lhs(),data); | ||
|
||
for (int32_t i=0; i<m_machines.vlen; i++) | ||
((CKernelMachine*)m_machines[i])->set_kernel(m_kernel); | ||
return true; | ||
} | ||
|
||
virtual bool is_ready() | ||
{ | ||
if (m_kernel && m_kernel->get_num_vec_lhs() && m_kernel->get_num_vec_rhs()) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
virtual CMachine* get_machine_from_trained(CMachine* machine) | ||
{ | ||
return new CKernelMachine((CKernelMachine*)machine); | ||
} | ||
|
||
virtual int32_t get_num_rhs_vectors() | ||
{ | ||
return m_kernel->get_num_vec_rhs(); | ||
} | ||
|
||
private: | ||
|
||
CKernel* m_kernel; | ||
|
||
}; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* 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. | ||
* | ||
* Written (W) 2012 Sergey Lisitsyn | ||
* Copyright (C) 2012 Sergey Lisitsyn | ||
*/ | ||
|
||
#ifndef _LINEARMULTICLASSMACHINE_H___ | ||
#define _LINEARMULTICLASSMACHINE_H___ | ||
|
||
#include <shogun/lib/common.h> | ||
#include <shogun/features/DotFeatures.h> | ||
#include <shogun/machine/LinearMachine.h> | ||
#include <shogun/machine/MulticlassMachine.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
class CDotFeatures; | ||
class CLinearMachine; | ||
|
||
/** @brief generic linear multiclass machine */ | ||
class CLinearMulticlassMachine : public CMulticlassMachine | ||
{ | ||
public: | ||
/** default constructor */ | ||
CLinearMulticlassMachine() : CMulticlassMachine(), m_features(NULL) | ||
{ | ||
m_parameters->add((CSGObject**)&m_features,"m_features"); | ||
} | ||
|
||
/** standard constructor | ||
* @param strategy multiclass strategy | ||
* @param machine machine | ||
* @param labels labels | ||
*/ | ||
CLinearMulticlassMachine(EMulticlassStrategy strategy, CDotFeatures* features, CLinearMachine* machine, CLabels* labs) : | ||
CMulticlassMachine(strategy,machine,labs), m_features(NULL) | ||
{ | ||
set_features(features); | ||
m_parameters->add((CSGObject**)&m_features,"m_features"); | ||
} | ||
|
||
/** destructor */ | ||
virtual ~CLinearMulticlassMachine() | ||
{ | ||
SG_UNREF(m_features); | ||
} | ||
|
||
virtual const char* get_name() const | ||
{ | ||
return "LinearMulticlassMachine"; | ||
} | ||
|
||
/** set features | ||
* | ||
* @param f features | ||
*/ | ||
void set_features(CDotFeatures* f) | ||
{ | ||
SG_REF(f); | ||
SG_UNREF(m_features); | ||
m_features = f; | ||
} | ||
|
||
/** get features | ||
* | ||
* @return kernel | ||
*/ | ||
CDotFeatures* get_features() const | ||
{ | ||
SG_REF(m_features); | ||
return m_features; | ||
} | ||
|
||
protected: | ||
|
||
virtual bool init_machine_for_train(CFeatures* data) | ||
{ | ||
if (data) | ||
set_features((CDotFeatures*)data); | ||
|
||
((CLinearMachine*)m_machine)->set_features(m_features); | ||
|
||
return true; | ||
} | ||
|
||
virtual bool init_machines_for_apply(CFeatures* data) | ||
{ | ||
if (data) | ||
set_features((CDotFeatures*)data); | ||
|
||
for (int32_t i=0; i<m_machines.vlen; i++) | ||
((CLinearMachine*)m_machines[i])->set_features(m_features); | ||
|
||
return true; | ||
} | ||
|
||
virtual bool is_ready() | ||
{ | ||
if (m_features) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
virtual CMachine* get_machine_from_trained(CMachine* machine) | ||
{ | ||
return new CLinearMachine((CLinearMachine*)machine); | ||
} | ||
|
||
virtual int32_t get_num_rhs_vectors() | ||
{ | ||
return m_features->get_num_vectors(); | ||
} | ||
|
||
private: | ||
|
||
CDotFeatures* m_features; | ||
|
||
}; | ||
} | ||
#endif |
Oops, something went wrong.