Commit ca67276b by Sebastian Heimann

### solver: implemented local standard deviation technique

parent 057eed1f
 ... @@ -1379,6 +1379,14 @@ def select_most_excentric(xcandidates, xs, sbx, factor): ... @@ -1379,6 +1379,14 @@ def select_most_excentric(xcandidates, xs, sbx, factor): return xcandidates[ichoice] return xcandidates[ichoice] def local_std(xs): sbx = num.std(xs, axis=0) ssbx = num.sort(xs, axis=0) dssbx = num.diff(ssbx, axis=0) mdssbx = num.median(dssbx, axis=0) return mdssbx * dssbx.shape[0] / 2.6 def solve(problem, def solve(problem, rundir=None, rundir=None, niter_uniform=1000, niter_uniform=1000, ... @@ -1415,6 +1423,7 @@ def solve(problem, ... @@ -1415,6 +1423,7 @@ def solve(problem, sbx = None sbx = None mxs = None mxs = None covs = None covs = 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 + problem.nbootstrap, dtype=num.int) ... @@ -1472,13 +1481,13 @@ def solve(problem, ... @@ -1472,13 +1481,13 @@ def solve(problem, if compensate_excentricity: if compensate_excentricity: ichoice = excentricity_compensated_choice( ichoice = excentricity_compensated_choice( xhist[chains_i[jchoice, :], :], sbx, 2.) xhist[chains_i[jchoice, :], :], local_sxs[jchoice], 2.) xchoice = xhist[chains_i[jchoice, ichoice], :] xchoice = xhist[chains_i[jchoice, ichoice], :] else: else: ichoice = num.random.randint(0, nlinks) ichoice = num.random.randint(0, nlinks) xchoice = xhist[chains_i[jchoice, ichoice]] xchoice = xhist[chains_i[jchoice, ichoice], :] else: else: xchoice = mxs[jchoice] xchoice = mxs[jchoice] ... @@ -1519,9 +1528,9 @@ def solve(problem, ... @@ -1519,9 +1528,9 @@ def solve(problem, for ipar in xrange(npar): for ipar in xrange(npar): ntry = 0 ntry = 0 while True: while True: if sbx[ipar] > 0.: if local_sxs[jchoice][ipar] > 0.: v = num.random.normal( v = num.random.normal( xchoice[ipar], factor*sbx[ipar]) xchoice[ipar], factor*local_sxs[jchoice][ipar]) else: else: v = xchoice[ipar] v = xchoice[ipar] ... @@ -1543,7 +1552,7 @@ def solve(problem, ... @@ -1543,7 +1552,7 @@ def solve(problem, x = select_most_excentric( x = select_most_excentric( xcandidates, xcandidates, xhist[chains_i[jchoice, :], :], xhist[chains_i[jchoice, :], :], sbx, local_sxs[jchoice], factor) factor) try: try: ... @@ -1638,13 +1647,17 @@ def solve(problem, ... @@ -1638,13 +1647,17 @@ def solve(problem, covs = [] covs = [] mxs = [] mxs = [] local_sxs = [] for i in xrange(1 + problem.nbootstrap): for i in xrange(1 + problem.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) local_sx = local_std(xs) mxs.append(mx) mxs.append(mx) covs.append(cov) covs.append(cov) local_sxs.append(local_sx) if 'state' in status: if 'state' in status: lines.append( lines.append( ... @@ -1685,7 +1698,7 @@ def solve(problem, ... @@ -1685,7 +1698,7 @@ def solve(problem, chains_i[:, :nlinks], chains_i[:, :nlinks], ibase, ibase, jchoice, jchoice, sbx, local_sxs, factor) factor) iiter += 1 iiter += 1 ... @@ -2173,11 +2186,17 @@ def process_event(ievent, g_data_id): ... @@ -2173,11 +2186,17 @@ def process_event(ievent, g_data_id): synt = ds.synthetic_test synt = ds.synthetic_test if synt and synt.inject_solution: if synt and synt.inject_solution: xs_inject = synt.get_x()[num.newaxis, :] xs_inject = synt.get_x()[num.newaxis, :] #from matplotlib import pyplot as plt #from grond import plot #splot = plot.SolverPlot( # plt, 'time', 'magnitude', show=False, update_every=10, movie_filename='grond_opt_time_magnitude.mp4') solve(problem, solve(problem, rundir=rundir, rundir=rundir, status=status, status=status, xs_inject=xs_inject, xs_inject=xs_inject, # plot=splot, **config.solver_config.get_solver_kwargs()) **config.solver_config.get_solver_kwargs()) harvest(rundir, problem, force=True) harvest(rundir, problem, force=True) ... ...
 ... @@ -1638,24 +1638,24 @@ class SolverPlot(object): ... @@ -1638,24 +1638,24 @@ class SolverPlot(object): self.axes.set_xlim(*self.xlim) self.axes.set_xlim(*self.xlim) self.axes.set_ylim(*self.ylim) self.axes.set_ylim(*self.ylim) def update(self, xhist, chains_i, ibase, jchoice, sbx, factor): def update(self, xhist, chains_i, ibase, jchoice, local_sxs, factor): msize = 15. msize = 15. self.axes.cla() self.axes.cla() if jchoice is not None and sbx is not None: if jchoice is not None and local_sxs is not None: nx = 100 nx = 100 ny = 100 ny = 100 sx = sbx[self.ixpar] * factor sx = local_sxs[jchoice][self.ixpar] * factor sy = sbx[self.iypar] * factor sy = local_sxs[jchoice][self.iypar] * factor p = num.zeros((ny, nx)) p = num.zeros((ny, nx)) for j in [ jchoice ]: # xrange(self.problem.nbootstrap+1): for j in [ jchoice ]: # xrange(self.problem.nbootstrap+1): ps = core.excentricity_compensated_probabilities( ps = core.excentricity_compensated_probabilities( xhist[chains_i[j, :], :], sbx, 2.) xhist[chains_i[j, :], :], local_sxs[jchoice], 2.) bounds = self.problem.bounds() + \ bounds = self.problem.bounds() + \ self.problem.dependant_bounds() self.problem.dependant_bounds() ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!