TTK
Loading...
Searching...
No Matches
PDBarycenter.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#include <KDTree.h>
20
21#include <limits>
22
23namespace ttk {
24
25 class PDBarycenter : public Debug {
26
27 public:
29 threadNumber_ = 1;
30 this->setDebugMsgPrefix("PersistenceDiagramBarycenter");
31 }
32
33 ~PDBarycenter() override = default;
34
35 std::vector<std::vector<MatchingType>> execute(DiagramType &barycenter);
36 std::vector<std::vector<MatchingType>>
38 std::vector<std::vector<MatchingType>>
40 std::vector<std::vector<MatchingType>>
42
43 void setBidderDiagrams();
45 double previous_min_persistence,
46 double min_persistence,
47 std::vector<double> &initial_diagonal_prices,
48 std::vector<double> &initial_off_diagonal_prices,
49 int min_points_to_add,
50 bool add_points_to_barycenter = true);
51 void setInitialBarycenter(double min_persistence);
52 double getMaxPersistence();
53 double getLowestPersistence();
54 double getMinimalPrice(int i);
55
58 = std::pair<typename KDT::KDTreeRoot, typename KDT::KDTreeMap>;
59 KDTreePair getKDTree() const;
60
61 void runMatching(double *total_cost,
62 double epsilon,
63 std::vector<int> &sizes,
64 KDT &kdt,
65 std::vector<KDT *> &correspondence_kdt_map,
66 std::vector<double> *min_diag_price,
67 std::vector<double> *min_price,
68 std::vector<std::vector<MatchingType>> *all_matchings,
69 bool use_kdt,
70 bool actual_distance);
71
72 void
73 runMatchingAuction(double *total_cost,
74 std::vector<int> &sizes,
75 KDT &kdt,
76 std::vector<KDT *> &correspondence_kdt_map,
77 std::vector<double> *min_diag_price,
78 std::vector<std::vector<MatchingType>> *all_matchings,
79 bool use_kdt,
80 bool actual_distance);
81
82 double updateBarycenter(std::vector<std::vector<MatchingType>> &matchings);
83
84 double computeRealCost();
85 bool isPrecisionObjectiveMet(double, int);
87 std::vector<std::vector<MatchingType>> &matchings,
88 std::vector<std::vector<MatchingType>> &previous_matchings);
89 std::vector<std::vector<MatchingType>> correctMatchings(
90 std::vector<std::vector<MatchingType>> &previous_matchings);
91
93
94 double getEpsilon(double rho);
95 double getRho(double epsilon);
96
97 inline void setDeterministic(const bool deterministic) {
98 deterministic_ = deterministic;
99 }
100
101 inline void setMethod(const int &method) {
102 if(method == 0) {
103 method_ = "Partial Bidding";
104 }
105 if(method == 1) {
106 method_ = "Munkres";
107 } else if(method == 2) {
108 method_ = "Auction";
109 }
110 }
111
112 inline int setDiagrams(std::vector<DiagramType> *data) {
113 inputDiagrams_ = data;
114 return 0;
115 }
116
117 inline int setNumberOfInputs(int numberOfInputs) {
118 numberOfInputs_ = numberOfInputs;
119 // precision_objective_.resize(numberOfInputs_);
121 return 0;
122 }
123
124 inline void setWasserstein(const int &wasserstein) {
125 wasserstein_ = wasserstein;
126 }
127
128 inline void setUseProgressive(const bool use_progressive) {
129 use_progressive_ = use_progressive;
130 }
131
132 inline void setGeometricalFactor(const double geometrical_factor) {
133 geometrical_factor_ = geometrical_factor;
134 }
135
136 inline void setLambda(const double lambda) {
137 lambda_ = lambda;
138 }
139
140 inline void setCurrentBidders(std::vector<BidderDiagram> &diagrams) {
141 current_bidder_diagrams_ = diagrams;
142 }
143
144 inline void setCurrentBarycenter(std::vector<GoodDiagram> &barycenters) {
145 barycenter_goods_ = barycenters;
146 }
147
148 inline std::vector<BidderDiagram> &getCurrentBidders() {
150 }
151
152 inline std::vector<GoodDiagram> &getCurrentBarycenter() {
153 return barycenter_goods_;
154 }
155
156 inline void setReinitPrices(const bool reinit_prices) {
157 reinit_prices_ = reinit_prices;
158 }
159
160 inline void setEpsilonDecreases(const bool epsilon_decreases) {
161 epsilon_decreases_ = epsilon_decreases;
162 }
163
164 inline void setEarlyStoppage(const bool early_stoppage) {
165 early_stoppage_ = early_stoppage;
166 }
167
168 inline void setDiagramType(const int &diagramType) {
169 diagramType_ = diagramType;
170 if(diagramType_ == 0) {
173 } else if(diagramType_ == 1) {
176 } else {
179 }
180 }
181
182 inline void setNonMatchingWeight(double nonMatchingWeight) {
183 nonMatchingWeight_ = nonMatchingWeight;
184 }
185
186 double getCost() {
187 return cost_;
188 }
189
190 inline void setDeltaLim(double delta_lim) {
191 delta_lim_ = delta_lim;
192 }
193
194 protected:
195 // std::vector<bool> precision_objective_;
196 std::vector<double> precision_;
197
198 double delta_lim_{0.01};
199
200 // to kill any randomness
201 bool deterministic_{false};
202
203 std::string method_{"Partial Bidding"};
205 double nonMatchingWeight_ = 1.0;
206
208
209 // lambda_ : 0<=lambda<=1
210 // parametrizes the point used for the physical (critical) coordinates of
211 // the persistence paired lambda_ = 1 : extremum (min if pair min-sad, max
212 // if pair sad-max) lambda_ = 0 : saddle (awful stability) lambda_ = 1/2 :
213 // middle of the 2 critical points of the pair (bad stability)
214 double lambda_;
215
219 double cost_;
222 double epsilon_min_{1e-5};
223 std::vector<DiagramType> *inputDiagrams_;
224
227
228 std::vector<std::vector<double>> all_matchings_;
229 std::vector<std::vector<double>> all_old_matchings_;
230 std::vector<BidderDiagram> bidder_diagrams_;
231 std::vector<BidderDiagram> current_bidder_diagrams_;
232 std::vector<std::vector<int>> current_bidder_ids_;
233 std::vector<GoodDiagram> barycenter_goods_;
234
235 bool reinit_prices_{true};
237 bool early_stoppage_{true};
238 };
239} // namespace ttk
Minimalist debugging class.
Definition Debug.h:88
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
TTK KD-Tree.
Definition KDTree.h:21
std::vector< std::vector< MatchingType > > executeAuctionBarycenter(DiagramType &barycenter)
std::vector< GoodDiagram > & getCurrentBarycenter()
std::vector< std::vector< MatchingType > > executePartialBiddingBarycenter(DiagramType &barycenter)
std::vector< double > precision_
bool is_matching_stable()
void setEarlyStoppage(const bool early_stoppage)
ttk::CriticalType nt1_
~PDBarycenter() override=default
void setGeometricalFactor(const double geometrical_factor)
double getEpsilon(double rho)
int setDiagrams(std::vector< DiagramType > *data)
void runMatching(double *total_cost, double epsilon, std::vector< int > &sizes, KDT &kdt, std::vector< KDT * > &correspondence_kdt_map, std::vector< double > *min_diag_price, std::vector< double > *min_price, std::vector< std::vector< MatchingType > > *all_matchings, bool use_kdt, bool actual_distance)
std::pair< typename KDT::KDTreeRoot, typename KDT::KDTreeMap > KDTreePair
std::vector< std::vector< double > > all_old_matchings_
void setCurrentBarycenter(std::vector< GoodDiagram > &barycenters)
ttk::CriticalType nt2_
std::vector< GoodDiagram > barycenter_goods_
void setWasserstein(const int &wasserstein)
void setEpsilonDecreases(const bool epsilon_decreases)
void setDeltaLim(double delta_lim)
double getRho(double epsilon)
std::vector< BidderDiagram > current_bidder_diagrams_
void setCurrentBidders(std::vector< BidderDiagram > &diagrams)
double updateBarycenter(std::vector< std::vector< MatchingType > > &matchings)
void setInitialBarycenter(double min_persistence)
bool isPrecisionObjectiveMet(double, int)
void setDiagramType(const int &diagramType)
std::vector< BidderDiagram > bidder_diagrams_
std::vector< DiagramType > * inputDiagrams_
void setUseProgressive(const bool use_progressive)
void setNonMatchingWeight(double nonMatchingWeight)
void setMethod(const int &method)
KDTreePair getKDTree() const
void setReinitPrices(const bool reinit_prices)
std::vector< std::vector< MatchingType > > correctMatchings(std::vector< std::vector< MatchingType > > &previous_matchings)
std::string method_
void runMatchingAuction(double *total_cost, std::vector< int > &sizes, KDT &kdt, std::vector< KDT * > &correspondence_kdt_map, std::vector< double > *min_diag_price, std::vector< std::vector< MatchingType > > *all_matchings, bool use_kdt, bool actual_distance)
int setNumberOfInputs(int numberOfInputs)
void setDeterministic(const bool deterministic)
std::vector< std::vector< double > > all_matchings_
double getMinimalPrice(int i)
double getLowestPersistence()
std::vector< std::vector< MatchingType > > execute(DiagramType &barycenter)
void setLambda(const double lambda)
std::vector< BidderDiagram > & getCurrentBidders()
bool hasBarycenterConverged(std::vector< std::vector< MatchingType > > &matchings, std::vector< std::vector< MatchingType > > &previous_matchings)
std::vector< std::vector< int > > current_bidder_ids_
std::vector< std::vector< MatchingType > > executeMunkresBarycenter(DiagramType &barycenter)
double enrichCurrentBidderDiagrams(double previous_min_persistence, double min_persistence, std::vector< double > &initial_diagonal_prices, std::vector< double > &initial_off_diagonal_prices, int min_points_to_add, bool add_points_to_barycenter=true)
The Topology ToolKit.
CriticalType
default value for critical index
Definition DataTypes.h:80
std::vector< PersistencePair > DiagramType
Persistence Diagram type as a vector of Persistence pairs.