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

#include <GreedySampler.h>

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

Public Member Functions

 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...
 
virtual void save (std::string base_file_name)
 Save the object state to a file. More...
 
bool isComplete ()
 Check if the greedy algorithm procedure is complete. More...
 

Protected Member Functions

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...
 
virtual void load (std::string base_file_name)
 Load the object state from a file. More...
 
virtual void constructParameterPoints ()=0
 Construct the list of parameter point candidates to sample.
 
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.
 
virtual void getNextParameterPointAfterConvergenceFailure ()=0
 Get the next parameter point to sample after a convergence failure.
 
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

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 GreedySampler is a class defining the interface of a greedy algorithm that given a domain of parameter points, iteratively returns the next best parameter point to sample in order to create a ROM database efficiently.

Definition at line 74 of file GreedySampler.h.

Constructor & Destructor Documentation

◆ GreedySampler() [1/5]

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.

Parameters
[in]parameter_pointsA vector of CAROM::Vectors containing many user-defined parameter points from which a subset will be chosen for building ROMs.
[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 constant factor to increase the error indicator tolerance 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]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 101 of file GreedySampler.cpp.

◆ GreedySampler() [2/5]

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

Parameters
[in]parameter_pointsA vector of doubles containing the different parameter points.
[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]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 125 of file GreedySampler.cpp.

◆ GreedySampler() [3/5]

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

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]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 157 of file GreedySampler.cpp.

◆ GreedySampler() [4/5]

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

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]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 184 of file GreedySampler.cpp.

◆ GreedySampler() [5/5]

