14 #include "GreedyRandomSampler.h"
15 #include "utils/HDFDatabase.h"
25 double param_space_min,
26 double param_space_max,
27 int num_parameter_points,
29 double relative_error_tolerance,
33 int convergence_subset_size,
34 bool use_latin_hypercube,
35 std::string output_log_path,
36 std::string warm_start_file_name,
39 bool debug_algorithm) :
45 relative_error_tolerance,
49 convergence_subset_size,
71 if (warm_start_file_name !=
"")
80 int num_parameter_points,
82 double relative_error_tolerance,
86 int convergence_subset_size,
87 bool use_latin_hypercube,
88 std::string output_log_path,
89 std::string warm_start_file_name,
92 bool debug_algorithm) :
98 relative_error_tolerance,
102 convergence_subset_size,
104 warm_start_file_name,
124 if (warm_start_file_name !=
"")
131 std::string base_file_name,
132 std::string output_log_path) :
147 std::vector<double> frequencies;
148 std::vector<std::vector<double>> point_coordinates;
149 std::vector<int> point_indices;
157 point_coordinates.push_back(std::vector<double>());
162 std::uniform_real_distribution<double> unif(low, high);
163 point_coordinates[i].push_back(unif(
rng));
170 point_indices.push_back(i);
173 std::shuffle(point_indices.begin(), point_indices.end(),
rng);
177 int point_index = point_indices[i];
198 std::string full_file_name = base_file_name;
200 database.
open(full_file_name,
"r");
205 sprintf(tmp,
"use_latin_hypercube");
221 std::string full_file_name = base_file_name;
223 database.
open(full_file_name,
"wr");
227 sprintf(tmp,
"use_latin_hypercube");
void getInteger(const std::string &key, int &data)
Reads an integer associated with the supplied key from the currently open database file.
void putInteger(const std::string &key, int data)
Writes an integer associated with the supplied key to currently open database file.
void load(std::string base_file_name)
Load the object state from a file.
void save(std::string base_file_name)
Save the object state to a file.
GreedyRandomSampler(Vector param_space_min, Vector param_space_max, int num_parameter_points, bool check_local_rom, double relative_error_tolerance, double alpha, double max_clamp, int subset_size, int convergence_subset_size, bool use_latin_hypercube, std::string output_log_path="", std::string warm_start_file_name="", bool use_centroid=true, int random_seed=1, bool debug_algorithm=false)
Constructor.
~GreedyRandomSampler()
Destructor.
bool d_use_latin_hypercube
Use latin hypercube sampling instead of fixed uniform.
void getNextParameterPointAfterConvergenceFailure()
Get the next parameter point to sample after a convergence failure.
void constructParameterPoints()
Construct the list of parameter point candidates to sample.
double d_max_error
The current max error of the parameter points of the current iteration.
virtual void save(std::string base_file_name)
Save the object state to a file.
void printSamplingType(std::string sampling_type)
Print the sampling type.
std::vector< int > d_parameter_point_random_indices
The parameter point indices (used to generate the random subsets).
std::vector< Vector > d_convergence_points
The convergence parameter points to explore.
std::vector< Vector > d_parameter_points
The parameter points to explore.
int d_rank
The rank of the given processor.
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.
std::default_random_engine rng
Random engine used to generate subsets.
std::vector< int > d_parameter_point_local_rom
The local ROMs used to obtain the current errors of the parameter points.
int d_next_point_to_sample
The next parameter point to sample.
int d_num_parameter_points
The maximum number of parameter points to sample.
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.
Vector d_max_param_point
The maximum value of the parameter space.
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.
void checkParameterPointInput()
Construct the list of parameter point candidates to sample.
std::vector< Vector > generateRandomPoints(int num_points)
Generate a vector of random points.
virtual bool open(const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL) override
Opens an existing HDF5 database file with the supplied name.
virtual bool close()
Closes the currently open HDF5 database file.
const double & item(int i) const
Const Vector member access.
int dim() const
Returns the dimension of the Vector on this processor.