Commit a0198e3a authored by Marius Isken's avatar Marius Isken
Browse files

bugfix: nbootstrap

parent a3f71d43
......@@ -369,7 +369,8 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):
if weed != 3:
for ibootstrap in range(config.solver_config.nbootstrap):
bms = problem.bootstrap_misfits(misfits, ibootstrap)
bms = problem.bootstrap_misfits(
misfits, ibootstrap, config.solver_config.nbootstrap)
isort = num.argsort(bms)
ibests_list.append(isort[:nbest])
ibests.append(isort[0])
......@@ -462,7 +463,7 @@ def check(
x = problem.preconstrain(x)
break
except Forbidden:
except Exception:
pass
sources.append(problem.get_source(x))
......
......@@ -112,11 +112,15 @@ class GrondModel(object):
def __init__(self, **kwargs):
self.listeners = []
self.set_config(None)
self.set_problem(None)
def add_listener(self, listener):
self.listeners.append(listener)
def set_config(self, config):
self.config = config
def set_problem(self, problem):
self.problem = problem
......@@ -810,6 +814,7 @@ def draw_bootstrap_figure(model, plt):
fig = plt.figure()
problem = model.problem
solver = model.config.solver_config
gms = problem.global_misfits(model.misfits)
imodels = num.arange(model.nmodels)
......@@ -819,8 +824,9 @@ def draw_bootstrap_figure(model, plt):
gms_softclip = num.where(gms > 1.0, 0.1 * num.log10(gms) + 1.0, gms)
ibests = []
for ibootstrap in range(problem.nbootstrap):
bms = problem.bootstrap_misfits(model.misfits, ibootstrap)
for ibootstrap in range(solver.nbootstrap):
bms = problem.bootstrap_misfits(
model.misfits, ibootstrap, solver.nbootstrap)
isort_bms = num.argsort(bms)[::-1]
ibests.append(isort_bms[-1])
......@@ -1750,6 +1756,12 @@ def plot_result(dirname, plotnames_want,
model.set_problem(problem)
model.append(xs, misfits)
config = guts.load(filename=op.join(dirname, 'config.yaml'))
config.set_basepath(dirname)
config.setup_modelling_environment(problem)
model.set_config(config)
for plotname in ['bootstrap', 'sequence', 'contributions']:
if plotname in plotnames_want:
figs = plot_dispatch[plotname](model, plt)
......@@ -1772,13 +1784,16 @@ def plot_result(dirname, plotnames_want,
model.set_problem(problem)
model.append(xs, misfits)
config = guts.load(filename=op.join(dirname, 'config.yaml'))
config.set_basepath(dirname)
config.setup_modelling_environment(problem)
model.set_config(config)
for plotname in ['fits', 'fits_statics']:
if plotname in plotnames_want:
config = guts.load(filename=op.join(dirname, 'config.yaml'))
config.set_basepath(dirname)
config.setup_modelling_environment(problem)
event_name = problem.base_source.name
ds = config.get_dataset(event_name)
ds = model.config.get_dataset(event_name)
figs = plot_dispatch[plotname](ds, model, plt)
if save:
fns.extend(
......
......@@ -286,7 +286,7 @@ class Problem(Object):
else:
self.raise_invalid_norm_exponent()
def bootstrap_misfit(self, ms, ns, ibootstrap=None):
def bootstrap_misfit(self, ms, ns, ibootstrap=None, nbootstraps=None):
# Should this be nbootstrap?
exp, root = self.get_norm_functions()
......@@ -299,10 +299,11 @@ class Problem(Object):
w *= self.get_bootstrap_weights(ibootstrap)
return root(num.nansum(exp(w*ms)) / num.nansum(exp(w*ns)))
def bootstrap_misfits(self, misfits, ibootstrap):
def bootstrap_misfits(self, misfits, ibootstrap, nbootstraps):
exp, root = self.get_norm_functions()
w = self.get_bootstrap_weights(ibootstrap)[num.newaxis, :] * \
w = self.get_bootstrap_weights(
nbootstraps, ibootstrap)[num.newaxis, :] * \
self.get_target_weights()[num.newaxis, :] * \
self.inter_group_weights2(misfits[:, :, 1])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment