adasamp package¶
adasamp.sampling¶
Adaptive sampling: Adaptive optimization algorithm for black-box multi-objective optimization problems with binary constraints on the foundation of Bayes optimization.
- class adasamp.sampling.AdaptiveSampler(simulation_func, X_limits, Y_ref, iterations, Y_model, f_model, initial_samples=0, virtual_iterations=1, initial_sampling_func='random', utility_parameter_options={}, decision_parameter_options={}, X_initial_sample_limits=None, callback_func=None, stopping_condition_func=None, seed=None, verbose=False, save_memory_flag=False)[source]¶
Bases:
objectAdaptive sampler.
- Parameters
simulation_func (callable) – Function calculating the goals and feasibilities for given features. Must be of the form
simulation_func(X, **kwargs)and returns a tuple(Y, f), whereXis an ndarray of shape (n_samples, X_dim) andkwargsis a dict of any additional fixed parameters needed to completely specify the function. The returned valueYis an ndarray of shape (n_samples, Y_dim) representing the resulting goal functions andfis an ndarray of shape (n_samples,) representing the resulting binary feasibilities. Thekwargsparameter is provided when starting the adaptive sampling run viasample. The adaptive sampling run aims to maximize Y s.t. f == True.X_limits (list of float tuples (pairs)) – Feature space limits given by a list of pairs of lower and upper bounds:
[ (x1min, x1max), (x2min, x2max), ... ]. This list also specifies the dimensionalityX_dim = len(X_limits)of the feature space.Y_ref (list of float) – Goal space reference point of the form
[ y1min, y2min, ... ]. All resulting goal function values must be dominated by the reference point (w.r.t. maximization) or undesired behaviour might occur. This list also specifies the dimensionalityY_dim = len(Y_ref)of the goal space.iterations (int) – Number of adaptive sampling iterations.
Y_model (RegressionModel) – Estimator object for the internal regression problem of predicting
Y(goals) fromX(features). See RegressionModel for details.f_model (ClassificationModel) – Estimator object for the internal classification problem of predicting
f(feasibilities) fromX(features). See ClassificationModel for details.initial_samples (int, optional (default: 0)) – Number of initial samples to calculate before starting the adaptive sampling loop.
virtual_iterations (int, optional (default: 1)) – Number of virtual adaptive sampling iterations. Specifies the number of suggested samples per adaptive sampling iteration. Must be at least 1.
initial_sampling_func (str or callable, optional (default: "random")) – Function suggesting the initial sampling points. Can either be a string or a callable. The string can either be ‘random’ for uniformly distributed random samples or ‘factorial’ for a (full or reduced) factorial design of experiments. The callable must be of the form
initial_sampling_func(initial_samples, X_initial_sample_limits, seed), whereinitial_samples(int) represents the number of initial samples, X_initial_sample_limits` (list of tuples) the respective feature space limits andseed(int) a given random seed.utility_parameter_options (dict, optional (default: {})) –
Set parameters specifying the utility function. If not set, default values are used. The following parameters are available (=default values):
entropy_weight=1: entropic weight
optimization_weight=1: optimality weight
repulsion_weight=1: repulsion weight
repulsion_gamma=1: repulsion coefficient
repulsion_distance_func=”default”: distance function (either “default” or a callable of the form
repulsion_distance_func(x, y)returning the scalar distance of two pointsxandy.)evi_gamma = 1: Pareto volume parameter
sector_cutoff = 1: Pareto volume cutoff
decision_parameter_options (dict, optional (default: {})) –
Set decision specifying the utility function. If not set, default values are used. The following parameters are available (=default values):
popsize=15: differential evolution setting
maxiter=1000: differential evolution setting
tol=.01: differential evolution setting
atol=.05: differential evolution setting
polish=True: differential evolution setting
polish_extratol=.1: differential evolution polishing setting
polish_maxfun=100: differential evolution polishing setting
de_workers=-1: number of workers (-1: use all available)
polish_workers=-1: number of workers (-1: use all available)
X_initial_sample_limits (list of tuples or None, optional (default: None)) – Feature space limits for the initial sampling given by a list of pairs of lower and upper bounds in analogy to
X_limits. If set to None,X_limitsis used instead.callback_func (callable or None, optional (default: None)) – Function which is called after every adaptive sampling iteration and after the inital sampling. Must be of the form
callback_func(sampler, X, Y, f, iteration), wheresampleris the AdaptiveSampler object (self),Xis an ndarray of shape (n_samples, X_dim),Yis an ndarray of shape (n_samples, Y_dim) andfis an ndarray of shape (n_samples,) representing all samples until the current iteration given byiteration(int or None for the inital sampling call). The return value is stored in theinfoproperty. The callback function ignored if set to None.stopping_condition_func (callable or None, optional (default: None)) – Function evaluating a specified stopping criterion. Must be of the form
stopping_condition_func(X, Y, f), where X` is an ndarray of shape (n_samples, X_dim),Yis an ndarray of shape (n_samples, Y_dim) andfis an ndarray of shape (n_samples,) representing all samples. The function is called at the end of every adaptive sampling iteration. Its return value is used to determine whether the adaptive sampling loop is stopped prematurely before the number of iterations is reached: a True return value leads to a stop. The stopping condition function ignored if set to None.seed (int or None, optional (default: None)) – Random seed used for all non-deterministic parts of the algorithm. If set to None, an unspecified (pseudo-random) seed is used.
verbose (bool, optional (default: False)) – Set to True to print status messages. Use the
loggingmodule if enabled.save_memory_flag (bool, optional (default: False)) – Set to True to activate the memory saving mode, which switches to a memory efficient Pareto volume calculation at the cost of a possibly longer runtime.
- property info¶
Current sampling information (statistics etc.) in form of a dictionary.
- initial_sampling_factorial(initial_samples, X_initial_sample_limits, seed)[source]¶
Create an initial factorial design of experiments. If no full factorial design is possible, a random subsampling is used.
- initial_sampling_random_uniform(initial_samples, X_initial_sample_limits, seed)[source]¶
Create a random initial design of experiments within the given limits of the feature space.
- property opt_func¶
Current optimization function of the form
opt_func(X, workers), whereXis an ndarray of shape (1, X_dim) corresponding to a single sampling point. The property defaults to None if the optimization function has not yet been specified (i.e., None or callable).
- sample(**kwargs)[source]¶
Start sampling.
Perform an adaptive sampling with this sampler and return the sampled results.
- Parameters
**kwargs (dict, optional) – Any additional fixed parameters needed to completely specify
simulation_func.- Returns
X (ndarray of shape (n_samples, X_dim)) – Resulting array of sampled features.
Y (ndarray of shape (n_samples, Y_dim)) – Resulting array of corresponding goals from the simulation.
f (ndarray of shape (n_samples,)) – Resulting array of corresponding binary feasibilities from the simulation.
adasamp.util¶
Helper toolbox for adaptive sampling.
adasamp.models¶
Wrappers for adaptive sampling models.
- class adasamp.models.ClassificationModel[source]¶
Bases:
ABCClassification model wrapper.
Estimator for the adaptive sampling classification problem of predicting
f(binary feasibilities) fromX(features).- abstract fit(X, f)[source]¶
Train estimator.
Is called at least once before any prediction. The class labels can be either True or False and are automatically converted to integers before the training.
- Parameters
X (ndarray of shape (n_samples, X_dim)) – Array of features (estimator inputs).
f (ndarray of shape (n_samples,)) – Array of binary classification labels (estimator targets).
- abstract predict(X)[source]¶
Classifier prediction.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
- Returns
f – Predicted labels at the query points.
- Return type
ndarray of shape (n_query_points,)
- abstract predict_true_proba(X)[source]¶
Classifier probability prediction.
Returns the predicted probability of a True label at the respective query points.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
- Returns
p – Predicted probability for a True label at the query points. It is assumed that
0 <= p <= 1.- Return type
ndarray of shape (n_query_points,)
- class adasamp.models.RegressionModel[source]¶
Bases:
ABCRegression model wrapper.
Estimator for the adaptive sampling regression problem of predicting
Y(goals) fromX(features).- abstract fit(X, Y)[source]¶
Train estimator.
Is called at least once before any prediction.
- Parameters
X (ndarray of shape (n_samples, X_dim)) – Array of features (estimator inputs).
Y (ndarray of shape (n_samples, Y_dim)) – Array of regression values (estimator targets).
- abstract predict(X, return_std)[source]¶
Estimator prediction.
It is assumed that the predictive distribution is a Gaussian specified by a mean and a standard deviation.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
return_std (bool) – If set to True, return both the means and the standard deviations. If set to False, only return the means.
- Returns
Y_mu (ndarray of shape (n_query_points, Y_dim)) – Mean of the predictive distribution at the query points.
Y_sigma (ndarray of shape (n_query_points, Y_dim)) – Standard deviation of the predictive distribution at the query points. Covariances are not returned.
adasamp.models_sklearn¶
Helper classes for simple adaptive sampling models based on scikit-learn.
- class adasamp.models_sklearn.AdvancedMultiOutputRegressor(model_constructor, predict_fun=None, **kwargs)[source]¶
Bases:
BaseEstimatorRegression model with multiple, independent outputs.
For each output, a seperate sklearn-model is realized.
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
params – Parameter names mapped to their values.
- Return type
dict
- set_params(**parameters)[source]¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters
**params (dict) – Estimator parameters.
- Returns
self – Estimator instance.
- Return type
estimator instance
- class adasamp.models_sklearn.MultivariateGPR(**kwargs)[source]¶
Bases:
AdvancedMultiOutputRegressorGaussian process regressor with multiple, independent outputs.
An independent GaussianProcessRegressor for each output is realized.
- class adasamp.models_sklearn.Y_Model_GPR(kernel=1**2 * Matern(length_scale=1, nu=1.5), n_restarts_optimizer=5, random_state=0)[source]¶
Bases:
RegressionModelGaussian process regressor with multiple, independent outputs including scaling.
Realizes a pipeline: Standardization, independent GaussianProcessRegressor for each output.
- fit(X, Y)[source]¶
Train estimator.
Is called at least once before any prediction.
- Parameters
X (ndarray of shape (n_samples, X_dim)) – Array of features (estimator inputs).
Y (ndarray of shape (n_samples, Y_dim)) – Array of regression values (estimator targets).
- predict(X, return_std)[source]¶
Estimator prediction.
It is assumed that the predictive distribution is a Gaussian specified by a mean and a standard deviation.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
return_std (bool) – If set to True, return both the means and the standard deviations. If set to False, only return the means.
- Returns
Y_mu (ndarray of shape (n_query_points, Y_dim)) – Mean of the predictive distribution at the query points.
Y_sigma (ndarray of shape (n_query_points, Y_dim)) – Standard deviation of the predictive distribution at the query points. Covariances are not returned.
- class adasamp.models_sklearn.f_Model_SVM(kernel='rbf', cv_dict={'C': array([0.1, 0.27825594, 0.774263683, 2.15443469, 5.9948425, 16.6810054, 46.4158883, 129.154967, 359.381366, 1000.0]), 'gamma': array([0.1, 0.27825594, 0.774263683, 2.15443469, 5.9948425, 16.6810054, 46.4158883, 129.154967, 359.381366, 1000.0])}, n_splits=3, random_state=0)[source]¶
Bases:
ClassificationModelSupport vector classifier inlcuding scaling.
Realizes a pipeline: Standardization, SVM with GridSearchCV hyperparameter optimization.
- fit(X, f)[source]¶
Train estimator.
Is called at least once before any prediction. The class labels can be either True or False and are automatically converted to integers before the training.
- Parameters
X (ndarray of shape (n_samples, X_dim)) – Array of features (estimator inputs).
f (ndarray of shape (n_samples,)) – Array of binary classification labels (estimator targets).
- predict(X)[source]¶
Classifier prediction.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
- Returns
f – Predicted labels at the query points.
- Return type
ndarray of shape (n_query_points,)
- predict_true_proba(X)[source]¶
Classifier probability prediction.
Returns the predicted probability of a True label at the respective query points.
- Parameters
X (ndarray of shape (n_query_points, X_dim)) – Query points where the estimator is evaluated.
- Returns
p – Predicted probability for a True label at the query points. It is assumed that
0 <= p <= 1.- Return type
ndarray of shape (n_query_points,)