CAROM::GreedySampler::GreedySampler ( 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 216 of file GreedySampler.cpp.

Member Function Documentation

◆ addDatabaseFromFile()

void CAROM::GreedySampler::addDatabaseFromFile ( std::string const &  warm_start_file_name)
protected

Do a warm start by adding the sampled parameters from the database in a file to the current database.

Parameters
[in]warm_start_file_nameThe path to the HDF5 file of a previous database to use as a warm start.

Definition at line 237 of file GreedySampler.cpp.

◆ generateRandomPoints()

std::vector< Vector > CAROM::GreedySampler::generateRandomPoints ( int  num_points)
protected

Generate a vector of random points.

Parameters
[in]num_pointsThe number of points to generate
Returns
A vector of random points.

Definition at line 1216 of file GreedySampler.cpp.

◆ getNearestNonSampledPoint()

int CAROM::GreedySampler::getNearestNonSampledPoint ( Vector  point)

Returns the index of the nearest non-sampled parameter point to the given point.

Parameters
[in]pointThe CAROM::Vector holding the point.
Returns
An integer holding the nearest non-sampled point to the given point or -1 if none exist.

Definition at line 1270 of file GreedySampler.cpp.

◆ getNearestROM()

std::shared_ptr< Vector > CAROM::GreedySampler::getNearestROM ( Vector  point)

Returns the nearest local ROM to the specified parameter point.

Parameters
[in]pointThe CAROM::Vector holding the point.
Returns
A shared pointer holding the point or NULL if no local ROM exists.

Definition at line 1240 of file GreedySampler.cpp.

◆ getNearestROMIndexToParameterPoint()

int CAROM::GreedySampler::getNearestROMIndexToParameterPoint ( int  index,
bool  ignore_self 
)
protected

Returns the index to the nearest local ROM to the specified parameter point index in the parameter point list.

Parameters
[in]indexThe index of the specified parameter point.
[in]ignore_selfWhether to ignore the specified parameter point if a local ROM was built there.
Returns
The index of the point in the list of parameters.

Definition at line 1295 of file GreedySampler.cpp.

◆ getNextConvergencePointRequiringErrorIndicator()

struct GreedyErrorIndicatorPoint CAROM::GreedySampler::getNextConvergencePointRequiringErrorIndicator ( )
protected

Get the next convergence point requiring an error indicator.

Returns
A struct holding the point and the location of the nearest local ROM or NULL if no point is required.

Definition at line 542 of file GreedySampler.cpp.

◆ getNextParameterPoint()

std::shared_ptr< Vector > CAROM::GreedySampler::getNextParameterPoint ( )

Returns the next parameter point for which sampling is required.

Returns
A shared pointer holding the point or NULL if a point is not ready to be sampled.

Definition at line 542 of file GreedySampler.cpp.

◆ getNextPointRequiringErrorIndicator()

struct GreedyErrorIndicatorPoint CAROM::GreedySampler::getNextPointRequiringErrorIndicator ( )

Returns the next parameter point for which an error indicator is required.

Returns
A struct holding the point and the location of the nearest local ROM or NULL if no point is required.

Definition at line 542 of file GreedySampler.cpp.

◆ getNextPointRequiringRelativeError()

struct GreedyErrorIndicatorPoint CAROM::GreedySampler::getNextPointRequiringRelativeError ( )

Returns the next parameter point for which a relative error is required.

Returns
A struct holding the point and the location of the nearest local ROM or NULL if no point is required.

Definition at line 542 of file GreedySampler.cpp.

◆ getNextSubsetPointRequiringErrorIndicator()

struct GreedyErrorIndicatorPoint CAROM::GreedySampler::getNextSubsetPointRequiringErrorIndicator ( )
protected

Get the next subset point requiring an error indicator.

Returns
A struct holding the point and the location of the nearest local ROM or NULL if no point is required.

Definition at line 542 of file GreedySampler.cpp.

◆ getParameterPointDomain()

std::vector< Vector > CAROM::GreedySampler::getParameterPointDomain ( )

Get the domain of the parameter points.

Returns
A vector holding all parameter point candidates.

Definition at line 1329 of file GreedySampler.cpp.

◆ getSampledParameterPoints()

std::vector< Vector > CAROM::GreedySampler::getSampledParameterPoints ( )

Get the sampled parameter points.

Returns
A vector holding all sampled parameter points.

Definition at line 1335 of file GreedySampler.cpp.

◆ isComplete()

bool CAROM::GreedySampler::isComplete ( )

Check if the greedy algorithm procedure is complete.

Returns
A boolean representing if the greedy algorithm procedure is complete.

Definition at line 1453 of file GreedySampler.cpp.

◆ load()

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

Definition at line 275 of file GreedySampler.cpp.

◆ printErrorIndicator()

void CAROM::GreedySampler::printErrorIndicator ( Vector  errorIndicatorPoint,
double  proc_errors 
)
protected

Print the error indicator.

Parameters
[in]errorIndicatorPointThe vector where the error indicator was obtained.
[in]proc_errorsThe error indicator value.

Definition at line 1009 of file GreedySampler.cpp.

◆ printSamplingType()

void CAROM::GreedySampler::printSamplingType ( std::string  sampling_type)
protected

Print the sampling type.

Parameters
[in]sampling_typeThe sampling type.

Definition at line 811 of file GreedySampler.cpp.

◆ save()

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

Definition at line 1346 of file GreedySampler.cpp.

◆ setConvergenceErrorIndicator()

void CAROM::GreedySampler::setConvergenceErrorIndicator ( double  proc_errors)
protected

Set the error indicator for a convergence point.

Parameters
[in]proc_errorsThe error indicator value.

Definition at line 1151 of file GreedySampler.cpp.

◆ setPointErrorIndicator()

void CAROM::GreedySampler::setPointErrorIndicator ( double  error,
int  vec_size 
)

Set the error indicator error of the specified parameter point.

Parameters
[in]errorThe error indicator value.
[in]vec_sizeThe size of the vector the error indicator was obtained from. This is used for normalization.

Definition at line 971 of file GreedySampler.cpp.

◆ setPointRelativeError()

void CAROM::GreedySampler::setPointRelativeError ( double  error)

Set the relative error of the specified point.

Parameters
[in]errorThe relative error.

Definition at line 854 of file GreedySampler.cpp.

◆ setSubsetErrorIndicator()

void CAROM::GreedySampler::setSubsetErrorIndicator ( double  proc_errors)
protected

Set the error indicator for a subset point.

Parameters
[in]proc_errorsThe error indicator value.

Definition at line 1055 of file GreedySampler.cpp.


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