PROBI  1.0
 All Classes Functions
EuclideanSpace.hpp
1 #ifndef EUCLIDEANSPACE_H
2 #define EUCLIDEANSPACE_H
3 
4 #include <vector>
5 #include <memory>
6 #include <cmath>
7 #include <functional>
8 
9 #include "Point.hpp"
10 #include "Norm.hpp"
11 
16 {
17 public:
18  EuclideanSpace(std::function<Norm<Point>*()> createNorm);
19 
20  template<typename InputIterator>
21  std::unique_ptr<std::vector<Point>> orthonormalize(InputIterator begin, InputIterator end);
22 
23 private:
24  Norm<Point>* norm;
25 };
26 
27 
28 template<typename InputIterator>
29 std::unique_ptr<std::vector<Point>> EuclideanSpace::orthonormalize(InputIterator begin, InputIterator end)
30 {
31  std::unique_ptr<std::vector<Point>> basis(new std::vector<Point>());
32  auto proj = [](Point const & u, Point const & v) -> Point
33  {
34  return ((u*v) * (1/(u*u))) * u;
35  };
36 
37  // Normalize vectors
38  int dim = 0;
39  while(begin != end)
40  {
41  Point p(*begin);
42  for(int i = 0; i < dim; ++i)
43  p = p - proj((*basis)[i], p);
44  // Check for linear dependency
45  if(norm->length(p) > 0.000001)
46  {
47  p = (1 / norm->length(p)) * p;
48  basis->push_back(p);
49  ++dim;
50  }
51  ++begin;
52  }
53 
54  return basis;
55 }
56 
57 #endif