The problems.base module

Base classes for Grond’s problem definition and the model history container.

Common behaviour of all source models offered by Grond is implemented here. Source model specific details are implemented in the respective submodules.

class grond.problems.base.ProblemConfig(**kwargs)[source]

Base class for config section defining the objective function setup.

Factory for Problem objects.

name_template

str

norm_exponent

int, default: 2

nthreads

int, default: 1

get_problem(event, target_groups, targets)[source]

Instantiate the problem with a given event and targets.

Returns

Problem object

class grond.problems.base.Problem(**kwargs)[source]

Base class for objective function setup.

Defines the problem to be solved by the optimiser.

name

str

ranges

dict of pyrocko.gf.seismosizer.Range objects, default: {}

dependants

list of grond.meta.Parameter objects, default: []

norm_exponent

int, default: 2

base_source

pyrocko.gf.seismosizer.Source, optional

targets

list of grond.targets.base.MisfitTarget objects, default: []

target_groups

list of grond.targets.base.TargetGroup objects, default: []

grond_version

str, optional

nthreads

int, default: 1

combine_misfits(misfits, extra_weights=None, extra_residuals=None, extra_correlated_weights={}, get_contributions=False)[source]

Combine misfit contributions (residuals) to global or bootstrap misfits

Parameters
  • misfits – 3D array misfits[imodel, iresidual, 0] are the misfit contributions (residuals) misfits[imodel, iresidual, 1] are the normalisation contributions. It is also possible to give the misfit and normalisation contributions for a single model as misfits[iresidual, 0] and misfits[iresidual, 1]`` in which case, the first dimension (imodel) of the result will be stipped off.

  • extra_weights – if given, 2D array of extra weights to be applied to the contributions, indexed as extra_weights[ibootstrap, iresidual].

  • extra_residuals – if given, 2D array of perturbations to be added to the residuals, indexed as extra_residuals[ibootstrap, iresidual].

  • extra_correlated_weights – if a dictionary of imisfit: correlated weight matrix is passed a correlated weight matrix is applied to the misfit and normalisation values. imisfit is the starting index in the misfits vector the correlated weight matrix applies to.

  • get_contributions – get the weighted and perturbed contributions (don’t do the sum).

Returns

if no extra_weights or extra_residuals are given, a 1D array indexed as misfits[imodel] containing the global misfit for each model is returned, otherwise a 2D array misfits[imodel, ibootstrap] with the misfit for every model and weighting/residual set is returned.

inter_family_weights2(ns)[source]
Parameters

ns – 2D array with normalization factors ns[imodel, itarget]

Returns

2D array weights[imodel, itarget]

class grond.problems.base.ModelHistory(problem, nchains=None, path=None, mode='r')[source]

Write, read and follow sequences of models produced in an optimisation run.

Parameters
  • problemgrond.Problem instance

  • path (str, optional) – path to rundir, defaults to None

  • mode (str, optional) – open mode, ‘r’: read, ‘w’: write

add_listener(listener)[source]

Add a listener to the history

The listening class can implement the following methods: * extend

classmethod follow(path, nchains=None, wait=20.0)[source]

Start following a rundir (constructor).

Parameters
  • path (str, optional) – the path to follow, a grond rundir

  • wait (number in seconds, optional) – wait time until the folder become alive

Returns

A ModelHistory instance

update()[source]

Update history from path

exception grond.problems.base.ProblemInfoNotAvailable[source]
exception grond.problems.base.ProblemDataNotAvailable[source]
exception grond.problems.base.InvalidAttributeName[source]
exception grond.problems.base.NoSuchAttribute[source]