profit.al

Submodules

Package Contents

Classes

ActiveLearning

Active learning base class.

SimpleAL

Simple active learning algorithm based on a surrogate model and an acquisition function to find next candidates.

McmcAL

Markov-chain Monte-Carlo active learning algorithm.

class profit.al.ActiveLearning(runner, variables, ntrain, nwarmup=defaults['nwarmup'], batch_size=defaults['batch_size'], convergence_criterion=defaults['convergence_criterion'], nsearch=defaults['nsearch'], make_plot=defaults['make_plot'])[source]

Bases: profit.util.base_class.CustomABC

Active learning base class.

Parameters:
  • runner (profit.run.Runner) – Runner to dynamically start runs.

  • variables (profit.util.variable.VariableGroup) – Variables.

  • ntrain (int) – Total number of training points.

  • nwarmup (int) – Number of warmup (random) initialization points.

  • batch_size (int) – Number of training samples learned in parallel.

  • convergence_criterion (float) – AL is stopped when the loss of the acquisition function is lower than this criterion. Not implemented yet.

  • nsearch (int) – Number of possible candidate points in each dimension.

  • make_plot (bool) – Flat indicating if the AL progress is plotted.

krun

Current training cycle.

Type:

int

labels
abstract warmup(save_intermediate=defaults['save_intermediate'])[source]

Warmup cycle before the actual learning starts.

abstract learn(resume_from=defaults['resume_from'], save_intermediate=defaults['save_intermediate'])[source]

Main loop for active learning.

update_run(candidates)[source]

Run a batch of simulations with the new candidates.

Parameters:

candidates (np.array) – Input points to run the simulation on.

update_data()[source]

Update the variables with the runner data.

abstract save(path)[source]

Save the AL model.

Parameters:

path (str) – Path where the model is saved.

save_intermediate(model_path=None, input_path=None, output_path=None)[source]
abstract plot()[source]

Plot the progress of the AL learning.

classmethod from_config(runner, variables, config, base_config)[source]

Instantiates an ActiveLearning object from the configuration parameters.

Parameters:
Returns:

AL instance.

Return type:

profit.al.active_learning.ActiveLearning

class profit.al.SimpleAL(runner, variables, surrogate, ntrain, nwarmup=base_defaults['nwarmup'], batch_size=base_defaults['batch_size'], acquisition_function=defaults['acquisition_function'], convergence_criterion=base_defaults['convergence_criterion'], nsearch=base_defaults['nsearch'], make_plot=base_defaults['make_plot'], searchtype=defaults['searchtype'])[source]

Bases: profit.al.ActiveLearning

Simple active learning algorithm based on a surrogate model and an acquisition function to find next candidates.

Parameters:
  • surrogate (profit.sur.Surrogate) – Surrogate used for fitting.

  • acquisition_function (str/profit.al.acquisition_functions.AcquisitionFunction) – Acquisition function used for selecting the next candidates.

search_space

np.linspace for each AL input variable.

Type:

dict[str, np.array]

Xpred

Matrix of the candidate points built with np.meshgrid.

Type:

np.array

labels
warmup(save_intermediate=base_defaults['save_intermediate'])[source]

To get data for active learning, sample initial points randomly.

learn(resume_from=base_defaults['resume_from'], save_intermediate=base_defaults['save_intermediate'])[source]

Main loop for active learning.

find_next_candidates()[source]

Find the next candidates using the acquisition function’s method find_next_candidates.

Returns:

Next training points.

Return type:

np.array

update_run(candidates)[source]

Run a batch of simulations with the new candidates.

Parameters:

candidates (np.array) – Input points to run the simulation on.

save(path)[source]

Save the AL model.

Parameters:

path (str) – Path where the model is saved.

plot()[source]

Plot the progress of the AL learning.

classmethod from_config(runner, variables, config, base_config)[source]

Instantiates an ActiveLearning object from the configuration parameters.

Parameters:
Returns:

AL instance.

Return type:

profit.al.active_learning.ActiveLearning

class profit.al.McmcAL(runner, variables, reference_data, ntrain, warmup_cycles=defaults['warmup_cycles'], nwarmup=base_defaults['nwarmup'], batch_size=base_defaults['batch_size'], target_acceptance_rate=defaults['target_acceptance_rate'], convergence_criterion=base_defaults['convergence_criterion'], nsearch=base_defaults['nsearch'], sigma_n=defaults['sigma_n'], make_plot=base_defaults['make_plot'], initial_points=defaults['initial_points'], save=defaults['save'], last_percent=defaults['last_percent'], delayed_acceptance=defaults['delayed_acceptance'])[source]

Bases: profit.al.ActiveLearning

Markov-chain Monte-Carlo active learning algorithm.

Parameters:
  • reference_data (np.ndarray) – Observed experimental data points. This is not the simulated model data!

  • warmup_cycles (int) – Number of warmup cycles with nwarmup iterations each.

  • target_acceptance_rate (float) – Target rate with which probability new points are accepted.

  • sigma_n (float) – Estimated standard deviation of the experimental data.

  • initial_points (list of float) – Starting points for the MCMC.

  • delayed_acceptancd (bool) – Whether to use delayed acceptance with a surrogate model for the likelihood.

Xpred

Matrix of the candidate points built with np.meshgrid.

Type:

np.ndarray

dx

Distance between iterations in parameter space.

Type:

np.ndarray

ndim

Dimension of input parameters.

Type:

int

Xtrain

Array of sampled MCMC points.

Type:

np.ndarray

log_likelihood

Array of the log likelihood during training.

Type:

np.ndarray

accepted

Boolean array of accepted/rejected sample MCMC points.

Type:

np.ndarray[bool]

labels
cost(y)[source]
f(x)[source]
warmup(save_intermediate=base_defaults['save_intermediate'])[source]

Warmup MCMC.

learn(resume_from=base_defaults['resume_from'], save_intermediate=base_defaults['save_intermediate'])[source]

Main loop for active learning.

do_mcmc(rng)[source]
update_run(candidates)[source]

Run a batch of simulations with the new candidates.

Parameters:

candidates (np.array) – Input points to run the simulation on.

update_data()[source]

Update the variables with the runner data.

save(path)[source]

Save the AL model.

Parameters:

path (str) – Path where the model is saved.

save_stats(path)[source]

Save mean and std of X values

plot()[source]

Plot the progress of the AL learning.

plot_mcmc(phase)[source]
classmethod from_config(runner, variables, config, base_config)[source]

Instantiates an ActiveLearning object from the configuration parameters.

Parameters:
Returns:

AL instance.

Return type:

profit.al.active_learning.ActiveLearning