libROM  v1.0
Data-driven physical simulation library
GreedyCustomSampler.cpp
1 
11 // Description: This class greedily selects parameter points
12 // for the construction of a ROM database.
13 
14 #include "GreedyCustomSampler.h"
15 #include <cmath>
16 #include <algorithm>
17 #include <limits.h>
18 #include <fstream>
19 
20 namespace CAROM {
21 
23  std::vector<double> parameter_points,
24  bool check_local_rom,
25  double relative_error_tolerance,
26  double alpha,
27  double max_clamp,
28  int subset_size,
29  int convergence_subset_size,
30  std::string output_log_path,
31  std::string warm_start_file_name,
32  bool use_centroid,
33  int random_seed,
34  bool debug_algorithm) :
36  parameter_points,
37  check_local_rom,
38  relative_error_tolerance,
39  alpha,
40  max_clamp,
41  subset_size,
42  convergence_subset_size,
43  output_log_path,
44  warm_start_file_name,
45  use_centroid,
46  random_seed,
47  debug_algorithm
48  )
49 {
50  printSamplingType("pre-defined");
53 
54  if (warm_start_file_name != "")
55  {
56  addDatabaseFromFile(warm_start_file_name);
57  }
58 }
59 
61  std::vector<Vector> parameter_points,
62  bool check_local_rom,
63  double relative_error_tolerance,
64  double alpha,
65  double max_clamp,
66  int subset_size,
67  int convergence_subset_size,
68  std::string output_log_path,
69  std::string warm_start_file_name,
70  bool use_centroid,
71  int random_seed,
72  bool debug_algorithm) :
74  parameter_points,
75  check_local_rom,
76  relative_error_tolerance,
77  alpha,
78  max_clamp,
79  subset_size,
80  convergence_subset_size,
81  output_log_path,
82  warm_start_file_name,
83  use_centroid,
84  random_seed,
85  debug_algorithm
86  )
87 {
88  printSamplingType("pre-defined");
91 
92  if (warm_start_file_name != "")
93  {
94  addDatabaseFromFile(warm_start_file_name);
95  }
96 }
97 
99  std::string base_file_name,
100  std::string output_log_path) :
102  base_file_name,
103  output_log_path
104  ) {}
105 
106 void
108 {
111 
112  for (int i = 0; i < d_parameter_points.size(); i++)
113  {
114  for (int j = 0; j < d_parameter_points[i].dim(); j++)
115  {
116  d_min_param_point.item(j) = std::min(d_min_param_point.item(j),
117  d_parameter_points[i].item(j));
118  d_max_param_point.item(j) = std::max(d_max_param_point.item(j),
119  d_parameter_points[i].item(j));
120  }
121  }
122 
124 }
125 
126 void
128 {
131 }
132 
134 {
135 }
136 
137 }
GreedyCustomSampler(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 getNextParameterPointAfterConvergenceFailure()
Get the next parameter point to sample after a convergence failure.
void constructParameterPoints()
Construct the list of parameter point candidates to sample.
void printSamplingType(std::string sampling_type)
Print the sampling type.
std::vector< Vector > d_convergence_points
The convergence parameter points to explore.
std::vector< Vector > d_parameter_points
The parameter points to explore.
void initializeParameterPoints()
Initialize the list of parameter point candidates to sample.
int d_counter
An internal counter.
int d_next_point_to_sample
The next parameter point to sample.
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.
int getNearestNonSampledPoint(Vector point)
Returns the index of the nearest non-sampled parameter point to the given point.
const double & item(int i) const
Const Vector member access.
Definition: Vector.h:656