libROM  v1.0
Data-driven physical simulation library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CAROM::GreedyRandomSampler Class Reference

#include <GreedyRandomSampler.h>

Inheritance diagram for CAROM::GreedyRandomSampler:
CAROM::GreedySampler

Public Member Functions

 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. More...
 
 GreedyRandomSampler (double param_space_min, double 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. More...
 
 GreedyRandomSampler (std::string base_file_name, std::string output_log_path="")
 Constructor. More...
 
void save (std::string base_file_name)
 Save the object state to a file. More...
 
 ~GreedyRandomSampler ()
 Destructor.
 
- Public Member Functions inherited from CAROM::GreedySampler
 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. More...
 
 GreedySampler (std::vector< double > 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. More...
 
 GreedySampler (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, std::string output_log_path="", std::string warm_start_file_name="", bool use_centroid=true, int random_seed=1, bool debug_algorithm=false)
 Constructor. More...
 
 GreedySampler (double param_space_min, double 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, std::string output_log_path="", std::string warm_start_file_name="", bool use_centroid=true, int random_seed=1, bool debug_algorithm=false)
 Constructor. More...
 
 GreedySampler (std::string base_file_name, std::string output_log_path="")
 Constructor. More...
 
 ~GreedySampler ()
 Destructor.
 
std::shared_ptr< VectorgetNextParameterPoint ()
 Returns the next parameter point for which sampling is required. More...
 
struct GreedyErrorIndicatorPoint getNextPointRequiringRelativeError ()
 Returns the next parameter point for which a relative error is required. More...
 
struct GreedyErrorIndicatorPoint getNextPointRequiringErrorIndicator ()
 Returns the next parameter point for which an error indicator is required. More...
 
void setPointRelativeError (double error)
 Set the relative error of the specified point. More...
 
void setPointErrorIndicator (double error, int vec_size)
 Set the error indicator error of the specified parameter point. More...
 
int getNearestNonSampledPoint (Vector point)
 Returns the index of the nearest non-sampled parameter point to the given point. More...
 
std::shared_ptr< VectorgetNearestROM (Vector point)
 Returns the nearest local ROM to the specified parameter point. More...
 
std::vector< VectorgetParameterPointDomain ()
 Get the domain of the parameter points. More...
 
std::vector< VectorgetSampledParameterPoints ()
 Get the sampled parameter points. More...
 
bool isComplete ()
 Check if the greedy algorithm procedure is complete. More...
 

Protected Member Functions

void load (std::string base_file_name)
 Load the object state from a file. More...
 
void constructParameterPoints ()
 Construct the list of parameter point candidates to sample.
 
void getNextParameterPointAfterConvergenceFailure ()
 Get the next parameter point to sample after a convergence failure.
 
- Protected Member Functions inherited from CAROM::GreedySampler
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. More...
 
void checkParameterPointInput ()
 Construct the list of parameter point candidates to sample.
 
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.
 
void initializeParameterPoints ()
 Initialize the list of parameter point candidates to sample.
 
struct GreedyErrorIndicatorPoint getNextSubsetPointRequiringErrorIndicator ()
 Get the next subset point requiring an error indicator. More...
 
struct GreedyErrorIndicatorPoint getNextConvergencePointRequiringErrorIndicator ()
 Get the next convergence point requiring an error indicator. More...
 
std::vector< VectorgenerateRandomPoints (int num_points)
 Generate a vector of random points. More...
 
void agnosticPrint (std::string str)
 Print to output_log_file or cout.
 
void printErrorIndicator (Vector errorIndicatorPoint, double proc_errors)
 Print the error indicator. More...
 
void printErrorIndicatorToleranceNotMet ()
 Print that the error indicator was not met.
 
void printSamplingType (std::string sampling_type)
 Print the sampling type. More...
 
void printConvergenceAchieved ()
 Print that convergence was achieved.
 
void setSubsetErrorIndicator (double proc_errors)
 Set the error indicator for a subset point. More...
 
void setConvergenceErrorIndicator (double proc_errors)
 Set the error indicator for a convergence point. More...
 
void generateConvergenceSubset ()
 Generate a new set of convergence points.
 
void startConvergence ()
 Switch to convergence mode.
 
int getNearestROMIndexToParameterPoint (int index, bool ignore_self)
 Returns the index to the nearest local ROM to the specified parameter point index in the parameter point list. More...
 

Protected Attributes

bool d_use_latin_hypercube
 Use latin hypercube sampling instead of fixed uniform.
 
- Protected Attributes inherited from CAROM::GreedySampler
std::vector< Vectord_parameter_points
 The parameter points to explore.
 
std::vector< Vectord_convergence_points
 The convergence parameter points to explore.
 
Vector d_min_param_point
 The minimum value of the parameter space.
 
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.
 
std::vector< int > d_parameter_point_random_indices
 The parameter point indices (used to generate the random subsets).
 
std::vector< double > d_parameter_point_errors
 The current errors of the parameter points.
 
std::vector< int > d_parameter_point_local_rom
 The local ROMs used to obtain the current errors of the parameter points.
 
std::string d_output_log_path
 Output log path.
 
double d_max_error
 The current max error of the parameter points of the current iteration.
 
double d_curr_relative_error
 The current relative error of the current iteration.
 
double d_alpha
 The alpha constant.
 
double d_max_clamp
 The max_clamp constant.
 
double d_error_indicator_tol
 The error indicator tolerance used to terminate the greedy procedure.
 
double d_relative_error_tol
 The relative error tolerance used to terminate the greedy procedure.
 
int d_num_parameter_points
 The maximum number of parameter points to sample.
 
int d_subset_size
 The size of the subset of parameter points used per iteration.
 
int d_convergence_subset_size
 The size of the subset of parameter points used to check convergence.
 
int d_next_point_to_sample
 The next parameter point to sample.
 
int d_next_point_requiring_error_indicator
 The next parameter point requiring a error indicator.
 
bool d_use_centroid
 Whether the use the centroid heuristic for obtaining the first parameter point.
 
bool d_check_local_rom
 Whether the check the last sampled local ROM's error indicator after each iteration.
 
bool d_iteration_started
 Whether the database has already computed a new parameter point for the current iteration.
 
bool d_convergence_started
 Whether the database is in the convergence verifying phase.
 
bool d_next_parameter_point_computed
 Whether the database has already computed a new parameter point to sample.
 
bool d_point_requiring_error_indicator_computed
 Whether the database has already computed a new paramter point requiring a error indicator.
 
bool d_subset_created
 Whether the database has already created a random subset for this iteration.
 
bool d_debug_algorithm
 Turn off randomness for debugging purposes.
 
int d_counter
 An internal counter.
 
int d_subset_counter
 An internal subset counter.
 
bool d_procedure_completed
 Whether the greedy procedure has completed.
 
int d_rank
 The rank of the given processor.
 
int d_random_seed
 Then random seed used to generate subsets.
 
std::default_random_engine rng
 Random engine used to generate subsets.
 

Detailed Description

Class GreedyRandomSampler implements a variant of Choi et. al's greedy algorithm using random sampling or latin-hypercube sampling.

Definition at line 26 of file GreedyRandomSampler.h.

Constructor & Destructor Documentation

◆ GreedyRandomSampler() [1/3]

CAROM::GreedyRandomSampler::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.

Parameters
[in]param_space_minA CAROM::Vector representing the minimum of the parameter space domain.
[in]param_space_maxA CAROM::Vector representing the maximum of the parameter space domain.
[in]num_parameter_pointsThe maximum number of parameter points to sample.
[in]check_local_romCompute local ROM error indicator each iteration.
[in]relative_error_toleranceThe relative error tolerance value for which to end the algorithm.
[in]alphaA alpha constant to increase greedy algorithm by each iteration.
[in]max_clampA scalar factor representing the maximum amount the error indicator tolerance can change per iteration.
[in]subset_sizeThe size of the random subset.
[in]convergence_subset_sizeThe size of the convergence subset.
[in]use_latin_hypercubeWhether to use latin-hypercube sampling instead of random sampling.
[in]output_log_pathThe path to the output log file. If not used, outputs to stdout.
[in]warm_start_file_nameThe path to the HDF5 file of a previous database to use as a warm start.
[in]use_centroidWhether to use the centroid heuristic when determining the first parameter point to sample.
[in]random_seedA random seed.
[in]debug_algorithmWhether to turn off all randomness for debugging purposes.

Definition at line 77 of file GreedyRandomSampler.cpp.

◆ GreedyRandomSampler() [2/3]

CAROM::GreedyRandomSampler::GreedyRandomSampler ( double  param_space_min,
double  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.

Parameters
[in]param_space_minA double representing the minimum of the parameter space domain.
[in]param_space_maxA double representing the maximum of the parameter space domain.
[in]num_parameter_pointsThe maximum number of parameter points to sample.
[in]check_local_romCompute local ROM error indicator each iteration.
[in]relative_error_toleranceThe relative error tolerance value for which to end the algorithm.
[in]alphaA alpha constant to increase greedy algorithm by each iteration.
[in]max_clampA scalar factor representing the maximum amount the error indicator tolerance can change per iteration.
[in]subset_sizeThe size of the random subset.
[in]convergence_subset_sizeThe size of the convergence subset.
[in]use_latin_hypercubeWhether to use latin-hypercube sampling instead of random sampling.
[in]output_log_pathThe path to the output log file. If not used, outputs to stdout.
[in]warm_start_file_nameThe path to the HDF5 file of a previous database to use as a warm start.
[in]use_centroidWhether to use the centroid heuristic when determining the first parameter point to sample.
[in]random_seedA random seed.
[in]debug_algorithmWhether to turn off all randomness for debugging purposes.

Definition at line 24 of file GreedyRandomSampler.cpp.

◆ GreedyRandomSampler() [3/3]

CAROM::GreedyRandomSampler::GreedyRandomSampler ( std::string  base_file_name,
std::string  output_log_path = "" 
)

Constructor.

Parameters
[in]base_file_nameThe base part of the file of the database to load when restarting from a save.
[in]output_log_pathThe path to the output log file. If not used, outputs to stdout.

Definition at line 130 of file GreedyRandomSampler.cpp.

Member Function Documentation

◆ load()

void CAROM::GreedyRandomSampler::load ( std::string  base_file_name)
protectedvirtual

Load the object state from a file.

Parameters
[in]base_file_nameThe base part of the file to load the database from.

Reimplemented from CAROM::GreedySampler.

Definition at line 193 of file GreedyRandomSampler.cpp.

◆ save()

void CAROM::GreedyRandomSampler::save ( std::string  base_file_name)
virtual

Save the object state to a file.

Parameters
[in]base_file_nameThe base part of the file to save the database to.

Reimplemented from CAROM::GreedySampler.

Definition at line 214 of file GreedyRandomSampler.cpp.


The documentation for this class was generated from the following files: