MINT2
HyperPoint.cpp
Go to the documentation of this file.
1 #include "Mint/HyperPoint.h"
2 #include <math.h>
3 
6 HyperPoint::HyperPoint(int dimension) :
7  _coords(dimension, 0.0)
8 {
9 }
10 
14 HyperPoint::HyperPoint(int dimension, double val) :
15  _coords(dimension, val)
16 {
17 }
18 
21 HyperPoint::HyperPoint(std::vector<double> coords) :
22  _coords(coords)
23 {
24 }
25 
29  _coords(1, 0.0)
30 {
31  at(0) = x1;
32 }
33 
36 HyperPoint::HyperPoint(double x1, double x2) :
37  _coords(2, 0.0)
38 {
39  at(0) = x1;
40  at(1) = x2;
41 }
42 
45 HyperPoint::HyperPoint(double x1, double x2, double x3) :
46  _coords(3, 0.0)
47 {
48  at(0) = x1;
49  at(1) = x2;
50  at(2) = x3;
51 }
52 
55 HyperPoint::HyperPoint(double x1, double x2, double x3, double x4) :
56  _coords(4, 0.0)
57 {
58  at(0) = x1;
59  at(1) = x2;
60  at(2) = x3;
61  at(3) = x4;
62 }
63 
66 HyperPoint::HyperPoint(double x1, double x2, double x3, double x4, double x5) :
67  _coords(5, 0.0)
68 {
69  at(0) = x1;
70  at(1) = x2;
71  at(2) = x3;
72  at(3) = x4;
73  at(4) = x5;
74 }
75 
76 HyperPoint::HyperPoint(double x1, double x2, double x3, double x4, double x5, double x6) :
77  _coords(6, 0.0)
78 {
79  at(0) = x1;
80  at(1) = x2;
81  at(2) = x3;
82  at(3) = x4;
83  at(4) = x5;
84  at(5) = x6;
85 }
86 
87 HyperPoint::HyperPoint(double x1, double x2, double x3, double x4, double x5, double x6, double x7) :
88  _coords(7, 0.0)
89 {
90  at(0) = x1;
91  at(1) = x2;
92  at(2) = x3;
93  at(3) = x4;
94  at(4) = x5;
95  at(5) = x6;
96  at(6) = x7;
97 }
98 
99 
100 
104  double total = 1.0;
105  for (int i = 0; i < size(); i++) total *= this->at(i);
106  return total;
107 }
108 
111 bool HyperPoint::compatible(const HyperPoint & other, bool printError) const{
112 
113  if (getDimension() != other.getDimension()) {
114  if (printError == true) ERROR_LOG << "HyperPoints are of different dimension i.e. not compatible!!!";
115  return 0;
116  }
117  return 1;
118 
119 }
120 
123 double HyperPoint::distanceTo(const HyperPoint & other) const{
124  if (this->compatible(other) == 0) return 0.0;
125  HyperPoint temp = other - *this;
126  return temp.norm();
127 }
128 
131 double HyperPoint::norm() const{
132  double normVal = 0.0;
133  for (int i = 0; i < size(); i++) normVal += at(i)*at(i);
134  return sqrt(normVal);
135 }
136 
139 double HyperPoint::norm2() const{
140  double normVal = 0.0;
141  for (int i = 0; i < size(); i++) normVal += at(i)*at(i);
142  return normVal;
143 }
144 
147 double HyperPoint::dotProduct(const HyperPoint & other) const{
148  if (this->compatible(other) == 0) return 0.0;
149 
150  double val = 0.0;
151  for (int i = 0; i < size(); i++) val += at(i)*other.at(i);
152  return val;
153 }
154 
157 void HyperPoint::fillRandom(double min, double max){
158 
159  for(int i = 0; i < size(); i++) at(i) = gRandom->Uniform(min,max);
160 }
161 
165  if (this->compatible(other) == 0) return *this;
166 
167  HyperPoint projection(*this);
168  double scale = this->dotProduct(other) / this->dotProduct(*this);
169  return (projection * scale);
170 }
171 
179  //if (this->compatible(other) == 0) return *this;
180 
181  _coords = other._coords;
182  _weights = other._weights;
183 
184  return *this;
185 }
186 
190 
191  if (this->compatible(other) == 0) return *this;
192 
193  HyperPoint temp(size());
194 
195  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) + other.at(i);
196 
197  return temp;
198 
199 }
200 
204 
205  if (this->compatible(other) == 0) return *this;
206 
207  HyperPoint temp(size());
208 
209  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) - other.at(i);
210 
211  return temp;
212 
213 }
214 
217 HyperPoint HyperPoint::operator- (const double & other) const{
218 
219  HyperPoint temp(size());
220 
221  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) - other;
222 
223  return temp;
224 
225 }
226 
229 HyperPoint HyperPoint::operator+ (const double & other) const{
230 
231  HyperPoint temp(size());
232 
233  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) + other;
234 
235  return temp;
236 
237 }
238 
241 HyperPoint HyperPoint::operator/ (const double & other) const{
242 
243  HyperPoint temp(size());
244 
245  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) / other;
246 
247  return temp;
248 
249 }
250 
253 HyperPoint HyperPoint::operator* (const double & other) const{
254 
255  HyperPoint temp(size());
256 
257  for (int i = 0; i < size(); i++) temp.at(i) = this->at(i) * other;
258 
259  return temp;
260 
261 }
262 
267 
268  HyperPoint point(getDimension());
269 
270  for (int i = 0; i < getDimension(); i++){
271  double val = 0.0;
272  for (int j = 0; j < getDimension(); j++){
273  val += at(j)*matrix(i,j);
274  }
275  point.at(i) = val;
276  }
277 
278  return point;
279 
280 }
281 
285 bool HyperPoint::operator <(const HyperPoint& other) const{
286  if (this->compatible(other) == 0) return false;
287 
288  for (int i = 0; i < size(); i++) {
289  if (this->at(i) < other.at(i)) return true;
290  if (this->at(i) > other.at(i)) return false;
291  }
292  return false;
293 }
294 
298 bool HyperPoint::operator >(const HyperPoint& other) const{
299  if (this->compatible(other) == 0) return false;
300 
301  for (int i = 0; i < size(); i++) {
302  if (this->at(i) < other.at(i)) return false;
303  if (this->at(i) > other.at(i)) return true;
304  }
305  return false;
306 }
307 
311 bool HyperPoint::operator <=(const HyperPoint& other) const{
312  if (this->compatible(other) == 0) return false;
313 
314  for (int i = 0; i < size(); i++) {
315  if (this->at(i) < other.at(i)) return true;
316  if (this->at(i) > other.at(i)) return false;
317  }
318  return true;
319 }
320 
324 bool HyperPoint::operator >=(const HyperPoint& other) const{
325  if (this->compatible(other) == 0) return false;
326 
327  for (int i = 0; i < size(); i++) {
328  if (this->at(i) < other.at(i)) return false;
329  if (this->at(i) > other.at(i)) return true;
330  }
331  return true;
332 }
333 
336 bool HyperPoint::allLT (const HyperPoint& other) const{
337  if (this->compatible(other) == 0) return false;
338 
339  for (int i = 0; i < size(); i++) {
340  if (this->at(i) >= other.at(i)) return false;
341  }
342  return true;
343 }
344 
347 bool HyperPoint::allGT (const HyperPoint& other) const{
348  if (this->compatible(other) == 0) return false;
349 
350  for (int i = 0; i < size(); i++) {
351  if (this->at(i) <= other.at(i)) return false;
352  }
353  return true;
354 }
355 
358 bool HyperPoint::allLTOE(const HyperPoint& other) const{
359  if (this->compatible(other) == 0) return false;
360 
361  for (int i = 0; i < size(); i++) {
362  if (this->at(i) > other.at(i)) return false;
363  }
364  return true;
365 }
366 
369 bool HyperPoint::allGTOE(const HyperPoint& other) const{
370  if (this->compatible(other) == 0) return false;
371 
372  for (int i = 0; i < size(); i++) {
373  if (this->at(i) < other.at(i)) return false;
374  }
375  return true;
376 }
377 
380 bool HyperPoint::operator ==(const HyperPoint& other) const{
381  if (this->compatible(other) == 0) return false;
382 
383  for (int i = 0; i < size(); i++) if (this->at(i) != other.at(i)) return false;
384  return true;
385 }
386 
389 bool HyperPoint::operator !=(const HyperPoint& other) const{
390  if (this->compatible(other) == 0) return false;
391 
392  for (int i = 0; i < size(); i++) if (this->at(i) != other.at(i)) return true;
393  return false;
394 }
395 
398 bool HyperPoint::operator <(const double& other) const{
399  for (int i = 0; i < size(); i++) if ((this->at(i) < other)==0) return false;
400  return true;
401 }
402 
405 bool HyperPoint::operator >(const double& other) const{
406  for (int i = 0; i < size(); i++) if ((this->at(i) > other)==0) return false;
407  return true;
408 }
409 
412 bool HyperPoint::operator <=(const double& other) const{
413  for (int i = 0; i < size(); i++) if ((this->at(i) <= other)==0) return false;
414  return true;
415 }
416 
419 bool HyperPoint::operator >=(const double& other) const{
420  for (int i = 0; i < size(); i++) if ((this->at(i) >= other)==0) return false;
421  return true;
422 }
423 
426 bool HyperPoint::operator ==(const double& other) const{
427  for (int i = 0; i < size(); i++) if ((this->at(i) == other)==0) return false;
428  return true;
429 }
430 
433 const double& HyperPoint::at (int i) const{
434  if (i >= this->size()) {
435  ERROR_LOG << "The component of this HyperPoint you have selected is out of range";
436  return _coords.at(this->size() - 1);
437  }
438  return _coords.at(i);
439 }
440 
443 double& HyperPoint::at (int i){
444  if (i >= size()) {
445  ERROR_LOG << "The component of this HyperPoint you have selected is out of range";
446  return _coords.at(size() - 1);
447  }
448  return _coords.at(i);
449 }
450 
453 void HyperPoint::print(std::ostream& os, int endline) const{
454 
455  std::ostringstream oss;
456 
457  oss << "( ";
458  for(int i = 0; i < (size() - 1); i++){
459  oss << std::setw(10) << std::left << _coords.at(i) << ", ";
460  }
461  if (size() != 0) oss << std::setw(10) << std::left << _coords.at(size() - 1);
462  oss << ")";
463 
464  this->printWeight(oss, 0);
465 
466  if (endline) oss << std::endl;
467 
468  os << oss.str();
469 }
470 
471 std::ostream& operator<<(std::ostream& os, const HyperPoint& point) {
472  point.print(os, 0);
473  return os;
474 }
475 
479 }
480 
481 
void fillRandom(double min=-1.0, double max=1.0)
Definition: HyperPoint.cpp:157
bool allLTOE(const HyperPoint &other) const
Definition: HyperPoint.cpp:358
bool allGT(const HyperPoint &other) const
Definition: HyperPoint.cpp:347
HyperPoint(int dimension)
Definition: HyperPoint.cpp:6
int size() const
Definition: HyperPoint.h:96
virtual void print(std::ostream &os=std::cout, int endline=1) const
Definition: HyperPoint.cpp:453
double dotProduct(const HyperPoint &other) const
Definition: HyperPoint.cpp:147
HyperPoint operator *(const double &other) const
Definition: HyperPoint.cpp:253
bool allLT(const HyperPoint &other) const
Definition: HyperPoint.cpp:336
bool operator >(const HyperPoint &other) const
Definition: HyperPoint.cpp:298
#define ERROR_LOG
HyperPoint & operator=(const HyperPoint &other)
Definition: HyperPoint.cpp:178
std::ostream & operator<<(std::ostream &os, const HyperPoint &point)
Definition: HyperPoint.cpp:471
bool operator==(const HyperPoint &other) const
Definition: HyperPoint.cpp:380
bool operator !=(const HyperPoint &other) const
Definition: HyperPoint.cpp:389
HyperPoint operator-(const HyperPoint &other) const
Definition: HyperPoint.cpp:203
std::vector< double > _coords
Definition: HyperPoint.h:30
bool compatible(const HyperPoint &other, bool printError=true) const
Definition: HyperPoint.cpp:111
double multiplyElements() const
Definition: HyperPoint.cpp:103
HyperPoint operator+(const HyperPoint &other) const
Definition: HyperPoint.cpp:189
bool operator >=(const HyperPoint &other) const
Definition: HyperPoint.cpp:324
const double & at(int i) const
Definition: HyperPoint.cpp:433
std::vector< double > _weights
Definition: Weights.h:27
bool operator<=(const HyperPoint &other) const
Definition: HyperPoint.cpp:311
HyperPoint project(const HyperPoint &other) const
Definition: HyperPoint.cpp:164
double norm2() const
Definition: HyperPoint.cpp:139
void printWeight(std::ostream &os=std::cout, int endline=1) const
Definition: Weights.cpp:26
bool operator<(const HyperPoint &other) const
Definition: HyperPoint.cpp:285
HyperPoint operator/(const double &other) const
Definition: HyperPoint.cpp:241
int getDimension() const
Definition: HyperPoint.h:99
double distanceTo(const HyperPoint &other) const
Definition: HyperPoint.cpp:123
HyperPoint linearTransformation(const TMatrixD &matrix)
Definition: HyperPoint.cpp:266
bool allGTOE(const HyperPoint &other) const
Definition: HyperPoint.cpp:369
double norm() const
Definition: HyperPoint.cpp:131