31 #ifndef included_GreedySampler_h
32 #define included_GreedySampler_h
34 #include "linalg/Vector.h"
41 #if __cplusplus >= 201103L
44 #include <boost/shared_ptr.hpp>
103 const std::vector<Vector> & parameter_points,
104 bool check_local_rom,
105 double relative_error_tolerance,
109 int convergence_subset_size,
110 std::string output_log_path =
"",
111 std::string warm_start_file_name =
"",
112 bool use_centroid =
true,
114 bool debug_algorithm =
false);
141 const std::vector<double> & parameter_points,
142 bool check_local_rom,
143 double relative_error_tolerance,
147 int convergence_subset_size,
148 std::string output_log_path =
"",
149 std::string warm_start_file_name =
"",
150 bool use_centroid =
true,
152 bool debug_algorithm =
false);
183 const Vector & param_space_min,
184 const Vector & param_space_max,
185 int num_parameter_points,
186 bool check_local_rom,
187 double relative_error_tolerance,
191 int convergence_subset_size,
192 std::string output_log_path =
"",
193 std::string warm_start_file_name =
"",
194 bool use_centroid =
true,
196 bool debug_algorithm =
false);
227 double param_space_min,
228 double param_space_max,
229 int num_parameter_points,
230 bool check_local_rom,
231 double relative_error_tolerance,
235 int convergence_subset_size,
236 std::string output_log_path =
"",
237 std::string warm_start_file_name =
"",
238 bool use_centroid =
true,
240 bool debug_algorithm =
false);
251 std::string base_file_name,
252 std::string output_log_path =
"");
265 std::shared_ptr<Vector>
325 std::shared_ptr<Vector>
351 save(std::string base_file_name);
372 std::string
const& warm_start_file_name);
381 std::string base_file_name);
397 bool check_local_rom,
398 double relative_error_tolerance,
402 int convergence_subset_size,
403 std::string output_log_path,
406 bool debug_algorithm);
694 std::default_random_engine
rng;
706 const std::shared_ptr<Vector> & point,
707 const std::shared_ptr<Vector> & localROM);
717 Vector getNearestPoint(
const std::vector<Vector> & paramPoints,
728 double getNearestPoint(
const std::vector<double> & paramPoints,
double point);
void printErrorIndicator(const Vector &errorIndicatorPoint, double proc_errors)
Print the error indicator.
GreedySampler(const std::vector< Vector > ¶meter_points, bool check_local_rom, double relative_error_tolerance, double alpha, double max_clamp, int subset_size, int convergence_subset_size, std::string output_log_path="", std::string warm_start_file_name="", bool use_centroid=true, int random_seed=1, bool debug_algorithm=false)
Constructor.
void printConvergenceAchieved()
Print that convergence was achieved.
virtual void constructParameterPoints()=0
Construct the list of parameter point candidates to sample.
void setPointRelativeError(double error)
Set the relative error of the specified point.
void generateConvergenceSubset()
Generate a new set of convergence points.
GreedyErrorIndicatorPoint getNextPointRequiringRelativeError()
Returns the next parameter point for which a relative error is required.
double d_max_error
The current max error of the parameter points of the current iteration.
int getNearestNonSampledPoint(const Vector &point)
Returns the index of the nearest non-sampled parameter point to the given point.
virtual void save(std::string base_file_name)
Save the object state to a file.
bool d_subset_created
Whether the database has already created a random subset for this iteration.
int d_next_point_requiring_error_indicator
The next parameter point requiring a error indicator.
void printSamplingType(std::string sampling_type)
Print the sampling type.
void setSubsetErrorIndicator(double proc_errors)
Set the error indicator for a subset point.
int d_subset_counter
An internal subset counter.
double d_max_clamp
The max_clamp constant.
bool d_use_centroid
Whether the use the centroid heuristic for obtaining the first parameter point.
bool d_point_requiring_error_indicator_computed
Whether the database has already computed a new paramter point requiring a error indicator.
void setConvergenceErrorIndicator(double proc_errors)
Set the error indicator for a convergence point.
bool isComplete()
Check if the greedy algorithm procedure is complete.
int d_random_seed
Then random seed used to generate subsets.
int d_subset_size
The size of the subset of parameter points used per iteration.
bool d_debug_algorithm
Turn off randomness for debugging purposes.
std::vector< Vector > getParameterPointDomain()
Get the domain of the parameter points.
double d_relative_error_tol
The relative error tolerance used to terminate the greedy procedure.
std::string d_output_log_path
Output log path.
void constructObject(bool check_local_rom, double relative_error_tolerance, double alpha, double max_clamp, int subset_size, int convergence_subset_size, std::string output_log_path, bool use_centroid, int random_seed, bool debug_algorithm)
Construct the GreedySampler object.
bool d_check_local_rom
Whether the check the last sampled local ROM's error indicator after each iteration.
std::vector< int > d_parameter_point_random_indices
The parameter point indices (used to generate the random subsets).
virtual void getNextParameterPointAfterConvergenceFailure()=0
Get the next parameter point to sample after a convergence failure.
std::vector< Vector > d_convergence_points
The convergence parameter points to explore.
GreedyErrorIndicatorPoint getNextSubsetPointRequiringErrorIndicator()
Get the next subset point requiring an error indicator.
std::vector< Vector > d_parameter_points
The parameter points to explore.
int d_rank
The rank of the given processor.
double d_curr_relative_error
The current relative error of the current iteration.
std::vector< double > d_parameter_point_errors
The current errors of the parameter points.
void initializeParameterPoints()
Initialize the list of parameter point candidates to sample.
int d_counter
An internal counter.
bool d_next_parameter_point_computed
Whether the database has already computed a new parameter point to sample.
virtual ~GreedySampler()
Destructor.
void setPointErrorIndicator(double error, int vec_size)
Set the error indicator error of the specified parameter point.
std::default_random_engine rng
Random engine used to generate subsets.
GreedyErrorIndicatorPoint getNextConvergencePointRequiringErrorIndicator()
Get the next convergence point requiring an error indicator.
std::vector< int > d_parameter_point_local_rom
The local ROMs used to obtain the current errors of the parameter points.
GreedyErrorIndicatorPoint getNextPointRequiringErrorIndicator()
Returns the next parameter point for which an error indicator is required.
int d_next_point_to_sample
The next parameter point to sample.
void agnosticPrint(std::string str)
Print to output_log_file or cout.
int d_num_parameter_points
The maximum number of parameter points to sample.
std::shared_ptr< Vector > getNearestROM(const Vector &point)
Returns the nearest local ROM to the specified parameter point.
double d_error_indicator_tol
The error indicator tolerance used to terminate the greedy procedure.
virtual void load(std::string base_file_name)
Load the object state from a file.
int getNearestROMIndexToParameterPoint(int index, bool ignore_self)
Returns the index to the nearest local ROM to the specified parameter point index in the parameter po...
bool d_procedure_completed
Whether the greedy procedure has completed.
int d_convergence_subset_size
The size of the subset of parameter points used to check convergence.
bool d_convergence_started
Whether the database is in the convergence verifying phase.
void printErrorIndicatorToleranceNotMet()
Print that the error indicator was not met.
double d_alpha
The alpha constant.
std::vector< Vector > getSampledParameterPoints()
Get the sampled parameter points.
Vector d_max_param_point
The maximum value of the parameter space.
std::set< int > d_parameter_sampled_indices
The parameter points that were already sampled.
void startConvergence()
Switch to convergence mode.
Vector d_min_param_point
The minimum value of the parameter space.
void addDatabaseFromFile(std::string const &warm_start_file_name)
Do a warm start by adding the sampled parameters from the database in a file to the current database.
std::shared_ptr< Vector > getNextParameterPoint()
Returns the next parameter point for which sampling is required.
bool d_iteration_started
Whether the database has already computed a new parameter point for the current iteration.
void checkParameterPointInput()
Construct the list of parameter point candidates to sample.
std::vector< Vector > generateRandomPoints(int num_points)
Generate a vector of random points.
int getNearestPointIndex(const std::vector< Vector > ¶m_points, Vector &point)
Given a vector, find the nearest point in a domain.
GreedyErrorIndicatorPoint createGreedyErrorIndicatorPoint(const std::shared_ptr< Vector > &point, const std::shared_ptr< Vector > &localROM)
Create a greedy error indicator point.
std::shared_ptr< Vector > localROM
The parameter point of the closest local ROM.
std::shared_ptr< Vector > point
The parameter point to calculate the error indicator.