11 #ifndef _CUSTOMDISTANCE_H___ 12 #define _CUSTOMDISTANCE_H___ 58 const float64_t* dm, int32_t rows, int32_t cols);
71 const float32_t* dm, int32_t rows, int32_t cols);
85 virtual bool dummy_init(int32_t rows, int32_t cols);
120 virtual const char*
get_name()
const {
return "CustomDistance"; }
166 const T* dm, int64_t len)
171 int64_t cols = (int64_t) floor(-0.5 +
CMath::sqrt(0.25+2*len));
173 int64_t int32_max=2147483647;
176 SG_ERROR(
"Matrix larger than %d x %d\n", int32_max)
178 if (cols*(cols+1)/2 != len)
180 SG_ERROR(
"dm should be a vector containing a lower triangle matrix, with len=cols*(cols+1)/2 elements\n")
185 SG_DEBUG(
"using custom distance of size %dx%d\n", cols,cols)
193 for (int64_t i=0; i<len; i++)
211 const float64_t* dm, int32_t rows, int32_t cols)
227 const float32_t* dm, int32_t rows, int32_t cols)
242 const T* dm, int32_t rows, int32_t cols)
247 SG_DEBUG(
"using custom distance of size %dx%d\n", cols,cols)
255 for (int64_t row=0; row<
num_rows; row++)
257 for (int64_t col=row; col<
num_cols; col++)
259 int64_t idx=row * num_cols - row*(row+1)/2 + col;
277 const float64_t* dm, int32_t rows, int32_t cols)
292 const float32_t* dm, int32_t rows, int32_t cols)
308 SG_DEBUG(
"using custom distance of size %dx%d\n", rows,cols)
316 for (int32_t row=0; row<
num_rows; row++)
318 for (int32_t col=0; col<
num_cols; col++)
320 dmatrix[row * num_cols + col]=dm[col*num_rows+row];
368 void cleanup_custom();
bool set_triangle_distance_matrix_from_full(const float64_t *dm, int32_t rows, int32_t cols)
virtual float64_t compute(int32_t row, int32_t col)
bool set_triangle_distance_matrix_from_triangle(const float32_t *dm, int32_t len)
Class Distance, a base class for all the distances used in the Shogun toolbox.
virtual int32_t get_num_vec_lhs()
virtual bool dummy_init(int32_t rows, int32_t cols)
bool set_triangle_distance_matrix_from_full_generic(const T *dm, int32_t rows, int32_t cols)
EFeatureClass
shogun feature class
virtual int32_t get_num_vec_rhs()
bool set_triangle_distance_matrix_from_triangle_generic(const T *dm, int64_t len)
bool set_full_distance_matrix_from_full(const float64_t *dm, int32_t rows, int32_t cols)
virtual EFeatureClass get_feature_class()
EFeatureType
shogun feature type
bool set_triangle_distance_matrix_from_full(const float32_t *dm, int32_t rows, int32_t cols)
virtual EFeatureType get_feature_type()
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
bool set_full_distance_matrix_from_full_generic(const T *dm, int32_t rows, int32_t cols)
virtual ~CCustomDistance()
virtual bool init(CFeatures *l, CFeatures *r)
The Custom Distance allows for custom user provided distance matrices.
static float32_t sqrt(float32_t x)
x^0.5
virtual bool has_features()
bool set_full_distance_matrix_from_full(const float32_t *dm, int32_t rows, int32_t cols)
virtual EDistanceType get_distance_type()
bool set_triangle_distance_matrix_from_triangle(const float64_t *dm, int32_t len)
virtual const char * get_name() const