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
Soeren Sonnenburg
committed
Sep 21, 2011
1 parent
b3eccaf
commit 00f7777
Showing
3 changed files
with
312 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <shogun/preprocessor/DecompressString.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** default constructor */ | ||
template <class ST> | ||
CDecompressString<ST>::CDecompressString() : CStringPreprocessor<ST>() | ||
{ | ||
compressor=NULL; | ||
} | ||
|
||
template <class ST> | ||
CDecompressString<ST>::CDecompressString(E_COMPRESSION_TYPE ct) : CStringPreprocessor<ST>() | ||
{ | ||
compressor=new CCompressor(ct); | ||
} | ||
|
||
template <class ST> | ||
CDecompressString<ST>::~CDecompressString() | ||
{ | ||
delete compressor; | ||
} | ||
|
||
template <class ST> | ||
bool CDecompressString<ST>::init(CFeatures* f) | ||
{ | ||
ASSERT(f->get_feature_class()==C_STRING); | ||
return true; | ||
} | ||
|
||
template <class ST> | ||
void CDecompressString<ST>::cleanup() | ||
{ | ||
} | ||
|
||
template <class ST> | ||
bool CDecompressString<ST>::load(FILE* f) | ||
{ | ||
SG_SET_LOCALE_C; | ||
SG_RESET_LOCALE; | ||
return false; | ||
} | ||
|
||
template <class ST> | ||
bool CDecompressString<ST>::save(FILE* f) | ||
{ | ||
SG_SET_LOCALE_C; | ||
SG_RESET_LOCALE; | ||
return false; | ||
} | ||
|
||
template <class ST> | ||
bool CDecompressString<ST>::apply_to_string_features(CFeatures* f) | ||
{ | ||
int32_t i; | ||
int32_t num_vec=((CStringFeatures<ST>*)f)->get_num_vectors(); | ||
|
||
for (i=0; i<num_vec; i++) | ||
{ | ||
int32_t len=0; | ||
bool free_vec; | ||
ST* vec=((CStringFeatures<ST>*)f)-> | ||
get_feature_vector(i, len, free_vec); | ||
|
||
ST* decompressed=apply_to_string(vec, len); | ||
((CStringFeatures<ST>*)f)-> | ||
free_feature_vector(vec, i, free_vec); | ||
((CStringFeatures<ST>*)f)-> | ||
cleanup_feature_vector(i); | ||
((CStringFeatures<ST>*)f)-> | ||
set_feature_vector(i, decompressed, len); | ||
} | ||
return true; | ||
} | ||
|
||
template <class ST> | ||
ST* CDecompressString<ST>::apply_to_string(ST* f, int32_t &len) | ||
{ | ||
uint64_t compressed_size=((int32_t*) f)[0]; | ||
uint64_t uncompressed_size=((int32_t*) f)[1]; | ||
|
||
int32_t offs=CMath::ceil(2.0*sizeof(int32_t)/sizeof(ST)); | ||
ASSERT(uint64_t(len)==uint64_t(offs)+compressed_size); | ||
|
||
len=uncompressed_size; | ||
uncompressed_size*=sizeof(ST); | ||
ST* vec=SG_MALLOC(ST, len); | ||
compressor->decompress((uint8_t*) (&f[offs]), compressed_size, | ||
(uint8_t*) vec, uncompressed_size); | ||
|
||
ASSERT(uncompressed_size==((uint64_t) len)*sizeof(ST)); | ||
return vec; | ||
} | ||
|
||
template <class ST> | ||
EPreprocessorType CDecompressString<ST>::get_type() const | ||
{ | ||
return P_DECOMPRESSSTRING; | ||
} | ||
|
||
template class CDecompressString<bool>; | ||
template class CDecompressString<char>; | ||
template class CDecompressString<int8_t>; | ||
template class CDecompressString<uint8_t>; | ||
template class CDecompressString<int16_t>; | ||
template class CDecompressString<uint16_t>; | ||
template class CDecompressString<int32_t>; | ||
template class CDecompressString<uint32_t>; | ||
template class CDecompressString<int64_t>; | ||
template class CDecompressString<uint64_t>; | ||
template class CDecompressString<float32_t>; | ||
template class CDecompressString<float64_t>; | ||
template class CDecompressString<floatmax_t>; | ||
} |
96 changes: 96 additions & 0 deletions
96
src/shogun/preprocessor/DimensionReductionPreprocessor.cpp
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,96 @@ | ||
#include <shogun/preprocessor/DimensionReductionPreprocessor.h> | ||
#include <shogun/kernel/GaussianKernel.h> | ||
#include <shogun/distance/EuclidianDistance.h> | ||
|
||
using namespace shogun; | ||
|
||
CDimensionReductionPreprocessor::CDimensionReductionPreprocessor() | ||
: CSimplePreprocessor<float64_t>() | ||
{ | ||
m_target_dim = 1; | ||
m_distance = new CEuclidianDistance(); | ||
m_distance->parallel = this->parallel; | ||
SG_REF(this->parallel); | ||
m_kernel = new CGaussianKernel(); | ||
m_kernel->parallel = this->parallel; | ||
SG_REF(this->parallel); | ||
|
||
init(); | ||
} | ||
|
||
CDimensionReductionPreprocessor::~CDimensionReductionPreprocessor() | ||
{ | ||
delete m_distance; | ||
SG_UNREF(this->parallel); | ||
delete m_kernel; | ||
SG_UNREF(this->parallel); | ||
} | ||
|
||
bool CDimensionReductionPreprocessor::init(CFeatures* data) | ||
{ | ||
return true; | ||
} | ||
|
||
void CDimensionReductionPreprocessor::cleanup() | ||
{ | ||
|
||
} | ||
|
||
SGMatrix<float64_t> CDimensionReductionPreprocessor::apply_to_feature_matrix(CFeatures* features) | ||
{ | ||
return ((CSimpleFeatures<float64_t>*)features)->get_feature_matrix(); | ||
}; | ||
|
||
SGVector<float64_t> CDimensionReductionPreprocessor::apply_to_feature_vector(SGVector<float64_t> vector) | ||
{ | ||
return vector; | ||
}; | ||
|
||
EPreprocessorType CDimensionReductionPreprocessor::get_type() const { return P_DIMENSIONREDUCTIONPREPROCESSOR; }; | ||
|
||
void CDimensionReductionPreprocessor::set_target_dim(int32_t dim) | ||
{ | ||
ASSERT(dim>0 || dim==AUTO_TARGET_DIM); | ||
m_target_dim = dim; | ||
} | ||
|
||
int32_t CDimensionReductionPreprocessor::get_target_dim() const | ||
{ | ||
return m_target_dim; | ||
} | ||
|
||
void CDimensionReductionPreprocessor::set_distance(CDistance* distance) | ||
{ | ||
SG_UNREF(m_distance->parallel); | ||
SG_UNREF(m_distance); | ||
SG_REF(distance); | ||
m_distance = distance; | ||
m_distance->parallel = this->parallel; | ||
SG_REF(this->parallel); | ||
} | ||
|
||
void CDimensionReductionPreprocessor::set_kernel(CKernel* kernel) | ||
{ | ||
SG_UNREF(m_kernel->parallel); | ||
SG_UNREF(m_kernel); | ||
SG_REF(kernel); | ||
m_kernel = kernel; | ||
m_kernel->parallel = this->parallel; | ||
SG_REF(this->parallel); | ||
} | ||
|
||
int32_t CDimensionReductionPreprocessor::detect_dim(SGMatrix<float64_t> distance_matrix) | ||
{ | ||
SG_NOTIMPLEMENTED; | ||
return 0; | ||
} | ||
|
||
void CDimensionReductionPreprocessor::init() | ||
{ | ||
m_parameters->add(&m_target_dim, "target_dim", | ||
"target dimensionality of preprocessor"); | ||
m_parameters->add((CSGObject**)&m_distance, "distance", | ||
"distance to be used for embedding"); | ||
m_parameters->add((CSGObject**)&m_kernel, "kernel", | ||
"kernel to be used for embedding"); | ||
} |
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,101 @@ | ||
#include <shogun/preprocessor/SimplePreprocessor.h> | ||
|
||
namespace shogun | ||
{ | ||
template <class ST> | ||
CSimplePreprocessor<ST>::CSimplePreprocessor() : CPreprocessor() | ||
{ | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<floatmax_t>::get_feature_type() | ||
{ | ||
return F_LONGREAL; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<float64_t>::get_feature_type() | ||
{ | ||
return F_DREAL; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<float32_t>::get_feature_type() | ||
{ | ||
return F_SHORTREAL; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<int16_t>::get_feature_type() | ||
{ | ||
return F_SHORT; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<uint16_t>::get_feature_type() | ||
{ | ||
return F_WORD; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<char>::get_feature_type() | ||
{ | ||
return F_CHAR; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<int8_t>::get_feature_type() | ||
{ | ||
return F_CHAR; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<uint8_t>::get_feature_type() | ||
{ | ||
return F_BYTE; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<int32_t>::get_feature_type() | ||
{ | ||
return F_INT; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<uint32_t>::get_feature_type() | ||
{ | ||
return F_UINT; | ||
} | ||
|
||
|
||
template<> EFeatureType CSimplePreprocessor<int64_t>::get_feature_type() | ||
{ | ||
return F_LONG; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<uint64_t>::get_feature_type() | ||
{ | ||
return F_ULONG; | ||
} | ||
|
||
template<> EFeatureType CSimplePreprocessor<bool>::get_feature_type() | ||
{ | ||
return F_BOOL; | ||
} | ||
|
||
template <class ST> | ||
EFeatureClass CSimplePreprocessor<ST>::get_feature_class() | ||
{ | ||
return C_SIMPLE; | ||
} | ||
|
||
template <class ST> | ||
EPreprocessorType CSimplePreprocessor<ST>::get_type() const | ||
{ | ||
return P_UNKNOWN; | ||
} | ||
|
||
template class CSimplePreprocessor<bool>; | ||
template class CSimplePreprocessor<char>; | ||
template class CSimplePreprocessor<int8_t>; | ||
template class CSimplePreprocessor<uint8_t>; | ||
template class CSimplePreprocessor<int16_t>; | ||
template class CSimplePreprocessor<uint16_t>; | ||
template class CSimplePreprocessor<int32_t>; | ||
template class CSimplePreprocessor<uint32_t>; | ||
template class CSimplePreprocessor<int64_t>; | ||
template class CSimplePreprocessor<uint64_t>; | ||
template class CSimplePreprocessor<float32_t>; | ||
template class CSimplePreprocessor<float64_t>; | ||
template class CSimplePreprocessor<floatmax_t>; | ||
} |