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 double getCost() {
183 return cost_;
184 }
185
186 protected:
187 // std::vector<bool> precision_objective_;
188 std::vector<double> precision_;
189
190 // to kill any randomness
191 bool deterministic_{false};
192
193 std::string method_{"Partial Bidding"};
195
197
198 // lambda_ : 0<=lambda<=1
199 // parametrizes the point used for the physical (critical) coordinates of
200 // the persistence paired lambda_ = 1 : extremum (min if pair min-sad, max
201 // if pair sad-max) lambda_ = 0 : saddle (awful stability) lambda_ = 1/2 :
202 // middle of the 2 critical points of the pair (bad stability)
203 double lambda_;
204
208 double cost_;
211 double epsilon_min_{1e-5};
212 std::vector<DiagramType> *inputDiagrams_;
213
216
217 std::vector<std::vector<double>> all_matchings_;
218 std::vector<std::vector<double>> all_old_matchings_;
219 std::vector<BidderDiagram> bidder_diagrams_;
220 std::vector<BidderDiagram> current_bidder_diagrams_;
221 std::vector<std::vector<int>> current_bidder_ids_;
222 std::vector<GoodDiagram> barycenter_goods_;
223
224 bool reinit_prices_{true};
226 bool early_stoppage_{true};
227 };
228} // namespace ttk
int threadNumber_
Definition: BaseClass.h:95
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()
Definition: PDBarycenter.h:152
std::vector< std::vector< MatchingType > > executePartialBiddingBarycenter(DiagramType &barycenter)
std::vector< double > precision_
Definition: PDBarycenter.h:188
bool is_matching_stable()
void setEarlyStoppage(const bool early_stoppage)
Definition: PDBarycenter.h:164
ttk::CriticalType nt1_
Definition: PDBarycenter.h:206
~PDBarycenter() override=default
void setGeometricalFactor(const double geometrical_factor)
Definition: PDBarycenter.h:132
double getEpsilon(double rho)
int setDiagrams(std::vector< DiagramType > *data)
Definition: PDBarycenter.h:112
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
Definition: PDBarycenter.h:58
std::vector< std::vector< double > > all_old_matchings_
Definition: PDBarycenter.h:218
void setCurrentBarycenter(std::vector< GoodDiagram > &barycenters)
Definition: PDBarycenter.h:144
ttk::CriticalType nt2_
Definition: PDBarycenter.h:207
std::vector< GoodDiagram > barycenter_goods_
Definition: PDBarycenter.h:222
void setWasserstein(const int &wasserstein)
Definition: PDBarycenter.h:124
void setEpsilonDecreases(const bool epsilon_decreases)
Definition: PDBarycenter.h:160
double getRho(double epsilon)
std::vector< BidderDiagram > current_bidder_diagrams_
Definition: PDBarycenter.h:220
void setCurrentBidders(std::vector< BidderDiagram > &diagrams)
Definition: PDBarycenter.h:140
double computeRealCost()
double updateBarycenter(std::vector< std::vector< MatchingType > > &matchings)
void setInitialBarycenter(double min_persistence)
bool isPrecisionObjectiveMet(double, int)
void setDiagramType(const int &diagramType)
Definition: PDBarycenter.h:168
std::vector< BidderDiagram > bidder_diagrams_
Definition: PDBarycenter.h:219
std::vector< DiagramType > * inputDiagrams_
Definition: PDBarycenter.h:212
void setUseProgressive(const bool use_progressive)
Definition: PDBarycenter.h:128
void setMethod(const int &method)
Definition: PDBarycenter.h:101
KDTreePair getKDTree() const
void setReinitPrices(const bool reinit_prices)
Definition: PDBarycenter.h:156
std::vector< std::vector< MatchingType > > correctMatchings(std::vector< std::vector< MatchingType > > &previous_matchings)
std::string method_
Definition: PDBarycenter.h:193
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)
Definition: PDBarycenter.h:117
double getMaxPersistence()
void setDeterministic(const bool deterministic)
Definition: PDBarycenter.h:97
std::vector< std::vector< double > > all_matchings_
Definition: PDBarycenter.h:217
double getMinimalPrice(int i)
double getLowestPersistence()
std::vector< std::vector< MatchingType > > execute(DiagramType &barycenter)
void setLambda(const double lambda)
Definition: PDBarycenter.h:136
std::vector< BidderDiagram > & getCurrentBidders()
Definition: PDBarycenter.h:148
bool hasBarycenterConverged(std::vector< std::vector< MatchingType > > &matchings, std::vector< std::vector< MatchingType > > &previous_matchings)
std::vector< std::vector< int > > current_bidder_ids_
Definition: PDBarycenter.h:221
double geometrical_factor_
Definition: PDBarycenter.h:196
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.