8 template <
class ScalarType>
void sphere_log_map(
const std::vector <ScalarType> &p,
const std::vector <ScalarType> &x,
9 std::vector <ScalarType> &logValue)
11 unsigned int sizeVec = p.size();
12 if (logValue.size() != sizeVec)
13 logValue.resize(sizeVec);
15 for (
unsigned int i = 0;i < sizeVec;++i)
19 for (
unsigned int i = 0;i < sizeVec;++i)
25 if (dotProd <= -1 + 1.0e-8)
26 dotProd = -1 + 1.0e-8;
28 for (
unsigned int i = 0;i < sizeVec;++i)
29 logValue[i] = (p[i] - x[i]*dotProd)*std::acos(dotProd)/std::sqrt(1.0 - dotProd*dotProd);
32 template <
class ScalarType>
void sphere_exp_map(
const std::vector <ScalarType> &p,
const std::vector <ScalarType> &x,
33 std::vector <ScalarType> &expValue)
35 unsigned int sizeVec = p.size();
36 if (expValue.size() != sizeVec)
37 expValue.resize(sizeVec);
40 for (
unsigned int i = 0;i < sizeVec;++i)
43 normP = std::sqrt(normP);
51 for (
unsigned int i = 0;i < sizeVec;++i)
52 expValue[i] = std::cos(normP)*x[i] + p[i]*std::sin(normP)/normP;
56 std::vector <ScalarType> ¢roidValue,
const std::vector <ScalarType> &initPoint,
57 const std::vector <ScalarType> &weights, std::vector <ScalarType> *workLogVector,
58 std::vector <ScalarType> *workVector,
double tol)
60 unsigned int sizeData = dataPoints.size();
61 unsigned int sizeVec = initPoint.size();
62 centroidValue = initPoint;
64 bool internalLogVector =
false;
65 bool internalVector =
false;
68 workLogVector =
new std::vector <ScalarType> (sizeVec);
69 internalLogVector =
true;
72 if (workLogVector->size() != sizeVec)
73 workLogVector->resize(sizeVec);
77 workVector =
new std::vector <ScalarType> (sizeVec);
78 internalVector =
true;
81 if (workVector->size() != sizeVec)
82 workVector->resize(sizeVec);
84 double sumWeights = 0;
85 for (
unsigned int i = 0;i < sizeData;++i)
86 sumWeights += weights[i];
88 double diffNewOld = tol + 1;
90 while (diffNewOld > tol)
92 for (
unsigned int j = 0;j < sizeVec;++j)
93 (*workLogVector)[j] = 0;
95 for (
unsigned int i = 0;i < sizeData;++i)
99 for (
unsigned int j = 0;j < sizeVec;++j)
100 (*workLogVector)[j] += weights[i]*(*workVector)[j];
103 for (
unsigned int j = 0;j < sizeVec;++j)
104 (*workLogVector)[j] /= sumWeights;
110 for (
unsigned int j = 0;j < sizeVec;++j)
111 diffNewOld += (centroidValue[j]-(*workVector)[j])*(centroidValue[j]-(*workVector)[j]);
113 diffNewOld = std::sqrt(diffNewOld);
115 centroidValue = (*workVector);
118 if (internalLogVector)
119 delete workLogVector;
void sphere_exp_map(const std::vector< ScalarType > &p, const std::vector< ScalarType > &x, std::vector< ScalarType > &expValue)
void sphere_log_map(const std::vector< ScalarType > &p, const std::vector< ScalarType > &x, std::vector< ScalarType > &logValue)
void ComputeSphericalCentroid(const std::vector< std::vector< ScalarType > > &dataPoints, std::vector< ScalarType > ¢roidValue, const std::vector< ScalarType > &initPoint, const std::vector< ScalarType > &weights, std::vector< ScalarType > *workLogVector=0, std::vector< ScalarType > *workVector=0, double tol=1.0e-4)