Commit 63ab17ee authored by Marius Isken's avatar Marius Isken
Browse files

nbootstrap to HighscoreSolver

parent 78ca5053
...@@ -187,7 +187,6 @@ def command_init(args): ...@@ -187,7 +187,6 @@ def command_init(args):
problem_config = grond.CMTProblemConfig( problem_config = grond.CMTProblemConfig(
name_template='cmt_%(event_name)s', name_template='cmt_%(event_name)s',
distance_min=2.*km, distance_min=2.*km,
nbootstrap=100,
mt_type='deviatoric', mt_type='deviatoric',
ranges=dict( ranges=dict(
time=Range(0, 10.0, relative='add'), time=Range(0, 10.0, relative='add'),
......
...@@ -325,8 +325,6 @@ class BadProblem(GrondError): ...@@ -325,8 +325,6 @@ class BadProblem(GrondError):
pass pass
def solve(problem, def solve(problem,
phases, phases,
rundir=None, rundir=None,
...@@ -427,7 +425,6 @@ def solve(problem, ...@@ -427,7 +425,6 @@ def solve(problem,
chains.insert(gbms, iiter) chains.insert(gbms, iiter)
chains_m[0, nlinks] = gm chains_m[0, nlinks] = gm
chains_m[1:, nlinks] = bms chains_m[1:, nlinks] = bms
chains_i[:, nlinks] = iiter chains_i[:, nlinks] = iiter
...@@ -539,13 +536,11 @@ class HighScoreOptimizer(Optimizer): ...@@ -539,13 +536,11 @@ class HighScoreOptimizer(Optimizer):
Optimizer.__init__(self) Optimizer.__init__(self)
self._kwargs = kwargs self._kwargs = kwargs
def solve( def solve(
problem, problem,
phases, phases,
rundir=None, rundir=None,
chain_length_factor=
chain_length_factor=8.0, chain_length_factor=8.0,
standard_deviation_estimator='median_density_single_chain', standard_deviation_estimator='median_density_single_chain',
...@@ -635,6 +630,7 @@ class StandardDeviationEstimatorChoice(StringChoice): ...@@ -635,6 +630,7 @@ class StandardDeviationEstimatorChoice(StringChoice):
class HighScoreOptimizerConfig(OptimizerConfig): class HighScoreOptimizerConfig(OptimizerConfig):
nbootstrap = Int.T(default=100)
niter_uniform = Int.T(default=1000) niter_uniform = Int.T(default=1000)
niter_transition = Int.T(default=0) niter_transition = Int.T(default=0)
niter_explorative = Int.T(default=10000) niter_explorative = Int.T(default=10000)
...@@ -650,6 +646,7 @@ class HighScoreOptimizerConfig(OptimizerConfig): ...@@ -650,6 +646,7 @@ class HighScoreOptimizerConfig(OptimizerConfig):
def get_optimizer_kwargs(self): def get_optimizer_kwargs(self):
return dict( return dict(
nbootstrap=self.nbootstrap,
niter_uniform=self.niter_uniform, niter_uniform=self.niter_uniform,
niter_transition=self.niter_transition, niter_transition=self.niter_transition,
niter_explorative=self.niter_explorative, niter_explorative=self.niter_explorative,
......
...@@ -3,7 +3,7 @@ import math ...@@ -3,7 +3,7 @@ import math
import logging import logging
from pyrocko import gf, util, moment_tensor as mtm from pyrocko import gf, util, moment_tensor as mtm
from pyrocko.guts import String, Float, Dict, Int, StringChoice from pyrocko.guts import String, Float, Dict, StringChoice
from .base import Problem, ProblemConfig from .base import Problem, ProblemConfig
from ..meta import Forbidden, expand_template, Parameter from ..meta import Forbidden, expand_template, Parameter
......
...@@ -18,7 +18,6 @@ class DoubleDCProblemConfig(ProblemConfig): ...@@ -18,7 +18,6 @@ class DoubleDCProblemConfig(ProblemConfig):
ranges = Dict.T(String.T(), gf.Range.T()) ranges = Dict.T(String.T(), gf.Range.T())
distance_min = Float.T(default=0.0) distance_min = Float.T(default=0.0)
nbootstrap = Int.T(default=100)
def get_problem(self, event, targets): def get_problem(self, event, targets):
if event.depth is None: if event.depth is None:
...@@ -38,7 +37,6 @@ class DoubleDCProblemConfig(ProblemConfig): ...@@ -38,7 +37,6 @@ class DoubleDCProblemConfig(ProblemConfig):
targets=targets, targets=targets,
ranges=self.ranges, ranges=self.ranges,
distance_min=self.distance_min, distance_min=self.distance_min,
nbootstrap=self.nbootstrap,
norm_exponent=self.norm_exponent) norm_exponent=self.norm_exponent)
return problem return problem
......
...@@ -18,7 +18,6 @@ class RectangularProblemConfig(ProblemConfig): ...@@ -18,7 +18,6 @@ class RectangularProblemConfig(ProblemConfig):
ranges = Dict.T(String.T(), gf.Range.T()) ranges = Dict.T(String.T(), gf.Range.T())
apply_balancing_weights = Bool.T(default=False) apply_balancing_weights = Bool.T(default=False)
decimation_factor = Int.T(default=1) decimation_factor = Int.T(default=1)
nbootstrap = Int.T(default=10)
distance_min = Float.T(default=0.) distance_min = Float.T(default=0.)
def get_problem(self, event, targets): def get_problem(self, event, targets):
...@@ -35,7 +34,6 @@ class RectangularProblemConfig(ProblemConfig): ...@@ -35,7 +34,6 @@ class RectangularProblemConfig(ProblemConfig):
name=expand_template(self.name_template, event.name), name=expand_template(self.name_template, event.name),
apply_balancing_weights=self.apply_balancing_weights, apply_balancing_weights=self.apply_balancing_weights,
base_source=base_source, base_source=base_source,
nbootstrap=self.nbootstrap,
distance_min=self.distance_min, distance_min=self.distance_min,
targets=targets, targets=targets,
ranges=self.ranges, ranges=self.ranges,
......
...@@ -58,6 +58,7 @@ def local_std(xs): ...@@ -58,6 +58,7 @@ def local_std(xs):
def solve(problem, def solve(problem,
rundir=None, rundir=None,
nbootstrap=100,
niter_uniform=1000, niter_uniform=1000,
niter_transition=1000, niter_transition=1000,
niter_explorative=10000, niter_explorative=10000,
...@@ -78,8 +79,8 @@ def solve(problem, ...@@ -78,8 +79,8 @@ def solve(problem,
npar = problem.nparameters npar = problem.nparameters
nlinks_cap = int(round(chain_length_factor * npar + 1)) nlinks_cap = int(round(chain_length_factor * npar + 1))
chains_m = num.zeros((1 + problem.nbootstrap, nlinks_cap), num.float) chains_m = num.zeros((1 + nbootstrap, nlinks_cap), num.float)
chains_i = num.zeros((1 + problem.nbootstrap, nlinks_cap), num.int) chains_i = num.zeros((1 + nbootstrap, nlinks_cap), num.int)
nlinks = 0 nlinks = 0
mbx = None mbx = None
...@@ -98,7 +99,7 @@ def solve(problem, ...@@ -98,7 +99,7 @@ def solve(problem,
local_sxs = None local_sxs = None
xhist = num.zeros((niter, npar)) xhist = num.zeros((niter, npar))
isbad_mask = None isbad_mask = None
accept_sum = num.zeros(1 + problem.nbootstrap, dtype=num.int) accept_sum = num.zeros(1 + nbootstrap, dtype=num.int)
accept_hist = num.zeros(niter, dtype=num.int) accept_hist = num.zeros(niter, dtype=num.int)
pnames = problem.parameter_names pnames = problem.parameter_names
...@@ -164,7 +165,7 @@ def solve(problem, ...@@ -164,7 +165,7 @@ def solve(problem,
x = problem.random_uniform(xbounds) x = problem.random_uniform(xbounds)
else: else:
# ibootstrap_choice = num.random.randint( # ibootstrap_choice = num.random.randint(
# 0, 1 + problem.nbootstrap) # 0, 1 + nbootstrap)
ibootstrap_choice = num.argmin(accept_sum) ibootstrap_choice = num.argmin(accept_sum)
if phase in ('transition', 'explorative'): if phase in ('transition', 'explorative'):
...@@ -309,7 +310,7 @@ def solve(problem, ...@@ -309,7 +310,7 @@ def solve(problem,
accept = (chains_i[:, nlinks_cap-1] != iiter).astype(num.int) accept = (chains_i[:, nlinks_cap-1] != iiter).astype(num.int)
nlinks -= 1 nlinks -= 1
else: else:
accept = num.ones(1 + problem.nbootstrap, dtype=num.int) accept = num.ones(1 + nbootstrap, dtype=num.int)
if rundir: if rundir:
problem.dump_problem_data( problem.dump_problem_data(
...@@ -342,7 +343,7 @@ def solve(problem, ...@@ -342,7 +343,7 @@ def solve(problem,
mxs = [] mxs = []
local_sxs = [] local_sxs = []
for i in xrange(1 + problem.nbootstrap): for i in xrange(1 + nbootstrap):
xs = xhist[chains_i[i, :nlinks], :] xs = xhist[chains_i[i, :nlinks], :]
mx = num.mean(xs, axis=0) mx = num.mean(xs, axis=0)
cov = num.cov(xs.T) cov = num.cov(xs.T)
...@@ -436,6 +437,7 @@ class StandardDeviationEstimatorChoice(StringChoice): ...@@ -436,6 +437,7 @@ class StandardDeviationEstimatorChoice(StringChoice):
class HighScoreSolverConfig(SolverConfig): class HighScoreSolverConfig(SolverConfig):
nbootstrap = Int.T(default=100)
niter_uniform = Int.T(default=1000) niter_uniform = Int.T(default=1000)
niter_transition = Int.T(default=0) niter_transition = Int.T(default=0)
niter_explorative = Int.T(default=10000) niter_explorative = Int.T(default=10000)
...@@ -451,6 +453,7 @@ class HighScoreSolverConfig(SolverConfig): ...@@ -451,6 +453,7 @@ class HighScoreSolverConfig(SolverConfig):
def get_solver_kwargs(self): def get_solver_kwargs(self):
return dict( return dict(
nbootstrap=self.nbootstrap,
niter_uniform=self.niter_uniform, niter_uniform=self.niter_uniform,
niter_transition=self.niter_transition, niter_transition=self.niter_transition,
niter_explorative=self.niter_explorative, niter_explorative=self.niter_explorative,
......
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