Commit 092f75f3 authored by Marius Isken's avatar Marius Isken
Browse files

Merge branch 'python3' of gitext.gfz-potsdam.de:heimann/grond into python3

parents 2f543386 93c3c59c
...@@ -19,7 +19,8 @@ from .solvers.base import SolverConfig ...@@ -19,7 +19,8 @@ from .solvers.base import SolverConfig
from .targets.base import TargetGroup from .targets.base import TargetGroup
from .analysers.base import AnalyserConfig from .analysers.base import AnalyserConfig
from .listeners import TerminalListener from .listeners import TerminalListener
from .meta import Path, HasPaths, expand_template, xjoin, GrondError, Notifier from .meta import Path, HasPaths, expand_template, xjoin, GrondError, \
Notifier, Forbidden
logger = logging.getLogger('grond.core') logger = logging.getLogger('grond.core')
guts_prefix = 'grond' guts_prefix = 'grond'
...@@ -268,6 +269,8 @@ def bootstrap_outliers(problem, misfits, std_factor=1.0): ...@@ -268,6 +269,8 @@ def bootstrap_outliers(problem, misfits, std_factor=1.0):
Identify bootstrap configurations performing bad in global configuration Identify bootstrap configurations performing bad in global configuration
''' '''
raise Exception('this function is broken')
gms = problem.global_misfits(misfits) gms = problem.global_misfits(misfits)
ibests = [] ibests = []
...@@ -370,7 +373,7 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0): ...@@ -370,7 +373,7 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):
if weed != 3: if weed != 3:
for ibootstrap in range(config.solver_config.nbootstrap): for ibootstrap in range(config.solver_config.nbootstrap):
bms = problem.bootstrap_misfits( bms = problem.bootstrap_misfits(
misfits, ibootstrap, config.solver_config.nbootstrap) misfits, config.solver_config.nbootstrap, ibootstrap)
isort = num.argsort(bms) isort = num.argsort(bms)
ibests_list.append(isort[:nbest]) ibests_list.append(isort[:nbest])
ibests.append(isort[0]) ibests.append(isort[0])
...@@ -463,7 +466,7 @@ def check( ...@@ -463,7 +466,7 @@ def check(
x = problem.preconstrain(x) x = problem.preconstrain(x)
break break
except Exception: except Forbidden:
pass pass
sources.append(problem.get_source(x)) sources.append(problem.get_source(x))
......
...@@ -200,7 +200,7 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None, sort_by='misfit'): ...@@ -200,7 +200,7 @@ def draw_sequence_figures(model, plt, misfit_cutoff=None, sort_by='misfit'):
bounds = problem.get_parameter_bounds() bounds = problem.get_parameter_bounds()
if ndep > 0: if ndep > 0:
bounds = num.vstack((bounds, problem.get_dependant_bounds())) bounds = num.concatenate((bounds, problem.get_dependant_bounds()))
xref = problem.get_xref() xref = problem.get_xref()
...@@ -361,13 +361,16 @@ def draw_jointpar_figures( ...@@ -361,13 +361,16 @@ def draw_jointpar_figures(
msize = 1.5 msize = 1.5
problem = model.problem problem = model.problem
solver = model.config.solver_config
if not problem: if not problem:
return [] return []
xs = model.xs xs = model.xs
bounds = num.vstack( bounds = num.concatenate((
(problem.get_parameter_bounds(), problem.get_dependant_bounds())) problem.get_parameter_bounds(),
problem.get_dependant_bounds()))
for ipar in range(problem.ncombined): for ipar in range(problem.ncombined):
par = problem.combined[ipar] par = problem.combined[ipar]
lo, hi = bounds[ipar] lo, hi = bounds[ipar]
...@@ -380,7 +383,8 @@ def draw_jointpar_figures( ...@@ -380,7 +383,8 @@ def draw_jointpar_figures(
xref = problem.get_xref() xref = problem.get_xref()
if ibootstrap is not None: if ibootstrap is not None:
gms = problem.bootstrap_misfits(model.misfits, ibootstrap) gms = problem.bootstrap_misfits(
model.misfits, solver.nbootstrap, ibootstrap)
else: else:
gms = problem.global_misfits(model.misfits) gms = problem.global_misfits(model.misfits)
...@@ -827,7 +831,7 @@ def draw_bootstrap_figure(model, plt): ...@@ -827,7 +831,7 @@ def draw_bootstrap_figure(model, plt):
ibests = [] ibests = []
for ibootstrap in range(solver.nbootstrap): for ibootstrap in range(solver.nbootstrap):
bms = problem.bootstrap_misfits( bms = problem.bootstrap_misfits(
model.misfits, ibootstrap, solver.nbootstrap) model.misfits, solver.nbootstrap, ibootstrap)
isort_bms = num.argsort(bms)[::-1] isort_bms = num.argsort(bms)[::-1]
ibests.append(isort_bms[-1]) ibests.append(isort_bms[-1])
...@@ -1211,7 +1215,7 @@ def draw_fits_figures(ds, model, plt): ...@@ -1211,7 +1215,7 @@ def draw_fits_figures(ds, model, plt):
nframes = len(targets) nframes = len(targets)
nx = int(math.ceil(math.sqrt(nframes))) nx = int(math.ceil(math.sqrt(nframes)))
ny = int((nframes - 1) // nx + 1) ny = (nframes - 1) / nx + 1
nxmax = 4 nxmax = 4
nymax = 4 nymax = 4
...@@ -1605,8 +1609,9 @@ def draw_location_figure(model, plt): ...@@ -1605,8 +1609,9 @@ def draw_location_figure(model, plt):
axes_dn = fig.add_subplot(2, 2, 2) axes_dn = fig.add_subplot(2, 2, 2)
axes_ed = fig.add_subplot(2, 2, 3) axes_ed = fig.add_subplot(2, 2, 3)
bounds = num.vstack( bounds = num.concatenate((
(problem.get_parameter_bounds(), problem.get_dependant_bounds())) problem.get_parameter_bounds(),
problem.get_dependant_bounds()))
gms = problem.global_misfits(model.misfits) gms = problem.global_misfits(model.misfits)
...@@ -1876,8 +1881,9 @@ class SolverPlot(object): ...@@ -1876,8 +1881,9 @@ class SolverPlot(object):
self.bcolors = colors.hsv_to_rgb(hsv[num.newaxis, :, :])[0, :, :] self.bcolors = colors.hsv_to_rgb(hsv[num.newaxis, :, :])[0, :, :]
bounds = self.problem.get_parameter_bounds()\ bounds = num.concatenate((
+ self.problem.get_dependant_bounds() problem.get_parameter_bounds(),
problem.get_dependant_bounds()))
self.xlim = fixlim(*xpar.scaled(bounds[ixpar])) self.xlim = fixlim(*xpar.scaled(bounds[ixpar]))
self.ylim = fixlim(*ypar.scaled(bounds[iypar])) self.ylim = fixlim(*ypar.scaled(bounds[iypar]))
...@@ -1931,8 +1937,9 @@ class SolverPlot(object): ...@@ -1931,8 +1937,9 @@ class SolverPlot(object):
ps = core.excentricity_compensated_probabilities( ps = core.excentricity_compensated_probabilities(
xhist[chains_i[j, :], :], local_sxs[jchoice], 2.) xhist[chains_i[j, :], :], local_sxs[jchoice], 2.)
bounds = self.problem.get_parameter_bounds() + \ bounds = num.concatenate((
self.problem.get_dependant_bounds() self.problem.get_parameter_bounds(),
self.problem.get_dependant_bounds()))
x = num.linspace( x = num.linspace(
bounds[self.ixpar][0], bounds[self.ixpar][1], nx) bounds[self.ixpar][0], bounds[self.ixpar][1], nx)
......
...@@ -286,8 +286,7 @@ class Problem(Object): ...@@ -286,8 +286,7 @@ class Problem(Object):
else: else:
self.raise_invalid_norm_exponent() self.raise_invalid_norm_exponent()
def bootstrap_misfit(self, ms, ns, ibootstrap=None, nbootstraps=None): def bootstrap_misfit(self, ms, ns, nbootstrap, ibootstrap=None):
# Should this be nbootstrap?
exp, root = self.get_norm_functions() exp, root = self.get_norm_functions()
w = self.get_target_weights() * self.inter_group_weights(ns) w = self.get_target_weights() * self.inter_group_weights(ns)
...@@ -296,14 +295,14 @@ class Problem(Object): ...@@ -296,14 +295,14 @@ class Problem(Object):
num.nansum(exp(w*ms[num.newaxis, :]), axis=1) / num.nansum(exp(w*ms[num.newaxis, :]), axis=1) /
num.nansum(exp(w*ns[num.newaxis, :]), axis=1)) num.nansum(exp(w*ns[num.newaxis, :]), axis=1))
w *= self.get_bootstrap_weights(ibootstrap) w *= self.get_bootstrap_weights(nbootstrap, ibootstrap)
return root(num.nansum(exp(w*ms)) / num.nansum(exp(w*ns))) return root(num.nansum(exp(w*ms)) / num.nansum(exp(w*ns)))
def bootstrap_misfits(self, misfits, ibootstrap, nbootstraps): def bootstrap_misfits(self, misfits, nbootstrap, ibootstrap=None):
exp, root = self.get_norm_functions() exp, root = self.get_norm_functions()
w = self.get_bootstrap_weights( w = self.get_bootstrap_weights(
nbootstraps, ibootstrap)[num.newaxis, :] * \ nbootstrap, ibootstrap)[num.newaxis, :] * \
self.get_target_weights()[num.newaxis, :] * \ self.get_target_weights()[num.newaxis, :] * \
self.inter_group_weights2(misfits[:, :, 1]) self.inter_group_weights2(misfits[:, :, 1])
......
...@@ -66,7 +66,6 @@ class DoubleDCProblem(Problem): ...@@ -66,7 +66,6 @@ class DoubleDCProblem(Problem):
dependants = [] dependants = []
distance_min = Float.T(default=0.0) distance_min = Float.T(default=0.0)
nbootstrap = Int.T(default=100)
def get_source(self, x): def get_source(self, x):
d = self.get_parameter_dict(x) d = self.get_parameter_dict(x)
......
...@@ -292,7 +292,7 @@ def solve(problem, ...@@ -292,7 +292,7 @@ def solve(problem,
return return
gm = problem.global_misfit(ms, ns) gm = problem.global_misfit(ms, ns)
bms = problem.bootstrap_misfit(ms, ns) bms = problem.bootstrap_misfit(ms, ns, nbootstrap)
chains_m[0, nlinks] = gm chains_m[0, nlinks] = gm
chains_m[1:, nlinks] = bms chains_m[1:, nlinks] = bms
......
Supports Markdown
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