invert4geom.optimization#

Module Contents#

Classes#

OptimalEqSourceParams

a class for finding the optimal depth and damping parameters to best fit a set of

Functions#

logging_callback(study, frozen_trial)

custom optuna callback, only print trial if it's the best value yet.

available_cpu_count()

Number of available virtual or physical CPUs on this system, i.e.

optuna_parallel(study_name, study_storage, objective)

Run optuna optimization in parallel. Pre-define the study, storage, and objective

optuna_max_cores(n_trials, optimize_study, study_name, ...)

Set up optuna optimization in parallel splitting up the number of trials over all

optuna_1job_per_core(n_trials, optimize_study, ...)

Set up optuna optimization in parallel giving each available core 1 trial.

optimize_eq_source_params(coordinates, data[, ...])

find the best parameter values for fitting equivalent sources to a set of gravity

Attributes#

optuna

joblib

psutil

tqdm_joblib

optuna[source]#
joblib[source]#
psutil[source]#
tqdm_joblib[source]#
logging_callback(study, frozen_trial)[source]#

custom optuna callback, only print trial if it’s the best value yet.

Parameters:
Return type:

None

available_cpu_count()[source]#

Number of available virtual or physical CPUs on this system, i.e. user/real as output by time(1) when called with an optimally scaling userspace-only program

Adapted from https://stackoverflow.com/a/1006301/18686384

Return type:

Any

optuna_parallel(study_name, study_storage, objective, n_trials=100, maximize_cpus=True, parallel=True)[source]#

Run optuna optimization in parallel. Pre-define the study, storage, and objective function and input them here.

Parameters:
  • study_name (str)

  • study_storage (Any)

  • objective (Callable[Ellipsis, float])

  • n_trials (int)

  • maximize_cpus (bool)

  • parallel (bool)

Return type:

tuple[Any, pandas.DataFrame]

optuna_max_cores(n_trials, optimize_study, study_name, study_storage, objective)[source]#

Set up optuna optimization in parallel splitting up the number of trials over all available cores.

Parameters:
  • n_trials (int)

  • optimize_study (Callable[Ellipsis, None])

  • study_name (str)

  • study_storage (Any)

  • objective (Callable[Ellipsis, float])

Return type:

None

optuna_1job_per_core(n_trials, optimize_study, study_name, study_storage, objective)[source]#

Set up optuna optimization in parallel giving each available core 1 trial.

Parameters:
  • n_trials (int)

  • optimize_study (Callable[Ellipsis, None])

  • study_name (str)

  • study_storage (Any)

  • objective (Callable[Ellipsis, float])

Return type:

None

class OptimalEqSourceParams(coordinates, data, damping_limits, depth_limits, **kwargs)[source]#

a class for finding the optimal depth and damping parameters to best fit a set of equivalent sources to the gravity data.

Parameters:
__call__(trial)[source]#
Parameters:

trial (optuna.trial) – the trial to run

Returns:

the score of the eq_sources fit

Return type:

float

optimize_eq_source_params(coordinates, data, n_trials=0, damping_limits=(0, 10**3), depth_limits=(0, 10000000.0), sampler=None, parallel=False, fname='tmp', use_existing=False, **eq_kwargs)[source]#

find the best parameter values for fitting equivalent sources to a set of gravity data.

Parameters:
  • coordinates (tuple[pd.Series | NDArray, pd.Series | NDArray,) – pd.Series | NDArray] easting, northing, and upwards coordinates of gravity data

  • data (pd.Series | NDArray) – gravity data values

  • n_trials (int, optional) – number of trials to perform / set of parameters to test, by default 0

  • damping_limits (tuple[float, float], optional) – lower and upper bounds of damping parameter, by default (0, 10**3)

  • depth_limits (tuple[float, float], optional) – lower and upper bounds of depth parameter, by default (0, 10e6)

  • sampler (optuna.samplers.BaseSampler | None, optional) – type of sampler to use, by default None

  • parallel (bool, optional) – if True, will run the trials in parallel, by default False

  • fname (str, optional) – path and filename to save the study results, by default “tmp”

  • use_existing (bool, optional) – if True, will continue a previously starting optimization, by default False

  • eq_kwargs (Any)

Returns:

gives a dataframe of the tested parameter sets and associated scores, and the best resulting fitted equivalent sources.

Return type:

tuple[pd.DataFrame, hm.EquivalentSources]