6 template <
class dataType>
8 std::vector<dataType> &distances) {
9 dataType variance = 0.0;
10 for(
auto distance : distances)
11 variance += distance * distance;
12 return variance / distances.size();
15 template <
class dataType>
19 std::vector<std::vector<double>> &v,
20 std::vector<std::vector<double>> &v2,
21 std::vector<double> &ts,
22 bool globalVariance) {
24 std::vector<ftm::MergeTree<dataType>> allInterpolated(trees.size());
26 if(not globalVariance) {
27 for(
unsigned int i = 0; i < trees.size(); ++i)
28 getInterpolation<dataType>(
29 barycenter, v, v2, ts[i], allInterpolated[i]);
30 computeOneBarycenter<dataType>(allInterpolated, barycenterInterpolated);
33 std::vector<dataType> distances(trees.size());
34#ifdef TTK_ENABLE_OPENMP
35#pragma omp parallel for schedule(dynamic) \
36 num_threads(this->threadNumber_) if(parallelize_)
38 for(
unsigned int i = 0; i < trees.size(); ++i) {
43 barycenterInterpolated, allInterpolated[i], distances[i],
true);
49 template <
class dataType>
53 std::vector<double> ts;
54 std::vector<std::vector<double>> v, v2;
55 return computeExplainedVariance<dataType>(
56 barycenter, trees, v, v2, ts,
true);
59 template <
class dataType>
63 std::vector<std::vector<std::vector<double>>> &vS,
64 std::vector<std::vector<std::vector<double>>> &v2s,
65 std::vector<std::vector<double>> &ts) {
66 std::vector<ftm::MergeTree<dataType>> allInterpolated(trees.size());
68 for(
unsigned int i = 0; i < trees.size(); ++i) {
69 std::vector<double> treeTs(ts.size());
70 for(
unsigned int j = 0; j < ts.size(); ++j)
72 getMultiInterpolation<dataType>(
73 barycenter, vS, v2s, treeTs, allInterpolated[i]);
75 computeOneBarycenter<dataType>(allInterpolated, barycenterInterpolated);
77 std::vector<dataType> distances(trees.size());
78#ifdef TTK_ENABLE_OPENMP
79#pragma omp parallel for schedule(dynamic) \
80 num_threads(this->threadNumber_) if(parallelize_)
82 for(
unsigned int i = 0; i < trees.size(); ++i) {
84 barycenterInterpolated, allInterpolated[i], distances[i],
true);
89 template <
class dataType>
92 std::vector<std::vector<double>> &v,
93 std::vector<std::vector<double>> &v2,
94 std::vector<double> &ts,
95 std::vector<double> &distances,
102 computeOneDistance<dataType>(
103 extremity1, extremity2, distance,
false, useDoubleInput, isFirstInput);
105 double tBarycenter = 0.0;
107 tBarycenter += t / ts.size();
109 distances.resize(ts.size());
110 for(
unsigned int i = 0; i < ts.size(); ++i)
111 distances[i] = (ts[i] - tBarycenter) * distance;
114 template <
class dataType>
117 std::vector<std::vector<double>> &v,
118 std::vector<std::vector<double>> &v2,
119 std::vector<double> &ts) {
120 std::vector<double> distances;
125 template <
class dataType>
128 std::vector<std::vector<double>> &v,
129 std::vector<std::vector<double>> &v2,
131 std::vector<std::vector<double>> &trees2V,
132 std::vector<std::vector<double>> &trees2V2,
133 std::vector<double> &ts) {
134 std::vector<double> distances, distances2;
137 barycenter2, trees2V, trees2V2, ts, distances2,
true,
false);
138 for(
unsigned int i = 0; i < distances.size(); ++i)
139 distances[i] =
mixDistances(distances[i], distances2[i]);
void computeOneDistance(ftm::MergeTree< dataType > &tree1, ftm::MergeTree< dataType > &tree2, std::vector< std::tuple< ftm::idNode, ftm::idNode, double > > &matching, dataType &distance, bool isCalled=false, bool useDoubleInput=false, bool isFirstInput=true)
double mixDistances(dataType distance1, dataType distance2)
void getInterpolation(ftm::MergeTree< dataType > &barycenter, std::vector< double * > &v, std::vector< double * > &v2, size_t vSize, double t, ftm::MergeTree< dataType > &interpolated, bool transposeVector=true)
void computeProjectionDistances(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts, std::vector< double > &distances, bool useDoubleInput=false, bool isFirstInput=true)
double computeExplainedVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts, bool computeGlobalVariance=false)
dataType computeVarianceFromDistances(std::vector< dataType > &distances)
double computeSurfaceExplainedVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees, std::vector< std::vector< std::vector< double > > > &vS, std::vector< std::vector< std::vector< double > > > &v2s, std::vector< std::vector< double > > &ts)
double computeExplainedVarianceT(ftm::MergeTree< dataType > &barycenter, std::vector< std::vector< double > > &v, std::vector< std::vector< double > > &v2, std::vector< double > &ts)
double computeGlobalVariance(ftm::MergeTree< dataType > &barycenter, std::vector< ftm::MergeTree< dataType > > &trees)