SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
JLCoverTreePoint.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2012 Fernando José Iglesias García
8  * Written (W) John Langford and Dinoj Surendran, v_array and its templatization
9  * Copyright (C) 2012 Fernando José Iglesias García
10  */
11 
12 #ifndef _JLCTPOINT_H__
13 #define _JLCTPOINT_H__
14 
15 #include <shogun/lib/config.h>
18 
19 namespace shogun
20 {
21 
23 template<class T>
24 class v_array{
25 
26  public:
29  T last() { return elements[index-1];}
30 
32  void decr() { index--;}
33 
35  v_array() { index = 0; length=0; elements = NULL;}
36 
40  T& operator[](unsigned int i) { return elements[i]; }
41 
42  public:
44  int index;
45 
47  int length;
48 
51 
52 };
53 
60 template<class T>
61 void push(v_array<T>& v, const T &new_ele)
62 {
63  while(v.index >= v.length)
64  {
65  v.length = 2*v.length + 3;
66  v.elements = (T *)realloc(v.elements,sizeof(T) * v.length);
67  }
68  v[v.index++] = new_ele;
69 }
70 
77 template<class T>
78 void alloc(v_array<T>& v, int length)
79 {
80  v.elements = (T *)realloc(v.elements, sizeof(T) * length);
81  v.length = length;
82 }
83 
93 template<class T>
95 {
96  if (stack.index > 0)
97  return stack[--stack.index];
98  else
99  return v_array<T>();
100 }
101 
108 {
109  FC_LHS = 0,
110  FC_RHS = 1,
111 };
112 
119 {
120 
121  public:
122 
126 
128  int32_t m_index;
129 
132 
133 }; /* class JLCoverTreePoint */
134 
139 {
144  {
145  if ( ! p1.m_distance->lhs_equals_rhs() )
146  {
147  SG_SERROR("lhs != rhs but the distance of two points "
148  "from the same container has been requested\n");
149  }
150  else
151  {
153  p2.m_index, upper_bound);
154  }
155  }
156  else
157  {
158  if ( p1.m_distance->lhs_equals_rhs() )
159  {
160  SG_SERROR("lhs == rhs but the distance of two points "
161  "from different containers has been requested\n");
162  }
163  else
164  {
165  if ( p1.m_features_container == FC_LHS )
166  {
168  p2.m_index, upper_bound);
169  }
170  else
171  {
173  p1.m_index, upper_bound);
174  }
175  }
176  }
177 
178  SG_SERROR("Something has gone wrong, case not handled\n")
179  return -1;
180 }
181 
184 {
185  CFeatures* features;
186  if ( fc == FC_LHS )
187  features = distance->get_lhs();
188  else
189  features = distance->get_rhs();
190 
192  for ( int32_t i = 0 ; i < features->get_num_vectors() ; ++i )
193  {
194  CJLCoverTreePoint new_point;
195 
196  new_point.m_distance = distance;
197  new_point.m_index = i;
198  new_point.m_features_container = fc;
199 
200  push(parsed, new_point);
201  }
202 
203  return parsed;
204 }
205 
208 {
209  SG_SERROR("Print JLCoverTreePoint not implemented\n")
210 }
211 
212 } /* namespace shogun */
213 
214 #endif /* _JLCTPOINT_H__*/
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
Class Distance, a base class for all the distances used in the Shogun toolbox.
Definition: Distance.h:87
CFeatures * get_lhs()
Definition: Distance.h:224
Class v_array taken directly from JL's implementation.
virtual int32_t get_num_vectors() const =0
unsigned int index()
Definition: v_array.h:107
CFeatures * get_rhs()
Definition: Distance.h:230
virtual float64_t distance_upper_bounded(int32_t idx_a, int32_t idx_b, float64_t upper_bound)
Definition: Distance.h:124
v_array< T > pop(v_array< v_array< T > > &stack)
Class Point to use with John Langford's CoverTree. This class must have some assoficated functions de...
v_array< CJLCoverTreePoint > parse_points(CDistance *distance, EFeaturesContainer fc)
void push(v_array< T > &v, const T &new_ele)
bool lhs_equals_rhs()
Definition: Distance.h:339
EFeaturesContainer m_features_container
void print(CJLCoverTreePoint &p)
void alloc(v_array< T > &v, int length)
double float64_t
Definition: common.h:50
T & operator[](unsigned int i)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
#define SG_SERROR(...)
Definition: SGIO.h:179

SHOGUN Machine Learning Toolbox - Documentation