Class mcmc_para_emu (o2scl)

O2scl : Class List

template<class func_t, class fill_t, class data_t, class vec_t = ubvector>
class mcmc_para_emu : public o2scl::mcmc_para_cli<std::function<int(size_t, const ubvector&, double&, data_t&)>, fill_t, data_t, ubvector>

MCMC with an emulator.

In order to retrain in the middle of an MCMC run, we need three tables for the emulator. First, the base table containing all the data potentially used for the emulator. Then a table each for the training and testing data. Similarly, we need three tables for the classifier.

For now, we force the user to handle any retraining of the proposal distribution (i.e. through a virtual function mechanism), because that retraining requires a more careful consideration of autocorrelations.

This class is experimental.

Note

OpenMP threading probably doesn’t work yet. This class currently requires Python support (for the classifier).

Constructor and destructor

std::vector<std::shared_ptr<interpm_base<ubvector, o2scl::const_matrix_view_table<>, o2scl::matrix_view_table<>>>> emu

List of shared pointers to the interpolators.

This list should have a size equal to the number of threads times the number of emulators to try for each thread. If the number of threads is larger than 1, then it is the user’s responsibility to ensure these emulators are thread safe.

If test_size is greater than zero and the number of emulators for each thread is larger than 1, then the code will train all of the emulators and ensure that the best emulator is used for subsequent calculations.

If the number of emulators for each thread is larger than 1 but test_size is 0, then only the first n_threads emulators will be used.

std::vector<std::shared_ptr<classify_python<ubvector, ubvector_int, o2scl::const_matrix_view_table<>, o2scl::matrix_view_table<>>>> cl_list

List of shared pointers to the classifiers.

This list should have a size equal to the number of threads times the number of classifiers to try for each thread. If the number of threads is larger than 1, then it is the user’s responsibility to ensure these classifiers are thread safe.

If test_size is greater than zero and the number of classifiers for each thread is larger than 1, then the code will train all of the classifiers and ensure that the best classifier is used for subsequent calculations.

If the number of classifiers for each thread is larger than 1 but test_size is 0, then only the first n_threads classifiers will be used.

inline mcmc_para_emu()
inline virtual ~mcmc_para_emu()
inline virtual int point_wrapper(size_t it, size_t np, const vec_t &p, double &log_wgt, data_t &dat)

Wrapper to the point function which uses the emulator and the classifier.

inline virtual void outside_parallel()

Update the emulator outside the parallel region.

inline virtual void file_header(o2scl_hdf::hdf_file &hf)

Initial write to HDF5 file.

inline virtual int add_line(const vec_t &pars, double log_weight, size_t walker_ix, int func_ret, bool mcmc_accept, data_t &dat, size_t i_thread, fill_t &fill)

The function to add a line to the table.

This function computes the full likelihood in case of an acceptance.

inline void emu_train()

Train the emulator.

inline void class_train()

Train the classifier.

inline int mcmc_emu(size_t n_params_local, vec_t &low, vec_t &high, std::vector<func_t> &func, std::vector<fill_t> &fill, std::vector<data_t> &data)

The new MCMC function.

inline virtual int mcmc_fill(size_t n_params_local, vec_t &low, vec_t &high, std::vector<func_t> &func, std::vector<fill_t> &fill, std::vector<data_t> &data)

Perform an MCMC without using any emulators or classifiers.

Public Types

typedef std::function<int(size_t, const vec_t&, double&, data_t&)> internal_point_t
typedef mcmc_para_cli<std::function<int(size_t, const vec_t&, double&, data_t&)>, fill_t, data_t, vec_t> parent_t

Public Members

std::string emu_file

File containing the training data for the emulator.

std::string class_file

File containing the training data for the classifier.

std::string emu_tname

File containing the training data for the emulator.

std::string class_tname

File containing the training data for the classifier.

size_t max_emu_size

Maximum size of emulator training tables (default 1000)

size_t max_class_size

Maximum size of classifier training tables (default 1000)

size_t n_retrain

Number of iterations before retraining (default 0)

A value of 0 means that the emulator will never be retrained.

bool use_classifier

If true, use a classifier (default false)

bool use_emulator

If true, use an emulator (default false)

bool exact_accept

If true, evaluate accepted points with full function (default false)

int show_emu

If true, show the emulator accuracy (default 0)

double test_size

Test size for emulator and classifier training (default 0)

Protected Attributes

o2scl::table_units emu_table

Table containing training data for the emulator.

o2scl::table_units emu_test

Table containing testing data for the emulator.

o2scl::table_units emu_base

Table containing initial emulator training file.

o2scl::table_units class_table

Table containing training data for the classifier.

o2scl::table_units class_test

Table containing testing data for the classifier.

o2scl::table_units class_base

Table containing initial classifier training file.

size_t n_rows_emu_base

The number of rows in the original training data file.

size_t n_rows_class_base

The number of rows in the original training data file.

std::vector<func_t> *func_ptr

Pointer to the user-specified function array.

size_t n_params_child

The number of parameters.

size_t next_retrain_sum

Sum at last retraining.

size_t n_total_emu

Number of total emulator calls.

size_t n_total_class

Number of total classifier calls.

size_t n_class_reject

Number of points rejected by the classifier.

size_t n_exact

Number of exact function calls.

size_t table_rows_inc

Number of table rows included in training and testing.

size_t next_retrain_row_emu

Next row in the emu_base table to add to the training and testing tables.

size_t next_retrain_row_class

Next row in the class_base table to add to the training and testing tables.