12 #include <shogun/lib/config.h> 80 REQUIRE(l,
"Left hand side features must be set!\n");
81 REQUIRE(r,
"Right hand side features must be set!\n");
84 "Right hand side of features (%s) must be of same type with left hand side features (%s)\n",
90 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
96 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
102 "Right hand side of features (%s) must be compatible with left hand side features (%s)\n",
185 REQUIRE(idx_a < lhs->get_num_vectors() && idx_b < rhs->get_num_vectors() && \
186 idx_a >= 0 && idx_b >= 0,
187 "idx_a (%d) must be in [0,%d] and idx_b (%d) must be in [0,%d]\n",
197 if (idx_a>=num_vectors)
198 idx_a=2*num_vectors-1-idx_a;
200 if (idx_b>=num_vectors)
201 idx_b=2*num_vectors-1-idx_b;
221 for(
index_t i=idx_r_start; idx_start < idx_stop; ++i,++idx_start)
222 result.
vector[i] = this->distance(idx_a,idx_start);
227 for(
index_t i=idx_r_start; idx_start < idx_stop; ++i,++idx_start)
228 result.
vector[i] = this->distance(idx_start,idx_b);
235 SG_INFO(
"precomputing distance matrix (%ix%i)\n", num_left, num_right)
237 ASSERT(num_left==num_right)
239 int32_t num=num_left;
244 for (int32_t i=0; i<num; i++)
247 for (int32_t j=0; j<=i; j++)
255 void CDistance::init()
265 "Feature vectors to occur on left hand side.");
267 "Feature vectors to occur on right hand side.");
280 int64_t total_num = int64_t(m)*n;
282 int64_t total_start=0;
283 int64_t total_end=total_num;
286 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
288 SG_DEBUG(
"returning distance matrix of size %dx%d\n", m, n)
290 result=SG_MALLOC(T, total_num);
294 #pragma omp parallel shared(num_threads, step) 299 num_threads=omp_get_num_threads();
300 step=total_num/num_threads;
303 int32_t thread_num=omp_get_thread_num();
307 int32_t thread_num=0;
309 bool verbose=(thread_num == 0);
312 int32_t end=(thread_num==num_threads) ? m :
compute_row_start((thread_num+1)*step, n, symmetric);
314 for (int32_t i=start; i<end; i++)
321 for (int32_t j=j_start; j<n; j++)
326 if (symmetric && i!=j)
333 if (symmetric && i!=j)
virtual const char * get_name() const =0
void do_precompute_matrix()
matrix precomputation
virtual bool has_features()
virtual bool get_feature_class_compatibility(EFeatureClass rhs) const
virtual int32_t get_num_vec_lhs()
virtual CFeatures * replace_lhs(CFeatures *lhs)
virtual void remove_lhs()
takes all necessary steps if the lhs is removed from distance matrix
virtual int32_t get_num_vectors() const =0
void run_distance_rhs(SGVector< float64_t > &result, const index_t idx_r_start, index_t idx_start, const index_t idx_stop, const index_t idx_a)
virtual bool check_compatibility(CFeatures *l, CFeatures *r)
void add(bool *param, const char *name, const char *description="")
Class SGObject is the base class of all shogun objects.
#define SG_OBJ_PROGRESS(o,...)
virtual void remove_lhs_and_rhs()
A File access base class.
virtual EFeatureClass get_feature_class() const =0
void run_distance_lhs(SGVector< float64_t > &result, const index_t idx_r_start, index_t idx_start, const index_t idx_stop, const index_t idx_b)
virtual int32_t get_num_vec_rhs()
static bool cancel_computations()
virtual CFeatures * replace_rhs(CFeatures *rhs)
int32_t compute_row_start(int64_t offs, int32_t n, bool symmetric)
virtual float64_t distance(int32_t idx_a, int32_t idx_b)
all of classes and functions are contained in the shogun namespace
virtual bool support_compatible_class() const
CFeatures * lhs
feature vectors to occur on the left hand side
The class Features is the base class of all feature objects.
CFeatures * rhs
feature vectors to occur on the right hand side
SGMatrix< float64_t > get_distance_matrix()
float32_t * precomputed_matrix
virtual bool init(CFeatures *lhs, CFeatures *rhs)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from distance matrix
virtual float64_t compute(int32_t idx_a, int32_t idx_b)=0
virtual EFeatureType get_feature_type() const =0