14 #include "GreedySampler.h"
15 #include "utils/HDFDatabase.h"
28 result.
point = std::shared_ptr<Vector>(point);
29 result.
localROM = std::shared_ptr<Vector>(localROM);
35 std::shared_ptr<Vector>& localROM)
38 result.
point = std::shared_ptr<Vector>(point);
48 return param_points[closest_point_index];
55 double closest_dist_to_points = INT_MAX;
56 int closest_point_index = -1;
58 for (
int i = 0; i < param_points.size(); i++)
61 point.
minus(param_points[i], diff);
62 double dist = diff.
norm();
63 if (dist < closest_dist_to_points)
65 closest_dist_to_points = dist;
66 closest_point_index = i;
70 return closest_point_index;
78 return param_points[closest_point_index];
85 double closest_dist_to_points = INT_MAX;
86 int closest_point_index = -1;
88 for (
int i = 0; i < param_points.size(); i++)
90 double dist = std::abs(point - param_points[i]);
91 if (dist < closest_dist_to_points)
93 closest_dist_to_points = dist;
94 closest_point_index = i;
98 return closest_point_index;
102 std::vector<Vector> parameter_points,
103 bool check_local_rom,
104 double relative_error_tolerance,
108 int convergence_subset_size,
109 std::string output_log_path,
110 std::string warm_start_file_name,
113 bool debug_algorithm)
120 constructObject(check_local_rom, relative_error_tolerance, alpha, max_clamp,
121 subset_size, convergence_subset_size, output_log_path, use_centroid,
122 random_seed, debug_algorithm);
126 std::vector<double> parameter_points,
127 bool check_local_rom,
128 double relative_error_tolerance,
132 int convergence_subset_size,
133 std::string output_log_path,
134 std::string warm_start_file_name,
137 bool debug_algorithm)
142 std::vector<Vector> parameter_points_vec;
143 for (
int i = 0; i < parameter_points.size(); i++)
146 vec.
item(0) = parameter_points[i];
147 parameter_points_vec.push_back(vec);
152 constructObject(check_local_rom, relative_error_tolerance, alpha, max_clamp,
153 subset_size, convergence_subset_size, output_log_path, use_centroid,
154 random_seed, debug_algorithm);
160 int num_parameter_points,
161 bool check_local_rom,
162 double relative_error_tolerance,
166 int convergence_subset_size,
167 std::string output_log_path,
168 std::string warm_start_file_name,
171 bool debug_algorithm)
178 constructObject(check_local_rom, relative_error_tolerance, alpha, max_clamp,
180 convergence_subset_size, output_log_path, use_centroid, random_seed,
185 double param_space_min,
186 double param_space_max,
187 int num_parameter_points,
188 bool check_local_rom,
189 double relative_error_tolerance,
193 int convergence_subset_size,
194 std::string output_log_path,
195 std::string warm_start_file_name,
198 bool debug_algorithm)
201 Vector param_space_min_vec(1,
false);
202 param_space_min_vec.
item(0) = param_space_min;
203 Vector param_space_max_vec(1,
false);
204 param_space_max_vec.
item(0) = param_space_max;
210 constructObject(check_local_rom, relative_error_tolerance, alpha, max_clamp,
212 convergence_subset_size, output_log_path, use_centroid, random_seed,
217 std::string base_file_name,
218 std::string output_log_path)
220 CAROM_ASSERT(!base_file_name.empty());
223 MPI_Initialized(&mpi_init);
225 MPI_Comm_rank(MPI_COMM_WORLD, &
d_rank);
233 load(base_file_name);
238 std::string
const& warm_start_file_name)
241 std::string full_file_name = warm_start_file_name;
243 database.
open(full_file_name,
"r");
245 sprintf(tmp,
"num_parameter_sampled_indices");
246 int num_parameter_sampled_indices;
247 database.
getInteger(tmp, num_parameter_sampled_indices);
248 if (num_parameter_sampled_indices > 0)
250 int temp_parameter_sampled_indices[num_parameter_sampled_indices];
251 sprintf(tmp,
"parameter_sampled_indices");
253 num_parameter_sampled_indices);
254 for (
int i = 0; i < num_parameter_sampled_indices; i++)
256 std::string vec_path = warm_start_file_name +
"_" + std::to_string(i);
263 double dist = diff.
norm();
276 std::string base_file_name)
279 std::string full_file_name = base_file_name;
281 database.
open(full_file_name,
"r");
283 sprintf(tmp,
"num_parameter_points");
284 int num_parameter_points;
285 database.
getInteger(tmp, num_parameter_points);
286 for (
int i = 0; i < num_parameter_points; i++)
288 std::string vec_path = base_file_name +
"_" + std::to_string(i);
294 std::string vec_path = base_file_name +
"_min_point";
297 vec_path = base_file_name +
"_max_point";
300 sprintf(tmp,
"num_parameter_sampled_indices");
301 int num_parameter_sampled_indices;
302 database.
getInteger(tmp, num_parameter_sampled_indices);
303 if (num_parameter_sampled_indices > 0)
305 int temp_parameter_sampled_indices[num_parameter_sampled_indices];
306 sprintf(tmp,
"parameter_sampled_indices");
308 num_parameter_sampled_indices);
309 for (
int i = 0; i < num_parameter_sampled_indices; i++)
316 sprintf(tmp,
"procedure_completed");
322 sprintf(tmp,
"max_error");
324 sprintf(tmp,
"curr_relative_error");
326 sprintf(tmp,
"error_indicator_tol");
328 sprintf(tmp,
"relative_error_tol");
330 sprintf(tmp,
"alpha");
332 sprintf(tmp,
"max_clamp");
334 sprintf(tmp,
"max_num_parameter_points");
336 sprintf(tmp,
"subset_size");
338 sprintf(tmp,
"convergence_subset_size");
340 sprintf(tmp,
"next_point_to_sample");
342 sprintf(tmp,
"next_point_requiring_error_indicator");
344 sprintf(tmp,
"check_local_rom");
347 sprintf(tmp,
"use_centroid");
350 sprintf(tmp,
"iteration_started");
353 sprintf(tmp,
"convergence_started");
356 sprintf(tmp,
"next_parameter_point_computed");
359 sprintf(tmp,
"point_requiring_error_indicator_computed");
362 sprintf(tmp,
"subset_created");
365 sprintf(tmp,
"debug_algorithm");
368 sprintf(tmp,
"counter");
370 sprintf(tmp,
"subset_counter");
372 sprintf(tmp,
"random_seed");
375 sprintf(tmp,
"parameter_point_random_indices");
380 sprintf(tmp,
"parameter_point_errors");
385 sprintf(tmp,
"parameter_point_local_rom");
392 std::string vec_path = base_file_name +
"_conv_" + std::to_string(i);
409 bool isGreater =
false;
429 CAROM_VERIFY(isGreater);
434 str +=
"Total number of sample points: " + std::to_string(
436 str +=
"Parameter space minimum: [ ";
442 str +=
"Parameter space maximum: [ ";
454 bool check_local_rom,
455 double relative_error_tolerance,
459 int convergence_subset_size,
460 std::string output_log_path,
463 bool debug_algorithm)
465 CAROM_VERIFY(relative_error_tolerance > 0.0);
466 CAROM_VERIFY(alpha >= 1.0);
467 CAROM_VERIFY(max_clamp >= 1.0);
468 CAROM_VERIFY(subset_size > 0);
469 CAROM_VERIFY(convergence_subset_size > 0);
470 CAROM_VERIFY(subset_size < convergence_subset_size);
471 CAROM_VERIFY(random_seed > 0);
474 MPI_Initialized(&mpi_init);
476 MPI_Comm_rank(MPI_COMM_WORLD, &
d_rank);
512 str +=
"Alpha constant: " + std::to_string(
d_alpha) +
"\n";
513 str +=
"Max clamp constant: " + std::to_string(
d_max_clamp) +
"\n";
514 str +=
"Iteration subset size: " + std::to_string(
d_subset_size) +
"\n";
541 std::shared_ptr<Vector>
546 return std::shared_ptr<Vector>(
nullptr);
550 return std::shared_ptr<Vector>(
nullptr);
555 return std::shared_ptr<Vector>(result);
580 str +=
"\nPoint sampled at [ ";
592 return std::shared_ptr<Vector>(result);
602 if (!d_next_parameter_point_computed)
607 Vector* result1 =
new Vector(d_parameter_points[d_next_point_to_sample]);
608 Vector* result2 = NULL;
610 if (d_parameter_sampled_indices.size() == 1)
612 result2 =
new Vector(d_parameter_points[getNearestROMIndexToParameterPoint(
613 d_next_point_to_sample,
false)]);
617 result2 =
new Vector(d_parameter_points[getNearestROMIndexToParameterPoint(
618 d_next_point_to_sample,
true)]);
624 struct GreedyErrorIndicatorPoint
625 GreedySampler::getNextPointRequiringErrorIndicator()
631 if (!d_iteration_started)
636 if (d_convergence_started)
638 return getNextConvergencePointRequiringErrorIndicator();
642 return getNextSubsetPointRequiringErrorIndicator();
646 struct GreedyErrorIndicatorPoint
647 GreedySampler::getNextSubsetPointRequiringErrorIndicator()
649 if (d_point_requiring_error_indicator_computed)
651 Vector* result1 =
new Vector(
652 d_parameter_points[d_next_point_requiring_error_indicator]);
653 Vector* result2 =
new Vector(
654 d_parameter_points[getNearestROMIndexToParameterPoint(
655 d_next_point_requiring_error_indicator,
false)]);
658 if (d_subset_counter == d_subset_size)
663 if(!d_subset_created)
666 if (!d_debug_algorithm)
668 std::shuffle(d_parameter_point_random_indices.begin(),
669 d_parameter_point_random_indices.end(), rng);
671 d_subset_created =
true;
674 d_next_point_requiring_error_indicator = -1;
676 while (d_counter < (
int) d_parameter_points.size() - 1)
679 if (d_subset_counter == d_subset_size)
683 auto search = d_parameter_sampled_indices.find(
684 d_parameter_point_random_indices[d_counter]);
685 if (search == d_parameter_sampled_indices.end())
689 d_parameter_point_errors[d_parameter_point_random_indices[d_counter]];
690 if (curr_error > d_max_error)
694 if (d_parameter_point_local_rom[d_parameter_point_random_indices[d_counter]] ==
695 getNearestROMIndexToParameterPoint(d_parameter_point_random_indices[d_counter],
698 d_max_error = curr_error;
699 d_next_point_to_sample = d_parameter_point_random_indices[d_counter];
703 str +=
"Error indicator at [ ";
705 i < d_parameter_points[d_parameter_point_random_indices[d_counter]].dim(); i++)
707 str += std::to_string(
708 d_parameter_points[d_parameter_point_random_indices[d_counter]].item(i)) +
" ";
710 str +=
"] skipped.\n";
711 str +=
"Error indicator " + std::to_string(curr_error) +
712 " already computed at the same local ROM.\n";
718 d_next_point_requiring_error_indicator =
719 d_parameter_point_random_indices[d_counter];
720 d_point_requiring_error_indicator_computed =
true;
721 Vector* result1 =
new Vector(
722 d_parameter_points[d_next_point_requiring_error_indicator]);
723 Vector* result2 =
new Vector(
724 d_parameter_points[getNearestROMIndexToParameterPoint(
725 d_next_point_requiring_error_indicator,
false)]);
734 str +=
"Error indicator at [ ";
736 i < d_parameter_points[d_parameter_point_random_indices[d_counter]].dim(); i++)
738 str += std::to_string(
739 d_parameter_points[d_parameter_point_random_indices[d_counter]].item(i)) +
" ";
741 str +=
"] skipped.\n";
742 str +=
"Error indicator " + std::to_string(curr_error) +
743 " is less than current max error " + std::to_string(d_max_error) +
"\n";
749 if (d_next_point_requiring_error_indicator == -1)
754 str +=
"Ran out of points to calculate error indicator for in this iteration.\n";
757 if (d_max_error < d_error_indicator_tol)
763 printErrorIndicatorToleranceNotMet();
764 d_iteration_started =
false;
771 struct GreedyErrorIndicatorPoint
772 GreedySampler::getNextConvergencePointRequiringErrorIndicator()
774 if (d_point_requiring_error_indicator_computed)
776 Vector* result1 =
new Vector(
777 d_convergence_points[d_next_point_requiring_error_indicator]);
778 std::shared_ptr<Vector> result2 = getNearestROM(
779 d_convergence_points[d_next_point_requiring_error_indicator]);
782 if (d_counter == d_convergence_subset_size)
787 d_next_point_requiring_error_indicator = -1;
790 if (d_counter < (
int) d_convergence_points.size())
792 d_next_point_requiring_error_indicator = d_counter;
793 d_point_requiring_error_indicator_computed =
true;
794 Vector* result1 =
new Vector(
795 d_convergence_points[d_next_point_requiring_error_indicator]);
796 std::shared_ptr<Vector> result2 = getNearestROM(
797 d_convergence_points[d_next_point_requiring_error_indicator]);
801 if (d_next_point_requiring_error_indicator == -1)
803 printConvergenceAchieved();
804 d_procedure_completed =
true;
816 str +=
"Sampling type: " + sampling_type +
"\n";
827 str +=
"Convergence achieved.\n";
830 str =
"\nSampled Parameter Points\n";
831 std::vector<std::pair<double, int>> first_dim_of_sampled_points;
834 first_dim_of_sampled_points.push_back(std::make_pair(
837 sort(first_dim_of_sampled_points.begin(), first_dim_of_sampled_points.end());
838 for (
int i = 0; i < first_dim_of_sampled_points.size(); i++)
844 str += std::to_string(
856 CAROM_VERIFY(error >= 0);
859 if (!std::isfinite(error))
869 str +=
"Relative error computed at [ ";
875 str +=
"Relative error: " + std::to_string(error) +
"\n";
898 str +=
"The relative error was smaller than the relative error tolerance. The error indicator tolerance must increase.\n";
899 str +=
"Alpha constant * relative error tolerance: " + std::to_string(
901 str +=
"The minimum value the error indicator tolerance can take is: " +
902 std::to_string(max1) +
"\n";
903 str +=
"Max clamp constant * current max error indicator: " + std::to_string(
905 str +=
"Relative error tolerance * current max error indicator / current relative error: "
906 + std::to_string(min2) +
"\n";
907 str +=
"The maximum value the error indicator tolerance can take is the minimum of the previous two values: "
908 + std::to_string(std::min(min1, min2)) +
"\n";
921 str +=
"The relative error was larger than the relative error tolerance. The error indicator tolerance must decrease.\n";
922 str +=
"Current error indicator tolerance: " + std::to_string(
924 str +=
"Relative error tolerance * current max error indicator / current relative error: "
925 + std::to_string(min1) +
"\n";
926 str +=
"The minimum value the error indicator tolerance can take is: " +
937 str +=
"Error indicator tolerance was adaptively changed from " +
938 std::to_string(old_error_indicator_tol) +
" to " + std::to_string(
973 CAROM_VERIFY(error >= 0);
976 double proc_errors = pow(error, 2);
977 int total_vec_size = vec_size;
978 CAROM_VERIFY(MPI_Allreduce(MPI_IN_PLACE,
983 MPI_COMM_WORLD) == MPI_SUCCESS);
984 CAROM_VERIFY(MPI_Allreduce(MPI_IN_PLACE,
989 MPI_COMM_WORLD) == MPI_SUCCESS);
990 proc_errors = sqrt(proc_errors);
991 proc_errors /= total_vec_size;
993 if (!std::isfinite(proc_errors))
995 proc_errors = INT_MAX;
1015 str +=
"Error indicator computed at [ ";
1016 for (
int i = 0 ; i < errorIndicatorPoint.
dim(); i++)
1018 str += std::to_string(errorIndicatorPoint.
item(i)) +
" ";
1021 str +=
"Error indicator: " + std::to_string(proc_errors) +
"\n";
1035 std::ofstream database_history;
1037 database_history << str;
1038 database_history.close();
1075 str +=
"Local ROM error indicator computed at [ ";
1079 str += std::to_string(
1083 str +=
"Local ROM error indicator (tolerance unchecked): " + std::to_string(
1084 proc_errors) +
"\n";
1087 str +=
"Error indicator at the local ROM was higher than the previous tolerance.\n";
1088 str +=
"The error indicator tolerance should always be at least the error indicator at the local ROM.\n";
1089 str +=
"Error indicator tolerance was adaptively changed from " +
1090 std::to_string(old_error_indicator_tol) +
" to " + std::to_string(
1205 " met. Computing convergence.\n";
1218 std::vector<Vector> random_points;
1220 std::vector<std::uniform_real_distribution<double>> unif;
1227 for (
int i = 0; i < num_points; i++)
1230 for (
int j = 0; j < point.
dim(); j++)
1234 random_points.push_back(point);
1236 return random_points;
1239 std::shared_ptr<Vector>
1245 double closest_dist_to_points = INT_MAX;
1246 int closest_point_index = -1;
1252 double dist = diff.
norm();
1253 if (dist < closest_dist_to_points)
1255 closest_dist_to_points = dist;
1256 closest_point_index = *itr;
1260 if (closest_point_index == -1)
1262 return std::shared_ptr<Vector>(
nullptr);
1266 return std::shared_ptr<Vector>(result);
1272 double closest_dist_to_points = INT_MAX;
1273 int closest_point_index = -1;
1282 double dist = diff.
norm();
1283 if (dist < closest_dist_to_points)
1285 closest_dist_to_points = dist;
1286 closest_point_index = i;
1291 return closest_point_index;
1300 double closest_dist_to_points = INT_MAX;
1301 int closest_point_index = -1;
1309 double dist = diff.
norm();
1310 if (dist < closest_dist_to_points ||
1313 closest_dist_to_points = dist;
1314 closest_point_index = *itr;
1317 else if (!ignore_self)
1319 closest_dist_to_points = 0;
1320 closest_point_index = *itr;
1325 return closest_point_index;
1337 std::vector<Vector> sampled_points;
1342 return sampled_points;
1348 CAROM_ASSERT(!base_file_name.empty());
1353 std::string full_file_name = base_file_name;
1355 database.
create(full_file_name);
1357 sprintf(tmp,
"num_parameter_points");
1361 std::string vec_path = base_file_name +
"_" + std::to_string(i);
1366 std::string vec_path = base_file_name +
"_conv_" + std::to_string(i);
1370 std::string vec_path = base_file_name +
"_min_point";
1373 vec_path = base_file_name +
"_max_point";
1376 sprintf(tmp,
"num_parameter_sampled_indices");
1380 sprintf(tmp,
"parameter_sampled_indices");
1381 std::vector<int> d_parameter_sampled_indices_vec(
1387 sprintf(tmp,
"procedure_completed");
1392 sprintf(tmp,
"max_error");
1394 sprintf(tmp,
"curr_relative_error");
1396 sprintf(tmp,
"error_indicator_tol");
1398 sprintf(tmp,
"relative_error_tol");
1400 sprintf(tmp,
"alpha");
1402 sprintf(tmp,
"max_clamp");
1404 sprintf(tmp,
"max_num_parameter_points");
1406 sprintf(tmp,
"subset_size");
1408 sprintf(tmp,
"convergence_subset_size");
1410 sprintf(tmp,
"next_point_to_sample");
1412 sprintf(tmp,
"next_point_requiring_error_indicator");
1414 sprintf(tmp,
"check_local_rom");
1416 sprintf(tmp,
"use_centroid");
1418 sprintf(tmp,
"iteration_started");
1420 sprintf(tmp,
"convergence_started");
1422 sprintf(tmp,
"next_parameter_point_computed");
1424 sprintf(tmp,
"point_requiring_error_indicator_computed");
1426 sprintf(tmp,
"subset_created");
1428 sprintf(tmp,
"debug_algorithm");
1430 sprintf(tmp,
"counter");
1432 sprintf(tmp,
"subset_counter");
1434 sprintf(tmp,
"random_seed");
1437 sprintf(tmp,
"parameter_point_random_indices");
1440 sprintf(tmp,
"parameter_point_errors");
1443 sprintf(tmp,
"parameter_point_local_rom");
1449 MPI_Barrier(MPI_COMM_WORLD);
1461 str +=
"Maximum number of parameter points reached. Stopping now.\n";
void getInteger(const std::string &key, int &data)
Reads an integer associated with the supplied key from the currently open database file.
void putDouble(const std::string &key, double data)
Writes a double associated with the supplied key to 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 getDouble(const std::string &key, double &data)
Reads a double associated with the supplied key from the currently open database file.
void printConvergenceAchieved()
Print that convergence was achieved.
void setPointRelativeError(double error)
Set the relative error of the specified point.
GreedySampler(std::vector< Vector > parameter_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 generateConvergenceSubset()
Generate a new set of convergence points.
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.
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.
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.
~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.
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.
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(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.
void printErrorIndicator(Vector errorIndicatorPoint, double proc_errors)
Print the error indicator.
struct GreedyErrorIndicatorPoint getNextPointRequiringErrorIndicator()
Returns the next parameter point for which an error indicator 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 getNearestNonSampledPoint(Vector point)
Returns the index of the nearest non-sampled parameter point to the given point.
virtual void getIntegerArray(const std::string &key, int *data, int nelements, const bool distributed=false)
Reads an array of integers associated with the supplied key from the currently open HDF5 database fil...
virtual bool create(const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL) override
Creates a new HDF5 database file with the supplied name.
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 void getDoubleArray(const std::string &key, double *data, int nelements, const bool distributed=false)
Reads an array of doubles associated with the supplied key from the currently open HDF5 database file...
virtual void putDoubleArray(const std::string &key, const double *const data, int nelements, const bool distributed=false)
Writes an array of doubles associated with the supplied key to the currently open HDF5 database file.
virtual void putIntegerArray(const std::string &key, const int *const data, int nelements, const bool distributed=false)
Writes an array of integers associated with the supplied key to the currently open HDF5 database file...
virtual bool close()
Closes the currently open HDF5 database file.
double norm() const
Form the norm of this.
Vector * minus(const Vector &other) const
Subtracts other and this and returns the result, reference version.
void write(const std::string &base_file_name)
write Vector into (a) HDF file(s).
const double & item(int i) const
Const Vector member access.
void local_read(const std::string &base_file_name, int rank)
read read a single rank of a distributed Vector from (a) HDF file(s).
int dim() const
Returns the dimension of the Vector on this processor.
Vector getNearestPoint(std::vector< Vector > param_points, Vector point)
Given a vector, find the nearest point in a domain.
struct GreedyErrorIndicatorPoint createGreedyErrorIndicatorPoint(Vector *point, Vector *localROM)
Create a greedy error indicator point.
int getNearestPointIndex(std::vector< Vector > param_points, Vector point)
Given a vector, find the nearest point in a domain.
int getCenterPoint(std::vector< Vector * > &points, bool use_centroid)
Get center point of a group of points.
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.