Optimize single objective

PyALAF.optimize.run_batch_learning(model, regression_model, acquisition_function='ideal', pool=None, batch_size=1, noise=0.1, initial_samples=2, active_learning_steps=10, lim=[-1, 1], alpha=0, random_state=None, return_samples=False, initialization='random', test_set=None, poly_degree=3, fictive_noise_level=0, calculate_test_metrics=True, custom_acfn_input=None)[source]

Perform batch-mode Active Learning for a discrete parameter space. The algorithm picks automatically initial data points from a given pool of discrete possible data points for evaluation using either a random approach or the model-free GSx method.

Parameters:
  • model (Model class) – Model to generate true data.

  • regression_model (sklearn model, str, optional) – scikit-learn regression model.

  • acquissition_function (str, optional) – Acquisition function. The default is ‘ideal’.

  • pool (nd_array, None, optional) – Array containing pool of data. All data is sampled from that pool. Data which is not sampled so far is used for calculating test metrics when test_set is None. For ‘None’ a grid with 100 points in each dimension is created. The default is ‘None’.

  • batch_size (int, optional) – Batch size for Active Learning. The model is updated only with true data when a batch is completed. The default value is 1.

  • noise (float, optional) – Noise in observation. The default is 0.1.

  • initial_samples (int, optional) – Number of initial samples to draw from the pool. The default is 2.

  • active_learning_steps (int, optional) – Number of active learning steps to perform. The default is 10.

  • lim (list, optional) – Boundaries for model evaluation. Only used when pool=None. The default is [-1,1].

  • alpha (float) – Hyperparameter for acquisition function. The default is 0.

  • random_state (int, optional) – Set random state. The default is None.

  • return_samples (bool, optional) – Whether to return the samples drawn so far. The default is False.

  • initialization (str, optional) – Initialization method for generating initial data. Choose from ‘random’ and ‘GSx’. ‘random’ uses Latin Hypercube sampling to generate the initial dat points. ‘GSx’ draws randomly the first data point and then uses the model-free GSx method to sample the other initial data points. The default value is ‘random’.

  • test_set (nd_array, optional) – Array containing explicit data points for testing. If it is ‘None’ all unsampled data points in the pool will be used for testing. The default value is ‘None’.

  • calculate_test_metrics (bool, optional) – Can be used for testing Active Learning algorithms for known models. Test metrics are calculated automatically. If ‘False’ no test metrics are calculated and the AL runs in deployement mode.

Returns:

  • results (pd_DataFrame) – Pandas DataFrame containing the columns: ‘m’, ‘mean_mse_test’, ‘max_observation’. Data is stored for each active learning step, where ‘m’ gives the number of data used for training, ‘mean_mse_test’ the MSE of the test set and ‘max_observation’ the maximum value observed so far.

  • sample_x (nd_array, optional) – Array that contains the sampled data points (in terms of their features). Only returned when return_samples is True.

PyALAF.optimize.run_continuous_batch_learning(model, regression_model, acquisition_function='ideal', opt_method='PSO', pool=None, batch_size=1, noise=0.1, initial_samples=2, active_learning_steps=10, lim=[-1, 1], alpha=0, n_jobs=1, random_state=None, initialization='random', pso_options=None, fictive_noise_level=0, poly_degree=3, calculate_test_metrics=True, custom_acfn_input=None)[source]

Perform batch-mode Active Learning in continuous parameter space for a given model generating the true data and a give regression model. The algorithm generates initial data automatically using either a random approach or using the model-free GSx approach.

Parameters:
  • model (Model class) – Model to generate true data.

  • regression_model (sklearn model, str, optional) – scikit-learn regression model.

  • acquissition_function (str, optional) – Acquisition function. Can also be a Callable. Then in custom_acfn_input it needs to be specified which input the custom function takes. The Callable should only take the input in the described order. The default is ‘ideal’.

  • opt_method (str, optional) – The method to optimize the acquisition function. Choose from ‘lbfgs’ and ‘PSO’. The default is ‘PSO’.

  • pool (nd_array, None, optional) – Array containing pool of data that is used for testing. For ‘None’ a grid with 100 points in each dimension is created. The default is ‘None’.

  • batch_size (int, optional) – Batch size for Active Learning. The model is updated only with true data when a batch is completed. The default value is 1.

  • noise (float, optional) – Noise in observation. The default is 0.1.

  • initial_samples (nd_array, int, optional) – If an integer is provided: Number of initial samples to draw. The default is 2. If an nd_array is provided: Initial data points. The parameter ‘initialization’ must be ‘data’.

  • active_learning_steps (int, optional) – Number of active learning steps to perform. The default is 10.

  • lim (list, optional) – Boundaries for model evaluation. Only used when pool=None. The default is [-1,1].

  • alpha (float, optional) – Hyperparameter for acquisition function. The default is 0.

  • n_jobs (int, optional) – Number of cores to use for parallel evaluation of PSO. Currently not used, PSO runs only in serial mode. The default is 1.

  • random_state (int, optional) – Set random state. The default is None.

  • initialization (str, optional) – Initialization method for generating initial data. Choose from ‘random’, ‘GSx’ or ‘data’. ‘random’ uses Latin Hypercube sampling to generate the initial dat points. ‘GSx’ draws randomly the first data point and then uses the model-free GSx method to sample the other initial data points. If ‘data’ is chosen, the initial data is assumed to be provided by ‘initial_samples’. The default value is ‘random’.

  • pso_options (dict, optional) – Dictionary with parameters for the Particle Swarm Optimization. Only used when opt_method is ‘PSO’. For ‘None’ default values are used. [‘c1’: 0.5, ‘c2’: 0.3, ‘w’: 0.9, ‘p’:dimensions*10, ‘i’:200]. c1 and c2 are swarm parmeters, w is the inertia, p gives the number of particles, i is the number of iterations. The default is ‘None’.

  • fictive_noise_level (float, optional) – Noise level for non-GPR models used for assuming predictions as true values to enable batch-wise learning.

  • calculate_test_metrics (bool, optional) – Can be used for testing Active Learning algorithms for known models. Test metrics are calculated automatically. If ‘False’ no test metrics are calculated and the AL runs in deployement mode.

  • custom_args_input (list, optional) –

    List of arguments which a custom acquisition function takes. It is important that the callable takes the arguments in the described order. The arguments must also be named as described here:

    x0: First argument, does not need to appear in this list. x: Values of the features of all evaluated samples y: Objective values of all evaluated samples max_y: Maximum observed value of all evaluated samples regression_model: sklearn model used for the fitting lim: boundary alpha: hyperparameter poly_x: sklearn poly_transformer. Must be given if a linear regression model should be used with the acquisition function

    The callable must return the value of the acquisition function as a float or as a numpy_array of floats.

Returns:

  • sample_x (nd_array) – Array that contains the sampled data points (in terms of their features).

  • results (pd_DataFrame, optional) – Pandas DataFrame containing the columns: ‘m’, ‘mean_mse_test’, ‘max_observation’. Data is stored for each active learning step, where ‘m’ gives the number of data used for training, ‘mean_mse_test’ the MSE of the test set and ‘max_observation’ the maximum value observed so far. Only returned when calculate_test_metrics is ‘True’.